diff options
author | merakor <cem@ckyln.com> | 2020-08-10 08:21:57 +0000 |
---|---|---|
committer | merakor <cem@ckyln.com> | 2020-08-10 08:21:57 +0000 |
commit | 36bd86d0a83f252a4e43df6638d6563304571711 (patch) | |
tree | 5e68ac114b79ecf7e258ee8f816318e7a92ab475 /src | |
parent | 5ca5c3e83ea7e02b9d5b160ecfc7510549691deb (diff) | |
download | cpt-36bd86d0a83f252a4e43df6638d6563304571711.tar.gz |
as_root(): use 'env' for setting variables.
FossilOrigin-Name: 1cfe280b0c731ed14d08c3e89f8eef0ee2202e9dbd9d5aeca2587dd4427f8124
Diffstat (limited to 'src')
-rw-r--r-- | src/cpt-lib | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/cpt-lib b/src/cpt-lib index 3218fab..df3f92d 100644 --- a/src/cpt-lib +++ b/src/cpt-lib @@ -75,10 +75,24 @@ as_root() { # 'doas' or 'su'. Hurrah for choice. [ "$uid" = 0 ] || log "Using '${su:-su}' (to become ${user:=root})" + # We are exporting package manager variables, so that we still have the same + # repository paths / access to the same cache directories etc. + set -- HOME="$HOME" \ + XDG_CACHE_HOME="$XDG_CACHE_HOME" \ + CPT_PATH="$CPT_PATH" \ + CPT_FORCE="$CPT_FORCE" \ + CPT_HOOK="$CPT_HOOK" \ + CPT_ROOT="$CPT_ROOT" \ + CPT_CHOICE="$CPT_CHOICE" \ + CPT_CACHE="$CPT_CACHE" \ + CPT_TMPDIR="$CPT_TMPDIR" \ + CPT_HOOK="$CPT_HOOK" \ + CPT_PID="$CPT_PID" \ + "$@" + case ${su##*/} in - sudo) sudo -E -u "$user" -- "$@" ;; - doas) doas -u "$user" -- "$@" ;; - su) su -pc "env USER=$user $* <&3" "$user" 3<&0 </dev/tty ;; + sudo|doas) "$su" -u "$user" -- env "$@" ;; + su) su -c "env $* <&3" "$user" 3<&0 </dev/tty ;; *) die "Invalid CPT_SU value: $su" ;; esac } |