From: Michael Tremer Date: Thu, 4 Jul 2024 19:05:37 +0000 (+0000) Subject: make.sh: Refactor determining BASEDIR X-Git-Tag: v2.29-core188~10^2~366 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=510dd732ea1c33c7d6629876ce2f140d7880fa1f;p=ipfire-2.x.git make.sh: Refactor determining BASEDIR Signed-off-by: Michael Tremer --- diff --git a/make.sh b/make.sh index d3750be61a..cdc76fc9ff 100755 --- a/make.sh +++ b/make.sh @@ -64,7 +64,6 @@ NORMAL="\\033[0;39m" HOST_ARCH="$(uname -m)" PWD=$(pwd) -BASENAME=$(basename $0) # Sets or adjusts pretty formatting variables resize_terminal() { @@ -94,6 +93,27 @@ resize_terminal # Call resize_terminal when terminal is being resized trap "resize_terminal" WINCH +find_base() { + local path + + # Figure out the absolute script path using readlink + path="$(readlink -f "${0}" 2>&1)" + + # If that failed, try realpath + if [ -z "${path}" ]; then + path="$(realpath "${0}" 2>&1)" + fi + + # If that failed, I am out of ideas + if [ -z "${path}" ]; then + echo "${0}: Could not determine BASEDIR" >&2 + return 1 + fi + + # Return the dirname + dirname "${path}" +} + system_processors() { getconf _NPROCESSORS_ONLN 2>/dev/null || echo "1" } @@ -1816,20 +1836,8 @@ exec_in_namespace() { "${0}" "$@" } -# Debian specific settings -if [ ! -e /etc/debian_version ]; then - FULLPATH=`which $0` -else - if [ -x /usr/bin/realpath ]; then - FULLPATH=`/usr/bin/realpath $0` - else - echo "ERROR: Need to do apt-get install realpath" - exit 1 - fi -fi - -# This is the directory where make.sh is in -export BASEDIR=$(echo $FULLPATH | sed "s/\/$BASENAME//g") +# Set BASEDIR +readonly BASEDIR="$(find_base)" LOGFILE=$BASEDIR/log/_build.preparation.log export LOGFILE