diff options
| author | Leah Rowe <leah@libreboot.org> | 2025-05-18 11:54:51 +0100 | 
|---|---|---|
| committer | Leah Rowe <leah@libreboot.org> | 2025-05-18 12:02:51 +0100 | 
| commit | ac36ea7f950a88e56be82e046004c9780c9e0803 (patch) | |
| tree | 1a1f754f24c80538f683fc1d30f508be3071175e /include | |
| parent | 484afcb91969b9325c448a6a77ad97a4813f7bfb (diff) | |
init.sh: initialise variables AFTER path
That way, unnecessary work is avoided on child instances.
Of course, the current check assumes that TMPDIR wasn't
already set by a wily user before running lbmk, but then
those sorts of users probably know what they're doing.
If they don't know, they will soon find out. Therefore, I
have added additional checks on child instances, preventing
the build system from running if XBMK_CACHE is not set; if
it isn't, then that could very easy lead to certain system
files being overwritten.
The user must never know what happens if XBMK_CACHE is unset.
We simply will not allow it.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/init.sh | 37 | 
1 files changed, 23 insertions, 14 deletions
| diff --git a/include/init.sh b/include/init.sh index 13592d83..363f0b18 100644 --- a/include/init.sh +++ b/include/init.sh @@ -76,9 +76,29 @@ xbmk_set_version()  xbmk_set_env()  { +	is_child="n" +  	xbmkpath="$PATH"  	export LOCALVERSION="-$projectname-${version%%-*}" +	# unify all temporary files/directories in a single TMPDIR +	[ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || \ +	    unset TMPDIR +	[ -n "${TMPDIR+x}" ] && export TMPDIR="$TMPDIR" && xbmktmp="$TMPDIR" +	[ -z "${TMPDIR+x}" ] || is_child="y" # child instance, so return + +	if [ "$is_child" = "y" ]; then +		[ -z "${XBMK_CACHE+x}" ] && err "XBMK_CACHE unset on child" +		[ -z "${XBMK_THREADS+x}" ] && err "XBMK_THREADS unset on child" +		e "lock" f missing && err "lock file absent on child" +		return 1 +	fi + +	# parent instance of xbmk, so don't return. set up TMPDIR +	export TMPDIR="/tmp" +	export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" +	xbmktmp="$TMPDIR" +  	# XBMK_CACHE is a directory, for caching downloads and git repon  	[ -z "${XBMK_CACHE+x}" ] && export XBMK_CACHE="$xbmkpwd/cache"  	[ -z "$XBMK_CACHE" ] && export XBMK_CACHE="$xbmkpwd/cache" @@ -91,6 +111,9 @@ xbmk_set_env()  	[ ! -e "$XBMK_CACHE" ] || \  	    [ -d "$XBMK_CACHE" ] || err "cachedir '$XBMK_CACHE' is a file"; : +	export PATH="$XBMK_CACHE/xbmkpath:$XBMK_CACHE/gnupath:$PATH" +	xbmkpath="$PATH" +  	# if "y": a coreboot target won't be built if target.cfg says release="n"  	# (this is used to exclude certain build targets from releases)  	[ -z "${XBMK_RELEASE+x}" ] && export XBMK_RELEASE="n" @@ -100,20 +123,6 @@ xbmk_set_env()  	[ -z "${XBMK_THREADS+x}" ] && export XBMK_THREADS=1  	expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \  	    1>/dev/null 2>/dev/null || export XBMK_THREADS=1; : - -	# unify all temporary files/directories in a single TMPDIR -	[ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || \ -	    unset TMPDIR -	[ -n "${TMPDIR+x}" ] && export TMPDIR="$TMPDIR" && xbmktmp="$TMPDIR" -	[ -z "${TMPDIR+x}" ] || return 1 # child instance, so return - -	# parent instance of xbmk, so don't return. set up TMPDIR -	export TMPDIR="/tmp" -	export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" -	xbmktmp="$TMPDIR" - -	export PATH="$XBMK_CACHE/xbmkpath:$XBMK_CACHE/gnupath:$PATH" -	xbmkpath="$PATH"  }  xbmk_lock() | 
