commit: f74127556dade2c7434517caf16967e452787d79
parent 64dcee6008ce4d8704babb9a107fd0afdb6f4993
Author: Michael Forney <mforney@mforney.org>
Date: Fri, 8 May 2020 13:05:22 -0700
Detect decompression tool automatically
This fixes cross-compilation from macOS, whose bsdtar does support
xz through liblzma, but does not have xz(1).
Diffstat:
5 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/pkg/git/fetch.sh b/pkg/git/fetch.sh
@@ -1,5 +1,4 @@
: "${SHA256SUM:=sha256sum}"
-: "${PAXREAD:=pax -r}"
set -e
@@ -18,4 +17,4 @@ if ! $SHA256SUM -c sha256 2>/dev/null ; then
fi
read -r _ archive <sha256
-gzip -d -c "$archive" | $PAXREAD -s ',^\.,src/man,'
+sh "$OLDPWD/scripts/extract.sh" "$archive" -s ',^\.,src/man,'
diff --git a/pkg/linux-headers/fetch.sh b/pkg/linux-headers/fetch.sh
@@ -1,5 +1,4 @@
: "${SHA256SUM:=sha256sum}"
-: "${PAXREAD:=pax -r}"
set -e
@@ -18,8 +17,7 @@ if ! $SHA256SUM -c sha256 2>/dev/null ; then
fi
read -r _ archive <sha256
-
-xz -d -c "$archive" | $PAXREAD -s ',^[^/]*,src,' \
+sh "$OLDPWD/scripts/extract.sh" "$archive" -s ',^[^/]*,src,' \
'linux-*/Makefile' \
'linux-*/arch/*/include/uapi' \
'linux-*/arch/*/syscalls' \
diff --git a/pkg/openbsd/fetch.sh b/pkg/openbsd/fetch.sh
@@ -1,5 +1,4 @@
: "${SHA256SUM:=sha256sum}"
-: "${PAXREAD:=pax -r}"
set -e
@@ -17,7 +16,7 @@ if ! $SHA256SUM -c sha256 2>/dev/null ; then
$SHA256SUM -c sha256
fi
-gzip -d -c src.tar.gz | $PAXREAD -s ',^,src/,' \
+sh "$OLDPWD/scripts/extract.sh" src.tar.gz -s ',^,src/,' \
'bin/pax/*' \
'include/*' \
'lib/libc/*' \
@@ -32,6 +31,6 @@ gzip -d -c src.tar.gz | $PAXREAD -s ',^,src/,' \
'usr.bin/rsync/*' \
'usr.bin/yacc/*' \
'usr.sbin/acme-client/*'
-gzip -d -c sys.tar.gz | $PAXREAD -s ',^,src/,' 'sys/sys/*'
+sh "$OLDPWD/scripts/extract.sh" sys.tar.gz -s ',^,src/,' 'sys/sys/*'
git apply -v --whitespace=nowarn --directory "$dir/src" patch/*
diff --git a/scripts/extract.sh b/scripts/extract.sh
@@ -0,0 +1,18 @@
+file=$1
+shift
+
+case $file in
+*.tar.gz|*.tgz) tool=gzip ;;
+*.tar.bz2) tool=bzip2 ;;
+*.tar.xz) tool=xz ;;
+*) exit 0
+esac
+
+if command -v bsdtar >/dev/null; then
+ exec bsdtar -xf "$file" "$@"
+elif command -v pax >/dev/null; then
+ "$tool" -d -c "$file" | pax "$@"
+else
+ printf '%s: bsdtar or pax is required' "$0" >&2
+ exit 1
+fi
diff --git a/scripts/fetch-curl.sh b/scripts/fetch-curl.sh
@@ -1,5 +1,4 @@
: "${SHA256SUM:=sha256sum}"
-: "${PAXREAD:=pax -r}"
set -e
@@ -23,19 +22,7 @@ if ! $SHA256SUM -c sha256 2>/dev/null ; then
fi
while read -r _ archive ; do
- case $archive in
- *.tar.gz|*.tgz)
- tool=gzip ;;
- *.tar.bz2)
- tool=bzip2 ;;
- *.tar.xz)
- tool=xz ;;
- *)
- tool=
- esac
- if [ -n "$tool" ] ; then
- "$tool" -d -c "$archive" | $PAXREAD -s ',^[^/]*,src,' '*/*'
- fi
+ sh "$OLDPWD/scripts/extract.sh" "$archive" -s ',^[^/]*,src,' '*/*'
done <sha256
if [ -d patch ] ; then