Meta: Don't depend on sudo for privileged operations

We previously depended on sudo's specific -E flag to keep all the
environment variables when performing a privilege escalation. We now
incorporate the -E flag into the $SUDO variable, allowing for other
privilege escalation binaries (such as doas) to be used (as long as
they preserve the current environment variables).
This commit is contained in:
Baitinq 2022-11-23 21:01:11 +01:00 committed by Linus Groh
parent 7a51e846b2
commit 88c9e4f3b0
Notes: sideshowbarker 2024-07-17 03:14:44 +09:00
6 changed files with 10 additions and 7 deletions

View File

@ -3,10 +3,13 @@
# SC2034: "Variable appears unused. Verify it or export it."
# Those are intentional here, as the file is meant to be included elsewhere.
SUDO="sudo"
# NOTE: If using another privilege escalation binary make sure it is configured or has the appropiate flag
# to keep the current environment variables in the launched process (in sudo's case this is achieved
# through the -E flag described in sudo(8).
SUDO="sudo -E"
if [ "$(uname -s)" = "SerenityOS" ]; then
SUDO="pls"
SUDO="pls -E"
fi
die() {

View File

@ -8,7 +8,7 @@ script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
${SUDO} -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View File

@ -8,7 +8,7 @@ script_path=$(cd -P -- "$(dirname -- "$0")" && pwd -P)
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
${SUDO} -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View File

@ -17,7 +17,7 @@ fi
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
${SUDO} -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View File

@ -25,7 +25,7 @@ if [ "$(id -u)" != 0 ]; then
USE_FUSE2FS=1
else
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
${SUDO} -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"

View File

@ -16,7 +16,7 @@ cleanup() {
if [ "$(id -u)" != 0 ]; then
set +e
${SUDO} -E -- sh -c "\"$0\" $* || exit 42"
${SUDO} -- sh -c "\"$0\" $* || exit 42"
case $? in
1)
die "this script needs to run as root"