File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,6 +29,21 @@ _detect_runtime() {
2929 fi
3030}
3131
32+ # Detect superuser command.
33+ # If running as root, no sudo is needed. Otherwise, check for sudo.
34+ _detect_sudo () {
35+ if [ " $( id -u) " = " 0" ]; then
36+ echo " "
37+ elif command -v sudo > /dev/null 2>&1 ; then
38+ echo " sudo"
39+ elif command -v doas > /dev/null 2>&1 ; then
40+ echo " doas"
41+ else
42+ echo " Error: This script must be run as root or with sudo/doas available in PATH" 1>&2
43+ exit 1
44+ fi
45+ }
46+
3247_show_usage () {
3348 echo " Usage: $0 [OPTIONS] [COMMAND]"
3449 echo " "
@@ -153,9 +168,10 @@ else
153168fi
154169
155170USER=builder
171+ REAL_SUDO=$( _detect_sudo) || exit 1
156172
157173if [ -n " ${TERMUX_DOCKER_USE_SUDO-} " ]; then
158- SUDO=" sudo "
174+ SUDO=$REAL_SUDO
159175else
160176 SUDO=" "
161177fi
@@ -190,7 +206,7 @@ if [ "$RUNTIME" = "docker" ]; then
190206 if [ -n " $msg " ]; then
191207 echo " $msg ..."
192208 fi
193- cat " $profile_path " | sed -e " s/{{CONTAINER_NAME}}/$CONTAINER_NAME /g" | sudo " $APPARMOR_PARSER " -rK
209+ cat " $profile_path " | sed -e " s/{{CONTAINER_NAME}}/$CONTAINER_NAME /g" | $REAL_SUDO " $APPARMOR_PARSER " -rK
194210 fi
195211 }
196212
You can’t perform that action at this time.
0 commit comments