summaryrefslogtreecommitdiff
path: root/scripts/extract.sh
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2020-05-08 13:05:22 -0700
committerMichael Forney <mforney@mforney.org>2020-05-08 13:05:22 -0700
commitf74127556dade2c7434517caf16967e452787d79 (patch)
tree1227b2bce10bcd9878f3944800a34d7dfaded272 /scripts/extract.sh
parent64dcee6008ce4d8704babb9a107fd0afdb6f4993 (diff)
Detect decompression tool automatically
This fixes cross-compilation from macOS, whose bsdtar does support xz through liblzma, but does not have xz(1).
Diffstat (limited to 'scripts/extract.sh')
-rw-r--r--scripts/extract.sh18
1 files changed, 18 insertions, 0 deletions
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