From 2ffe758ed848086439e5bc6c5723a4e77511c989 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Tue, 1 Sep 2020 09:32:00 +0200 Subject: [PATCH] Add gentoo-env-to-systemd This script transforms Gentoo's /etc/profile.env to a systemd user unit environment configuration file placed in /usr/lib/environment.d named gentoo-env.conf. The script is meant to be invoked by a, not yet existing, env-update hook that is invoked after /etc/profile.env was (re-)generated. Bug: https://bugs.gentoo.org/704416 Signed-off-by: Florian Schmaus --- gentoo-env-to-systemd | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100755 gentoo-env-to-systemd diff --git a/gentoo-env-to-systemd b/gentoo-env-to-systemd new file mode 100755 index 0000000..74d53d0 --- /dev/null +++ b/gentoo-env-to-systemd @@ -0,0 +1,33 @@ +#!/usr/bin/env bash +# Copyright 2020 Gentoo Authors +# Distributed under the terms of the GNU General Public License v3 (or any later version) +set -euo pipefail + +while getopts :d OPT; do + case $OPT in + d) + set -x + ;; + *) + echo "usage: ${0##*/} [-d]" + exit 2 + esac +done + +readonly GENTOO_PROFILE_ENV_PATH="/etc/profile.env" +readonly GENTOO_SYSTEMD_ENV_CONF="/usr/lib/environment.d/gentoo-env.conf" + +# Strip "export " to transform gentoo's profile.env syntax, which is +# shell, to systemd's environment.d syntax (which is shell-like +# without explicit "export" keyword). +readonly STRIP_EXPORT_REGEX="s;^export ;;" +# Strip comments. +readonly STRIP_COMMENTS_REGEX="/^[ \t]*#/d" +# Strip emtpy lines. +readonly STRIP_EMPTY_LINES_REGEX="/^[ \t]*$/d" + +sed -e "${STRIP_EXPORT_REGEX}" \ + -e "${STRIP_COMMENTS_REGEX}" \ + -e "${STRIP_EMPTY_LINES_REGEX}" \ + "${GENTOO_PROFILE_ENV_PATH}" \ + > "${GENTOO_SYSTEMD_ENV_CONF}" -- 2.26.2