From 3c70b5d4b0a9c7fd7d1c27022150227a95625b19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Hertzog?= Date: Wed, 24 Dec 2014 10:37:41 +0100 Subject: [PATCH] Allow running build_all.sh as non-root with sudo --- build_all.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/build_all.sh b/build_all.sh index a4d09b2..6804566 100755 --- a/build_all.sh +++ b/build_all.sh @@ -5,6 +5,16 @@ set -e KALI_DIST=kali KALI_VERSION="${VERSION:-daily}" TARGET_DIR=$(dirname $0)/images/kali-$KALI_VERSION +SUDO="" + +# We need root rights at some point +if [ "$(whoami)" != "root" ]; then + if ! which sudo >/dev/null; then + echo "ERROR: $0 is not run as root and sudo is not available" + exit 1 + fi + SUDO=sudo +fi HOST_ARCH="$(dpkg --print-architecture)" case "$HOST_ARCH" in @@ -82,9 +92,9 @@ mkdir -p $TARGET_DIR for KALI_ARCH in $KALI_ARCHES; do IMAGE_NAME=$(echo $IMAGE_TEMPLATE | sed -e "s/ARCH/$KALI_ARCH/") - lb clean --purge >prepare.log 2>&1 + $SUDO lb clean --purge >prepare.log 2>&1 lb config -a $KALI_ARCH $KALI_CONFIG_OPTS >>prepare.log 2>&1 - lb build >/dev/null + $SUDO lb build >/dev/null if [ $? -ne 0 ] || [ ! -e $IMAGE_NAME ]; then echo "Build of $KALI_DIST/$KALI_ARCH live image failed" >&2 echo "Last 50 lines of the log:" >&2