From f74127556dade2c7434517caf16967e452787d79 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Fri, 8 May 2020 13:05:22 -0700 Subject: Detect decompression tool automatically This fixes cross-compilation from macOS, whose bsdtar does support xz through liblzma, but does not have xz(1). --- scripts/extract.sh | 18 ++++++++++++++++++ scripts/fetch-curl.sh | 15 +-------------- 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 scripts/extract.sh (limited to 'scripts') diff --git a/scripts/extract.sh b/scripts/extract.sh new file mode 100644 index 00000000..1ffc23f8 --- /dev/null +++ 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 index 1e35c68d..80d70ee0 100644 --- 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