Line 0
Link Here
|
0 |
- |
1 |
#!/usr/bin/env bash |
|
|
2 |
# Copyright 2020 Gentoo Authors |
3 |
# Distributed under the terms of the GNU General Public License v3 (or any later version) |
4 |
set -euo pipefail |
5 |
|
6 |
while getopts :d OPT; do |
7 |
case $OPT in |
8 |
d) |
9 |
set -x |
10 |
;; |
11 |
*) |
12 |
echo "usage: ${0##*/} [-d]" |
13 |
exit 2 |
14 |
esac |
15 |
done |
16 |
|
17 |
readonly GENTOO_PROFILE_ENV_PATH="/etc/profile.env" |
18 |
readonly GENTOO_SYSTEMD_ENV_CONF="/usr/lib/environment.d/gentoo-env.conf" |
19 |
|
20 |
# Strip "export " to transform gentoo's profile.env syntax, which is |
21 |
# shell, to systemd's environment.d syntax (which is shell-like |
22 |
# without explicit "export" keyword). |
23 |
readonly STRIP_EXPORT_REGEX="s;^export ;;" |
24 |
# Strip comments. |
25 |
readonly STRIP_COMMENTS_REGEX="/^[ \t]*#/d" |
26 |
# Strip emtpy lines. |
27 |
readonly STRIP_EMPTY_LINES_REGEX="/^[ \t]*$/d" |
28 |
|
29 |
sed -e "${STRIP_EXPORT_REGEX}" \ |
30 |
-e "${STRIP_COMMENTS_REGEX}" \ |
31 |
-e "${STRIP_EMPTY_LINES_REGEX}" \ |
32 |
"${GENTOO_PROFILE_ENV_PATH}" \ |
33 |
> "${GENTOO_SYSTEMD_ENV_CONF}" |