From e711f76296fe10d5dd59a0dfe4649fe8c7a8b378 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 18 May 2020 09:08:04 +0300 Subject: [PATCH] kiss: Don't run user hook as root when sudo/doas are set to keep environment. Closes #157 --- kiss | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/kiss b/kiss index f53c731..cce4906 100755 --- a/kiss +++ b/kiss @@ -49,7 +49,10 @@ 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})" + [ "$uid" = 0 ] || { + log "Using '${su:-su}' (to become ${user:=root})" + export KISS_AS_ROOT=1 + } case $su in *sudo) sudo -E -u "$user" -- "$@" ;; @@ -69,11 +72,15 @@ _tar() { } run_hook() { + # If we have elevated permissions from non-root to + # root, don't run the non-root user's KISS_HOOK. + [ "$KISS_AS_ROOT" != 1 ] || KISS_HOOK=/etc/kiss-hook + # Provide a default post-build hook to remove files # and directories for things we don't support out of # the box. One can simply define their own hook to # override this behavior. - [ "${KISS_HOOK:-}" ] || { + [ -f "${KISS_HOOK:-}" ] || { case $1 in post-build) rm -rf "$3/usr/share/gettext" rm -rf "$3/usr/share/polkit-1"