Codebase list kali-defaults / 15c34cf
Move the content of etc/environment.d/* into etc/environment Files in /etc/environment.d(5) are picked up by systemd --user, however the XFCE session is not started by systemd --user, it is started by Lightdm. So variables in /etc/environment.d have pretty much no effect on XFCE. Adding more variables to /etc/environment starts to be tricky though, and requires more care on our side. First, we add a header to explain that kali-defaults touch this file, and we make sure that our modifications are enclosed with two markers, 'START KALI-DEFAULTS CONFIG' and 'STOP KALI-DEFAULTS CONFIG'. In short, it looks like that: # START KALI-DEFAULTS CONFIG # Everything from here and until STOP KALI-DEFAULTS CONFIG # was installed by the kali-defaults package, and it will # be removed if ever the kali-defaults package is removed. # If you want to disable a line, please do NOT remove it, # as it would be added back when kali-defaults is upgraded. # Instead, comment the line out, and your change will be # preserved accross upgrades. PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games COMMAND_NOT_FOUND_INSTALL_PROMPT=1 POWERSHELL_TELEMETRY_OPTOUT=1 # STOP KALI-DEFAULTS CONFIG Additionally, we now support NOT adding an environment variable, if ever we detect that it's been commented out by the administrator. At last, this commit also reworks how we handle the piuparts case, which is needed for our CI to pass. Arnaud Rebillout 3 years ago
3 changed file(s) with 62 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
3838 fi
3939 }
4040
41 set_env_header_if_unset() {
42 if grep -q '^# STOP KALI-DEFAULTS CONFIG' /etc/environment; then
43 return
44 fi
45
46 echo "Adding KALI-DEFAULTS header to /etc/environment"
47 {
48 echo "# START KALI-DEFAULTS CONFIG"
49 echo "# Everything from here and until STOP KALI-DEFAULTS CONFIG"
50 echo "# was installed by the kali-defaults package, and it will"
51 echo "# be removed if ever the kali-defaults package is removed."
52 echo "# If you want to disable a line, please do NOT remove it,"
53 echo "# as it would be added back when kali-defaults is upgraded."
54 echo "# Instead, comment the line out, and your change will be"
55 echo "# preserved across upgrades."
56 echo "# STOP KALI-DEFAULTS CONFIG"
57 } >> /etc/environment
58 }
59
60 set_env_var_if_unset() {
61 local setting=$1
62 local value=$2
63
64 # Bail out if the setting is set or is commented out
65 if grep -q "^#* *${setting}=" /etc/environment; then
66 return
67 fi
68
69 # Insert the setting just before the STOP marker
70 echo "Setting ${setting} in /etc/environment"
71 sed -i "/^# STOP KALI-DEFAULTS CONFIG/i ${setting}=${value}" \
72 /etc/environment
73 }
74
4175 configure_environment() {
76 echo "Configuring /etc/environment"
77
78 # Hack for piuparts: break the hard link
79 if [ -n "$PIUPARTS_TEST" ]; then
80 cp /etc/environment /etc/environment.tmp
81 mv /etc/environment.tmp /etc/environment
82 fi
83
84 set_env_header_if_unset
85
4286 # Force PATH via /etc/environment so that non-root users have system tools
4387 # available too (those in */sbin/)
44 if ! grep -q ^PATH= /etc/environment; then
45 echo "Configuring PATH in /etc/environment"
46 echo "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games" >> /etc/environment
47 fi
88 set_env_var_if_unset 'PATH' \
89 '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games'
90
91 # Propose to install commands not found
92 set_env_var_if_unset COMMAND_NOT_FOUND_INSTALL_PROMPT 1
93
94 # Opt-out of powershell telemetry reporting
95 set_env_var_if_unset POWERSHELL_TELEMETRY_OPTOUT 1
4896 }
4997
5098 if [ "$1" = "configure" ]; then
79127 install_config_file /etc/skel/.bashrc force
80128 fi
81129
130 if dpkg --compare-versions "$2" lt-nl 2021.2.0; then
131 # Drop PATH= from /etc/environment. No worries, we add
132 # it again with configure_environment().
133 sed -i '\|^PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games|d' /etc/environment
134 fi
135
82136 for file in $FILES_TO_DIVERT; do
83137 install_config_file $file
84138 done
3636 }
3737
3838 unconfigure_environment() {
39 # Cleanup change to /etc/environment
40 if grep -q ^PATH= /etc/environment; then
41 echo "Dropping PATH override from /etc/environment"
42 # sed -i breaks hardlinks, hence breaks piuparts,
43 # so we'd rather use an intermediary file
44 cp /etc/environment /etc/environment.tmp
45 sed '/^PATH=/d' /etc/environment.tmp > /etc/environment
46 rm /etc/environment.tmp
47 fi
39 # Cleanup changes in /etc/environment
40 echo "Unconfiguring /etc/environment"
41 sed -i '/^# START KALI-DEFAULTS CONFIG/,/^# STOP KALI-DEFAULTS CONFIG/d' \
42 /etc/environment
4843 }
4944
5045 case "$1" in
+0
-2
etc/environment.d/95kali-defaults.conf less more
0 POWERSHELL_TELEMETRY_OPTOUT=1
1 COMMAND_NOT_FOUND_INSTALL_PROMPT=1