]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
install-deps: extract SUDO variable logic into a reusable function
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 15 Mar 2025 16:44:00 +0000 (12:44 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 8 Oct 2025 23:18:08 +0000 (19:18 -0400)
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 <jmulligan@redhat.com>
(cherry picked from commit bbd7933598e11d84758a6f09fd176f47c744aaa2)

install-deps.sh
src/script/lib-build.sh

index cc7e15a6250a4769fb6aff56bc34fa11c4c1a479..0d56b0d5c9d8910362235f2fc1f0c4ae5f0dfc9b 100755 (executable)
@@ -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
index 0e915831a51aa3b0019caf333275debc9e67bbf8..0c131a7a3ea1b5e7f0be1d76847f3990614c8933 100644 (file)
@@ -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