Skip to content

Commit bbd7933

Browse files
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 <[email protected]>
1 parent c51c6cd commit bbd7933

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

install-deps.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ fi
2323
DIR=/tmp/install-deps.$$
2424
trap "rm -fr $DIR" EXIT
2525
mkdir -p $DIR
26-
if test $(id -u) != 0 ; then
27-
SUDO=sudo
28-
fi
26+
wrap_sudo
2927
# enable UTF-8 encoding for programs like pip that expect to
3028
# print more than just ascii chars
3129
export LC_ALL=C.UTF-8

src/script/lib-build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ function ci_debug() {
3232
fi
3333
}
3434

35+
function wrap_sudo() {
36+
# set or unset the SUDO env var so that scripts already running
37+
# as root do not call into sudo to escalate privs
38+
if test $(id -u) != 0 ; then
39+
SUDO=sudo
40+
else
41+
SUDO=""
42+
fi
43+
}
44+
3545
# get_processors returns 1/2 the value of the value returned by
3646
# the nproc program OR the value of the environment variable NPROC
3747
# allowing the user to tune the number of cores visible to the

0 commit comments

Comments
 (0)