55 lines
1.5 KiB
Bash
Executable File
55 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
# Fetches the ANISE kernels listed in data/kernels.tsv and verifies their
|
|
# checksums. Idempotent: a file that is already present and correct is left alone.
|
|
#
|
|
# Usage: scripts/fetch-kernels.sh [directory]
|
|
# ASTROKIT_KERNELS=/somewhere scripts/fetch-kernels.sh
|
|
|
|
set -e
|
|
|
|
root=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
manifest="$root/data/kernels.tsv"
|
|
target=${1:-${ASTROKIT_KERNELS:-$root/data/kernels}}
|
|
|
|
if [ ! -f "$manifest" ]; then
|
|
echo "no manifest at $manifest" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$target"
|
|
echo "kernels -> $target"
|
|
|
|
status=0
|
|
while IFS="$(printf '\t')" read -r name sha downloaded url purpose; do
|
|
case "$name" in '' | \#*) continue ;; esac
|
|
|
|
path="$target/$name"
|
|
if [ -f "$path" ] && [ "$(sha256sum "$path" | cut -d' ' -f1)" = "$sha" ]; then
|
|
echo " ok $name"
|
|
continue
|
|
fi
|
|
|
|
echo " fetching $name (pinned $downloaded)"
|
|
if ! curl -sfL --retry 3 -o "$path.partial" "$url"; then
|
|
echo " FAILED $name: could not download $url" >&2
|
|
rm -f "$path.partial"
|
|
status=1
|
|
continue
|
|
fi
|
|
|
|
got=$(sha256sum "$path.partial" | cut -d' ' -f1)
|
|
if [ "$got" != "$sha" ]; then
|
|
echo " FAILED $name: checksum mismatch" >&2
|
|
echo " expected $sha" >&2
|
|
echo " got $got" >&2
|
|
rm -f "$path.partial"
|
|
status=1
|
|
continue
|
|
fi
|
|
|
|
mv "$path.partial" "$path"
|
|
echo " verified $name"
|
|
done < "$manifest"
|
|
|
|
exit $status
|