Last active
December 23, 2015 15:19
-
-
Save FrozenCow/6654245 to your computer and use it in GitHub Desktop.
Systemd env.conf generation using profile.d
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo mkdir -p /etc/systemd/system/user@${UID}.service.d/ | |
./generate-systemd-envconf-from-profile.sh | sudo tee /etc/systemd/system/user@${UID}.service.d/env.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ -z "$EXPORTING" ] | |
then | |
# This hack is used to clear the environment to bare minimum. | |
env -i EXPORTING=1 HOME=$HOME $0 | |
exit | |
fi | |
BEFORE=$(mktemp) | |
AFTER=$(mktemp) | |
# Store the environment variables before we load profile | |
env > $BEFORE | |
export DISPLAY=:0 | |
source /etc/profile | |
source $HOME/.profile | |
# Store the environment variables after we have loaded profile | |
env > $AFTER | |
#echo .include /usr/lib/systemd/system/[email protected] | |
echo [Service] | |
# Use the difference of the 2 stored environment variables | |
# Extract the added (or modified) lines: the ones that are only in $AFTER | |
# Put it in the Systemd-form: Environment="NAME=VALUE" | |
diff $BEFORE $AFTER | grep '^>' | sed 's/^> \(.*\)=\(.*\)$/Environment="\1=\2"/g' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment