Skip to content

Commit

Permalink
build
Browse files Browse the repository at this point in the history
  • Loading branch information
adrelanos committed Jan 12, 2025
1 parent a5f1631 commit 6134e21
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion usr/share/usability-misc/dist-installer-cli-standalone
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 -- "${@}"
Expand All @@ -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
Expand Down

0 comments on commit 6134e21

Please sign in to comment.