From dccdaa2fefaf564484a9d38d6ccf35f726c4f7cd Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Sun, 16 Nov 2025 17:05:19 +0100 Subject: [PATCH] Fix: onLogin script when /etc/profile.d is executed with sh --- etc/profile.d/99-linuxmuster-linuxclient7.sh | 9 +++++++- .../linuxmusterLinuxclient7/templates.py | 4 ++-- .../scripts/env-fix}/lmn-export | 0 .../scripts/env-fix}/lmn-unset | 0 .../scripts/executeHookWithEnvFix.sh | 23 ------------------- wiki/Insights/Environment-workaround.md | 2 +- wiki/Insights/Script-calling-strategy.md | 2 +- 7 files changed, 12 insertions(+), 28 deletions(-) rename usr/{sbin => share/linuxmuster-linuxclient7/scripts/env-fix}/lmn-export (100%) rename usr/{sbin => share/linuxmuster-linuxclient7/scripts/env-fix}/lmn-unset (100%) delete mode 100755 usr/share/linuxmuster-linuxclient7/scripts/executeHookWithEnvFix.sh diff --git a/etc/profile.d/99-linuxmuster-linuxclient7.sh b/etc/profile.d/99-linuxmuster-linuxclient7.sh index ab5b0f5..a504dff 100755 --- a/etc/profile.d/99-linuxmuster-linuxclient7.sh +++ b/etc/profile.d/99-linuxmuster-linuxclient7.sh @@ -1,2 +1,9 @@ scriptDir=$(/usr/sbin/linuxmuster-linuxclient7 get-constant scriptDir) -source $scriptDir/executeHookWithEnvFix.sh onLogin \ No newline at end of file +tmpEnvFile=$(/usr/sbin/linuxmuster-linuxclient7 get-constant tmpEnvironmentFilePath) + +rm -f $tmpEnvFile + +LinuxmusterLinuxclient7EnvFixActive=1 PATH=$PATH:$scriptDir/env-fix $scriptDir/onLogin + +. $tmpEnvFile +rm -f $tmpEnvFile \ No newline at end of file diff --git a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/templates.py b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/templates.py index 971c80f..c4fc02f 100644 --- a/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/templates.py +++ b/usr/lib/python3/dist-packages/linuxmusterLinuxclient7/templates.py @@ -50,7 +50,7 @@ def _apply(templatePath): # never ever overwrite sssd.conf, this will lead to issues! # sssd.conf is written by `realm join`! if targetFilePath in constants.notTemplatableFiles: - logging.warning("Skipping forbidden file {}".format(targetFilePath)) + logging.warning(f"Skipping forbidden file {targetFilePath}") return True # create target directory @@ -61,7 +61,7 @@ def _apply(templatePath): fileData = _stripComment(fileData) # write config file - logging.debug("-> to {}".format(targetFilePath)) + logging.debug(f"-> to {targetFilePath}") with open(targetFilePath, 'w') as targetFile: targetFile.write(fileData) diff --git a/usr/sbin/lmn-export b/usr/share/linuxmuster-linuxclient7/scripts/env-fix/lmn-export similarity index 100% rename from usr/sbin/lmn-export rename to usr/share/linuxmuster-linuxclient7/scripts/env-fix/lmn-export diff --git a/usr/sbin/lmn-unset b/usr/share/linuxmuster-linuxclient7/scripts/env-fix/lmn-unset similarity index 100% rename from usr/sbin/lmn-unset rename to usr/share/linuxmuster-linuxclient7/scripts/env-fix/lmn-unset diff --git a/usr/share/linuxmuster-linuxclient7/scripts/executeHookWithEnvFix.sh b/usr/share/linuxmuster-linuxclient7/scripts/executeHookWithEnvFix.sh deleted file mode 100755 index 73e24ed..0000000 --- a/usr/share/linuxmuster-linuxclient7/scripts/executeHookWithEnvFix.sh +++ /dev/null @@ -1,23 +0,0 @@ -# This script calls the desired hook and sources the temporary env -# file afterwards to apply environment changes from lmn-export and lmn-unset - -scriptDir=$(/usr/sbin/linuxmuster-linuxclient7 get-constant scriptDir) - -if [ ! -f $scriptDir/$1 ]; then - echo "Unknown hook: $1!" - return 1 - exit 1 -fi - -export LinuxmusterLinuxclient7EnvFixActive=1 -export PATH=$PATH:/usr/sbin/lmn-export:/usr/sbin/lmn-unset -tmpEnvFile=$(/usr/sbin/linuxmuster-linuxclient7 get-constant tmpEnvironmentFilePath) - -rm -f $tmpEnvFile - -# call hook script -$scriptDir/$1 - -unset LinuxmusterLinuxclient7EnvFixActive -source $tmpEnvFile 2> /dev/null -rm -f $tmpEnvFile \ No newline at end of file diff --git a/wiki/Insights/Environment-workaround.md b/wiki/Insights/Environment-workaround.md index ffea99c..f30b69a 100644 --- a/wiki/Insights/Environment-workaround.md +++ b/wiki/Insights/Environment-workaround.md @@ -1,4 +1,4 @@ This client uses Python. This brings a major problem: In Python it is not possible to modify the environment of the parent process. Because of this, hook scripts must use `lmn-export` and `lmn-unset` instead of `export` and `unset`. These scripts write the environment variables to a temporary file in `~/.linuxmuster-linuxclient7-environment.sh` which is then sourced afterwards. -This only works for the `onLogin.d` hook / the `logon.sh` script and is achieved by sourcing the script `/usr/share/linuxmuster-linuxclient7/scripts/executeHookWithEnvFix.sh` in `/etc/profile.d/99-linuxmuster-linuxclient7.sh` which then calls the `onLogin` script and sources `~/.linuxmuster-linuxclient7-environment.sh` afterwards. \ No newline at end of file +This only works for the `onLogin.d` hook / the `logon.sh` script and is achieved in `/etc/profile.d/99-linuxmuster-linuxclient7.sh` which calls the `onLogin` script and sources `~/.linuxmuster-linuxclient7-environment.sh` afterwards. \ No newline at end of file diff --git a/wiki/Insights/Script-calling-strategy.md b/wiki/Insights/Script-calling-strategy.md index d3a80af..20b6a83 100644 --- a/wiki/Insights/Script-calling-strategy.md +++ b/wiki/Insights/Script-calling-strategy.md @@ -11,7 +11,7 @@ This file is placed there in adsso-setup via the template in `/usr/share/linuxmu Pam_exec calls this script on login AND on logout. If it is a login our logout is determined by the `PAM_TYPE` environment variable. ### onLogin -This is called via `/usr/share/linuxmuster-linuxclient7/scripts/executeHookWithEnvFix.sh`, which is called by `/etc/profile.d/99-linuxmuster-linuxclient7.sh` The reason for this is the [environment workaround](Environment-workaround) +This is called via `/etc/profile.d/99-linuxmuster-linuxclient7.sh`. Please note the [environment workaround](Environment-workaround). ### onSessionStart This is called via `/home/$user/.config/autostart`.