diff --git a/shellscripts/goto_build_dir.sh b/shellscripts/goto_build_dir.sh index 5003cbbb32ae0c3c0eb304a44dfeea9952d78949..456847cc60105adbca2a2c9f41bb1da2984ca5de 100755 --- a/shellscripts/goto_build_dir.sh +++ b/shellscripts/goto_build_dir.sh @@ -7,9 +7,10 @@ # # ---------------------------------------------------------------------- # 2024-01-19 v1.0 <axel.hahn@iml.unibe.ch> first lines +# 2024-07-25 v1.1 <axel.hahn@iml.unibe.ch> deny root access; shell fixes # ====================================================================== -cd $( dirname $0 )/.. +cd "$( dirname "$0" )/.." || exit 1 CI_APPROOT=$( pwd ) # ---------------------------------------------------------------------- @@ -24,6 +25,14 @@ cat <<HEADEREND HEADEREND +# ---------------------------------------------------------------------- +# deny start as root +# ---------------------------------------------------------------------- +if [ "$( id -u )" -eq 0 ]; then + echo "ERROR: do not start this script as root." + exit 1 +fi + # ---------------------------------------------------------------------- # detect workdir # ---------------------------------------------------------------------- @@ -42,9 +51,9 @@ builddir="$CI_WORKDIR/build/" # detect builds on error # ---------------------------------------------------------------------- -ls $builddir >/dev/null || exit 1 +ls "$builddir" >/dev/null || exit 1 echo "Searching for builds im $builddir..." -founddirs=$( find $builddir -maxdepth 2 -type d | grep '2[0-1][0-9][0-9][0-1][0-9][0-3][0-9]' | sort ) +founddirs=$( find "$builddir" -maxdepth 2 -type d | grep '2[0-1][0-9][0-9][0-1][0-9][0-3][0-9]' | sort ) if [ -z "$founddirs" ]; then echo "Good news: No build dirs (builds on error) were found. Aborting." @@ -69,7 +78,6 @@ echo -n "I want to jump to > " read -r DIR_APPROOT test -z "$DIR_APPROOT" && exit 1 -# DIR_APPROOT="/var/imldeployment/build/$DIR_APPROOT" ls "$DIR_APPROOT" >/dev/null || exit 2 # ---------------------------------------------------------------------- @@ -82,7 +90,7 @@ export DIR_SSH_KEYS="$CI_WORKDIR/data/sshkeys" export NVMINIT="$CI_APPROOT/shellscripts/nvm_init.sh"; export RVMSCRIPT="/usr/local/rvm/scripts/rvm"; -cd "$DIR_APPROOT" +cd "$DIR_APPROOT" || exit 1 cat <<EOF * Switching now into build dir