summaryrefslogtreecommitdiff
path: root/include/lib.sh
diff options
context:
space:
mode:
Diffstat (limited to 'include/lib.sh')
-rw-r--r--[-rwxr-xr-x]include/lib.sh58
1 files changed, 36 insertions, 22 deletions
diff --git a/include/lib.sh b/include/lib.sh
index 52187734..c5df639c 100755..100644
--- a/include/lib.sh
+++ b/include/lib.sh
@@ -7,8 +7,6 @@ export LC_COLLATE=C
export LC_ALL=C
_ua="Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0"
-kbnotice="Insert a .gkb file from config/data/grub/keymap/ as keymap.gkb \
-if you want a custom keymap in GRUB; use cbfstool from elf/cbfstool."
ifdtool="elf/ifdtool/default/ifdtool"
cbfstool="elf/cbfstool/default/cbfstool"
@@ -37,7 +35,7 @@ chkvars()
}
eval `setvars "" _nogit board xbmk_parent versiondate projectsite projectname \
- aur_notice cfgsdir datadir version relname`
+ aur_notice configdir datadir version relname`
for fv in projectname projectsite version versiondate; do
eval "[ ! -f "$fv" ] || read -r $fv < \"$fv\" || :"
@@ -58,8 +56,7 @@ e()
estr="[ -$es_t \"\$1\" ] || return 1"
[ $# -gt 2 ] && estr="[ -$es_t \"\$1\" ] && return 1" && es2="missing"
- eval "$estr"
- printf "%s %s\n" "$1" "$es2" 1>&2
+ eval "$estr"; printf "%s %s\n" "$1" "$es2" 1>&2
}
install_packages()
@@ -88,6 +85,14 @@ if [ -z "${TMPDIR+x}" ]; then
xbmk_parent="y"
fi
+# 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"
+[ -f "$XBMK_CACHE" ] && $err "cachedir '$XBMK_CACHE' exists but it's a file"
+
# 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"
@@ -98,7 +103,8 @@ expr "X$XBMK_THREADS" : "X-\{0,1\}[0123456789][0123456789]*$" \
1>/dev/null 2>/dev/null || export XBMK_THREADS=1 # user gave a non-integer
x_() {
- [ $# -lt 1 ] || $@ || $err "Unhandled non-zero exit: $@"; return 0
+ [ $# -lt 1 ] || $@ || \
+ $err "Unhandled non-zero exit: $(echo "$@")"; return 0
}
[ -e ".git" ] || [ -f "version" ] || printf "unknown\n" > version || \
@@ -113,8 +119,7 @@ versiondate_="$versiondate"
[ ! -e ".git" ] || versiondate="$(git show --no-patch --no-notes \
--pretty='%ct' HEAD)" || versiondate="$versiondate_"
for p in projectname version versiondate projectsite; do
- chkvars "$p"
- eval "x_ printf \"%s\\n\" \"\$$p\" > $p"
+ chkvars "$p"; eval "x_ printf \"%s\\n\" \"\$$p\" > $p"
done
relname="$projectname-$version"
export LOCALVERSION="-$projectname-${version%%-*}"
@@ -139,8 +144,7 @@ mkrom_tarball()
printf "%s\n" "$versiondate" > "$1/versiondate" || $err "$1 !vdate"
printf "%s\n" "$projectname" > "$1/projectname" || $err "$1 !pname"
- mktarball "$1" "${1%/*}/${relname}_${1##*/}.tar.xz"
- x_ rm -Rf "$1"
+ mktarball "$1" "${1%/*}/${relname}_${1##*/}.tar.xz"; x_ rm -Rf "$1"; :
}
mktarball()
@@ -174,31 +178,33 @@ rmgit()
singletree()
{
for targetfile in "config/${1}/"*/target.cfg; do
- [ -e "$targetfile" ] && [ -f "$targetfile" ] && return 1
+ [ -e "$targetfile" ] && [ -f "$targetfile" ] && return 1; :
done; return 0
}
download()
{
- dl_fail="y" # 1 url, 2 url backup, 3 destination, 4 checksum
- vendor_checksum "$4" "$3" 2>/dev/null || dl_fail="n"
+ cached="$XBMK_CACHE/file/$4"
+ dl_fail="n" # 1 url, 2 url backup, 3 destination, 4 checksum
+ vendor_checksum "$4" "$cached" 2>/dev/null && dl_fail="y"
[ "$dl_fail" = "n" ] && e "$3" f && return 0
- x_ mkdir -p "${3%/*}" && for url in "$1" "$2"; do
+ mkdir -p "${3%/*}" "$XBMK_CACHE/file" || \
+ $err "!mkdir '$3' '$XBMK_CACHE/file'"
+ for url in "$1" "$2"; do
[ "$dl_fail" = "n" ] && break
[ -z "$url" ] && continue
- x_ rm -f "$3"
- curl --location --retry 3 -A "$_ua" "$url" -o "$3" || \
- wget --tries 3 -U "$_ua" "$url" -O "$3" || continue
- vendor_checksum "$4" "$3" || dl_fail="n"
- done;
- [ "$dl_fail" = "y" ] && $err "$1 $2 $3 $4: not downloaded"; return 0
+ rm -f "$cached" || $err "!rm -f '$cached'"
+ curl --location --retry 3 -A "$_ua" "$url" -o "$cached" || \
+ wget --tries 3 -U "$_ua" "$url" -O "$cached" || continue
+ vendor_checksum "$4" "$cached" || dl_fail="n"
+ done; [ "$dl_fail" = "y" ] && $err "$1 $2 $3 $4: not downloaded"
+ [ "$cached" = "$3" ] || cp "$cached" "$3" || $err "!d cp $cached $3"; :
}
vendor_checksum()
{
[ "$(sha512sum "$2" | awk '{print $1}')" != "$1" ] || return 1
- printf "Bad checksum for file: %s\n" "$2" 1>&2
- rm -f "$2" || :
+ printf "Bad checksum for file: %s\n" "$2" 1>&2; rm -f "$2" || :; :
}
cbfs()
@@ -207,3 +213,11 @@ cbfs()
lzma="-c lzma" && [ $# -gt 3 ] && lzma="-t raw"
x_ "$cbfstool" "$1" $ccmd -f "$2" -n "$3" $lzma
}
+
+mk()
+{
+ mk_flag="$1" || $err "No argument given"
+ shift 1 && for mk_arg in $@; do
+ ./mk $mk_flag $mk_arg || $err "./mk $mk_flag $mk_arg"; :
+ done; :
+}