From cbac00465beaf10735be583de84198cfc3ec681f Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 23 Nov 2020 14:06:11 -0700 Subject: [PATCH] install.sh: cache root check Only run the `id -u` command to check for root once. Cache the result and use that instead of running it 3 times. Signed-off-by: Kyle J. McKay --- install.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 11f4345..bd7ccde 100755 --- a/install.sh +++ b/install.sh @@ -42,7 +42,9 @@ die() { warn "$@"; exit 1; } # Either we must run as root (but preferably not if disable_jailsetup is true) # or the mirror_user (preferred choice for disable_jailsetup). -if [ "$(id -u)" -eq 0 ]; then +isroot= +[ "$(id -u)" -ne 0 ] || isroot=1 +if [ -n "$isroot" ]; then if [ "${cfg_disable_jailsetup:-0}" != "0" ]; then cat <<'EOT' @@ -792,7 +794,7 @@ chmod 00755 "$cfg_reporoot/_global" "$cfg_reporoot/_global/hooks" "$cfg_reporoot if [ "${cfg_disable_jailsetup:-0}" = "0" ] && [ -n "$cfg_chrooted" ]; then echo "*** Setting up chroot jail for pushing..." - if [ "$(id -u)" -eq 0 ]; then + if [ -n "$isroot" ]; then # jailsetup may install things from $cfg_basedir/bin into the # chroot so we do a mini-update of just that portion now mkdir -p "$cfg_basedir" @@ -814,7 +816,7 @@ fi echo "*** Setting up jail configuration (project database)..." -[ "$(id -u)" -eq 0 ] || ./jailsetup.sh dbonly +[ -n "$isroot" ] || ./jailsetup.sh dbonly mkdir -p "$cfg_chroot" "$cfg_chroot/etc" touch "$cfg_chroot/etc/passwd" "$cfg_chroot/etc/group" chown "$cfg_mirror_user""$owngroup" "$cfg_chroot/etc" || -- 2.11.4.GIT