diff options
author | Leah Rowe <leah@libreboot.org> | 2025-04-11 20:04:53 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2025-04-11 20:04:53 +0100 |
commit | 5a0a24f555985c772b8414fe88a5862d23491956 (patch) | |
tree | 17a636d738385a1fc3a9adc6db8d0899901e6f23 /include/lib.sh | |
parent | a25a29cfbb7578ed44e862cc6a4ff019c340f499 (diff) |
lbmk: unified PWD handling (work directory)
instead of running pwd all the time, run it once in lib.sh,
and export PWD.
for lbmk-specific use of PWD, use xbmkpwd, which contains
the value of PWD as was set by the pwd utility in lib.sh.
many parts of lbmk rely on pwd, and it *must* be correct.
this change adds basic error handling, since pwd can in
fact return errors in some cases.
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'include/lib.sh')
-rw-r--r-- | include/lib.sh | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/include/lib.sh b/include/lib.sh index 5f87b9fa..a3cdf554 100644 --- a/include/lib.sh +++ b/include/lib.sh @@ -15,7 +15,6 @@ _ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0" ifdtool="elf/ifdtool/default/ifdtool" cbfstool="elf/cbfstool/default/cbfstool" rmodtool="elf/cbfstool/default/rmodtool" -tmpgit="`pwd`/tmp/gitclone" grubdata="config/data/grub" err="err_" @@ -25,6 +24,9 @@ err_() exit 1 } +xbmkpwd=`pwd` || $err "Cannot generate PWD" +export PWD="$xbmkpwd" + setvars() { _setvars="" && [ $# -lt 2 ] && $err "setvars: too few arguments" @@ -106,18 +108,18 @@ id -u 1>/dev/null 2>/dev/null || $err "suid check failed (id -u)" [ "$(id -u)" != "0" ] || $err "this command as root is not permitted" # XBMK_CACHE is a directory, for caching downloads and git repositories -[ -z "${XBMK_CACHE+x}" ] && export XBMK_CACHE="`pwd`/cache" -[ -z "$XBMK_CACHE" ] && export XBMK_CACHE="`pwd`/cache" -[ -L "$XBMK_CACHE" ] && [ "$XBMK_CACHE" = "`pwd`/cache" ] && \ - $err "cachedir is default, `pwd`/cache, but it exists and is a symlink" -[ -L "$XBMK_CACHE" ] && export XBMK_CACHE="`pwd`/cache" +[ -z "${XBMK_CACHE+x}" ] && export XBMK_CACHE="$xbmkpwd/cache" +[ -z "$XBMK_CACHE" ] && export XBMK_CACHE="$xbmkpwd/cache" +[ -L "$XBMK_CACHE" ] && [ "$XBMK_CACHE" = "$xbmkpwd/cache" ] && \ + $err "cachedir is default, $xbmkpwd/cache, but it exists and is a symlink" +[ -L "$XBMK_CACHE" ] && export XBMK_CACHE="$xbmkpwd/cache" [ -f "$XBMK_CACHE" ] && $err "cachedir '$XBMK_CACHE' exists but it's a file" # unify all temporary files/directories in a single TMPDIR [ -z "${TMPDIR+x}" ] || [ "${TMPDIR%_*}" = "/tmp/xbmk" ] || unset TMPDIR [ -n "${TMPDIR+x}" ] && export TMPDIR="$TMPDIR" if [ -z "${TMPDIR+x}" ]; then - [ -f "lock" ] && $err "`pwd`/lock exists. Is a build running?" + [ -f "lock" ] && $err "$xbmkpwd/lock exists. Is a build running?" export TMPDIR="/tmp" export TMPDIR="$(mktemp -d -t xbmk_XXXXXXXX)" touch lock || $err "cannot create 'lock' file" |