File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -231,6 +231,8 @@ ${underline}Non-Root Check:${nounderline} Running as root detected.
231231
232232# # Wrapper that supports su, sudo, doas
233233root_cmd (){
234+ local cmdarr
235+
234236 test -z " ${1:- } " && die 1 " ${underline} root_cmd function:${nounderline} Failed to pass arguments to root_cmd."
235237 if test -z " ${sucmd:- } " ; then
236238 get_su_cmd
@@ -245,7 +247,15 @@ root_cmd(){
245247 log_run " $root_cmd_loglevel " su root -s " ${cmd} " -- " ${@ } "
246248 ;;
247249 sudo)
248- log_run " $root_cmd_loglevel " sudo -- " ${@ } "
250+ cmdarr=( ' log_run' " $root_cmd_loglevel " ' sudo' )
251+ if [ -n " $ROOT_CMD_TARGET_USER " ]; then
252+ cmdarr+=( ' --user' " $ROOT_CMD_TARGET_USER " );
253+ fi
254+ if [ -n " $ROOT_CMD_TARGET_DIR " ]; then
255+ cmdarr+=( ' --chdir' " $ROOT_CMD_TARGET_DIR " );
256+ fi
257+ cmdarr+=( ' --' " ${@ } " )
258+ " ${cmdarr[@]} "
249259 ;;
250260 doas)
251261 log_run " $root_cmd_loglevel " doas -u root -- " ${@ } "
@@ -258,6 +268,8 @@ root_cmd(){
258268
259269
260270get_su_cmd (){
271+ export ROOT_CMD_TARGET_USER=' '
272+ export ROOT_CMD_TARGET_DIR=' '
261273 while true ; do
262274 has sudo && sucmd=sudo && break
263275 has doas && sucmd=doas && break
You can’t perform that action at this time.
0 commit comments