diff --git a/kiss b/kiss index cce4906..47edd3f 100755 --- a/kiss +++ b/kiss @@ -49,15 +49,18 @@ prompt() { as_root() { # Simple function to run a command as root using either 'sudo', # 'doas' or 'su'. Hurrah for choice. - [ "$uid" = 0 ] || { - log "Using '${su:-su}' (to become ${user:=root})" - export KISS_AS_ROOT=1 - } + [ "$uid" = 0 ] || log "Using '${su:-su}' (to become ${user:=root})" + + # Add the following environment variables to the root environment + # so that the non-root user's cache can be used. This is the + # portable method of doing so and works across all tools. + set -- env HOME="$HOME" XDG_CACHE_HOME="$XDG_CACHE_HOME" \ + KISS_PATH="$KISS_PATH" KISS_FORCE="$KISS_FORCE" "$@" case $su in - *sudo) sudo -E -u "$user" -- "$@" ;; - *doas) doas -u "$user" -- "$@" ;; - *) su -pc "$* <&3" "$user" 3<&0