diff --git a/usr/share/usability-misc/dist-installer-cli-standalone b/usr/share/usability-misc/dist-installer-cli-standalone index d56c069..92b4dd9 100755 --- a/usr/share/usability-misc/dist-installer-cli-standalone +++ b/usr/share/usability-misc/dist-installer-cli-standalone @@ -231,6 +231,8 @@ ${underline}Non-Root Check:${nounderline} Running as root detected. ## Wrapper that supports su, sudo, doas root_cmd(){ + local cmdarr + test -z "${1:-}" && die 1 "${underline}root_cmd function:${nounderline} Failed to pass arguments to root_cmd." if test -z "${sucmd:-}"; then get_su_cmd @@ -245,7 +247,15 @@ root_cmd(){ log_run "$root_cmd_loglevel" su root -s "${cmd}" -- "${@}" ;; sudo) - log_run "$root_cmd_loglevel" sudo -- "${@}" + cmdarr=( 'log_run' "$root_cmd_loglevel" 'sudo' ) + if [ -n "$ROOT_CMD_TARGET_USER" ]; then + cmdarr+=( '--user' "$ROOT_CMD_TARGET_USER" ); + fi + if [ -n "$ROOT_CMD_TARGET_DIR" ]; then + cmdarr+=( '--chdir' "$ROOT_CMD_TARGET_DIR" ); + fi + cmdarr+=( '--' "${@}" ) + "${cmdarr[@]}" ;; doas) log_run "$root_cmd_loglevel" doas -u root -- "${@}" @@ -258,6 +268,8 @@ root_cmd(){ get_su_cmd(){ + export ROOT_CMD_TARGET_USER='' + export ROOT_CMD_TARGET_DIR='' while true; do has sudo && sucmd=sudo && break has doas && sucmd=doas && break