sha256-tarball-to: Support zipfiles.

This commit is contained in:
Alex Vandiver
2025-03-27 18:07:37 +00:00
committed by Tim Abbott
parent bd54f0363e
commit ba9569a6fe

View File

@@ -1,4 +1,4 @@
#!/bin/sh #!/usr/bin/env bash
if [ "$#" -lt 4 ]; then if [ "$#" -lt 4 ]; then
echo "Usage:" echo "Usage:"
@@ -23,15 +23,29 @@ tmpdir="$(mktemp -d)"
trap 'rm -r "$tmpdir"' EXIT trap 'rm -r "$tmpdir"' EXIT
cd "$tmpdir" cd "$tmpdir"
# We support both .tar.gz and .zip files
if [[ "$URL" == *.tar.gz ]] || [[ "$URL" == *.tgz ]]; then
extension="tar.gz"
elif [[ "$URL" == *.zip ]]; then
extension="zip"
else
echo "Can't determine archive type from URL: $URL"
exit 1
fi
# Fetch to a predictable name, not whatever curl guesses from the URL # Fetch to a predictable name, not whatever curl guesses from the URL
LOCALFILE="archive.tar.gz" LOCALFILE="archive.$extension"
curl -fL --retry 3 -o "$LOCALFILE" "$URL" curl -fL --retry 3 -o "$LOCALFILE" "$URL"
# Check the hash against what was passed in # Check the hash against what was passed in
echo "$SHA256 $LOCALFILE" >"$LOCALFILE.sha256" echo "$SHA256 $LOCALFILE" >"$LOCALFILE.sha256"
sha256sum -c "$LOCALFILE.sha256" sha256sum -c "$LOCALFILE.sha256"
if [[ "$extension" == "tar.gz" ]]; then
tar xzf "$LOCALFILE" tar xzf "$LOCALFILE"
else
unzip "$LOCALFILE"
fi
# Take the rest of the arguments two-at-a-time, as source and # Take the rest of the arguments two-at-a-time, as source and
# destination to move out of the unpacked tarball. # destination to move out of the unpacked tarball.