@@ -, +, @@ --- lib/portage/util/env_update.py | 40 +++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) --- a/lib/portage/util/env_update.py +++ a/lib/portage/util/env_update.py @@ -6,6 +6,7 @@ __all__ = ['env_update'] import errno import glob import io +import re import stat import time @@ -340,7 +341,8 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, cenvnotice += "# GO INTO /etc/csh.cshrc NOT /etc/csh.env\n\n" #create /etc/profile.env for bash support - outfile = atomic_ofstream(os.path.join(eroot, "etc", "profile.env")) + profile_env_path = os.path.join(eroot, "etc", "profile.env") + outfile = atomic_ofstream(profile_env_path) outfile.write(penvnotice) env_keys = [x for x in env if x != "LDPATH"] @@ -353,6 +355,42 @@ def _env_update(makelinks, target_root, prev_mtimes, contents, env, outfile.write("export %s='%s'\n" % (k, v)) outfile.close() + # Create the systemd user environment configuration file + # /usr/lib/environment.d/gentoo-profile-env.conf with the + # environment variables of /etc/profile.enf if + # /usr/lib/environment.d exists. + systemd_environment_dir = os.path.join(eroot, "usr", "lib", "environment.d") + if os.path.isdir(systemd_environment_dir): + with open(profile_env_path, "r") as profile_env: + lines = profile_env.readlines() + + systemd_profile_env_path = os.path.join(systemd_environment_dir, + "gentoo-profile-env.conf") + + with open(systemd_profile_env_path, "w") as systemd_profile_env: + for line in lines: + # Skip comments. + if re.match(r"^[ \t]*#", line): + continue + + # Skip empty lines. + if re.match(r"^[ \t]*$", line): + continue + + # Skip variables with the empty string + # as value. Those sometimes appear in + # profile.env (e.g. "export GCC_SPECS=''"), + # but are invalid in systemd's syntax. + if line.endswith("=''\n"): + continue + + # Transform into systemd environment.d + # conf syntax, basically shell variable + # assignment (without "export "). + line = re.sub(r"^export ", "", line) + + systemd_profile_env.write(line) + #create /etc/csh.env for (t)csh support outfile = atomic_ofstream(os.path.join(eroot, "etc", "csh.env")) outfile.write(cenvnotice) --