Export PROFILE_HOME.
authorIain Patterson <me@iain.cx>
Fri, 9 May 2014 11:00:31 +0000 (12:00 +0100)
committerIain Patterson <me@iain.cx>
Wed, 28 May 2014 09:54:33 +0000 (10:54 +0100)
Export PROFILE_HOME in the environment so that become can be run from
became without losing settings.

.profile.d/BECOME.bashrc
opt/bin/become

index 32a69ed..50cb97a 100644 (file)
@@ -1,3 +1,8 @@
+# Export PROFILE_HOME to the environment if we need to preserve it.
+if [ -n "$PROFILE_HOME" ]; then
+  [ "$PROFILE_HOME" = "$HOME" ] || export PROFILE_HOME
+fi
+
 # Find a path, preferring the target user's version.
 function find_target_profile() {
   local path="$1"; shift
index 0825bd6..a7ad44a 100755 (executable)
@@ -47,7 +47,7 @@ builtin umask 077
 if exec 3>"$file" && exec <"$file" && rm "$file"; then
   builtin $umask
   echo >&3 "cd"
-  echo >&3 "PROFILE_HOME='$HOME'"
+  echo >&3 "PROFILE_HOME='${PROFILE_HOME:-$HOME}'"
   if [ -n "$PRINCIPAL" ]; then
     echo >&3 "PRINCIPAL='$PRINCIPAL'"
     if [ $kerberos = 1 ]; then
@@ -71,7 +71,7 @@ else
   exit 111
 fi
 
-echo >&3 ". $HOME/.bash_profile"
+echo >&3 ". ${PROFILE_HOME:-$HOME}/.bash_profile"
 [ -f "$BECOME/all" ] && cat >&3 2>/dev/null "$BECOME/all"
 [ -f "$BECOME/$user" ] && cat >&3 2>/dev/null "$BECOME/$user"
 [ $chdir = 1 ] && echo >&3 2>/dev/null "cd - &>/dev/null"