From 1b7d5b5f7f99df8ea9ed7635659abd40248b77b3 Mon Sep 17 00:00:00 2001 From: pancake Date: Tue, 23 Oct 2018 22:22:38 +0200 Subject: [PATCH] Downgrade credentials when building with sudo ##build --- sys/build.sh | 11 ++++++----- sys/install.sh | 11 +++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sys/build.sh b/sys/build.sh index d45c7ec967..08dd02c897 100755 --- a/sys/build.sh +++ b/sys/build.sh @@ -38,11 +38,12 @@ BuildJobsThrottler(){ echo "So, the build will run on $MAKE_JOBS job(s)." } -# Identify current platform -GetPlatform - -# Define number of parallel jobs as function of resources and platform -BuildJobsThrottler +if [ "`uname`" = Linux ]; then + # Identify current platform + GetPlatform + # Define number of parallel jobs depending on ncpus and memory + BuildJobsThrottler +fi if [ -z "${MAKE}" ]; then MAKE=make diff --git a/sys/install.sh b/sys/install.sh index 024d243c88..b35d3f8c41 100755 --- a/sys/install.sh +++ b/sys/install.sh @@ -4,6 +4,17 @@ MAKE=make gmake --help >/dev/null 2>&1 [ $? = 0 ] && MAKE=gmake +# if owner of sys/install.sh != uid && uid == 0 { exec sudo -u id -A $SUDO_UID sys/install.sh $* } + +if [ "${UID}" = 0 ]; then + echo "[XX] Do not run this script as root!" + if [ -n "${SUDO_USER}" ]; then + echo "[--] Downgrading credentials to ${SUDO_USER}" + exec sudo -u "${SUDO_USER}" sys/install.sh $* + fi + exit 1 +fi + ${MAKE} --help 2>&1 | grep -q gnu if [ $? != 0 ]; then echo "You need GNU Make to build me"