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)
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
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