From 9cf444cb4c8c8e1fa5d331d69df6f1b82c6a57e3 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Sat, 15 Mar 2025 12:44:00 -0400 Subject: [PATCH] install-deps: extract SUDO variable logic into a reusable function While the function is pretty simple and could be copy-pasted I prefer to extract things into functions to indicate that the logic is used/repeated elsewhere to ward off making changes to one copy vs the other. Signed-off-by: John Mulligan (cherry picked from commit bbd7933598e11d84758a6f09fd176f47c744aaa2) --- install-deps.sh | 4 +--- src/script/lib-build.sh | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/install-deps.sh b/install-deps.sh index cc7e15a6250..0d56b0d5c9d 100755 --- a/install-deps.sh +++ b/install-deps.sh @@ -23,9 +23,7 @@ fi DIR=/tmp/install-deps.$$ trap "rm -fr $DIR" EXIT mkdir -p $DIR -if test $(id -u) != 0 ; then - SUDO=sudo -fi +wrap_sudo # enable UTF-8 encoding for programs like pip that expect to # print more than just ascii chars export LC_ALL=C.UTF-8 diff --git a/src/script/lib-build.sh b/src/script/lib-build.sh index 0e915831a51..0c131a7a3ea 100644 --- a/src/script/lib-build.sh +++ b/src/script/lib-build.sh @@ -32,6 +32,16 @@ function ci_debug() { fi } +function wrap_sudo() { + # set or unset the SUDO env var so that scripts already running + # as root do not call into sudo to escalate privs + if test $(id -u) != 0 ; then + SUDO=sudo + else + SUDO="" + fi +} + # get_processors returns 1/2 the value of the value returned by # the nproc program OR the value of the environment variable NPROC # allowing the user to tune the number of cores visible to the -- 2.39.5