#!/usr/bin/env bash
#
# fetch.sh
[vectors]
#
# Fetch the files of draft-ietf-mlcodec-opus-dred-07 that the corpus names by digest and does not
# hold, into , and check each against the SHA-256 the draft states (§7.1):
#
# dred_unquantized_weights.bin the decoder weights ([DRED-Weights]): the profile's parameter set
# dred_testvectors.tar.gz the conformance test vectors ([DRED-Test-Vectors]), with
# `vectors`, unpacked into /dred_testvectors/ (the
# measurement of extensions/opus-dred.md §6 reads them)
#
# A file already in with the right digest is not fetched again. A digest that does not match
# fails, and the file is removed. The locations are the draft's own references.
set -euo pipefail
dir=${1:?usage: fetch.sh [vectors]}
base="https://media.xiph.org/opus/ietf/dred_material"
mkdir -p "$dir"
sha() { if command -v sha256sum >/dev/null; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi; }
get() {
local name=$1 want=$2
if [ -f "$dir/$name" ] && [ "$(sha "$dir/$name")" = "$want" ]; then return 0; fi
curl -sSfL --retry 3 -o "$dir/$name.part" "$base/$name"
local got
got=$(sha "$dir/$name.part")
if [ "$got" != "$want" ]; then
rm -f "$dir/$name.part"
echo "fetch.sh: $name has SHA-256 $got, not $want" >&2
exit 1
fi
mv "$dir/$name.part" "$dir/$name"
}
get dred_unquantized_weights.bin 394f0ecf19926cebd678019dc94a54c88ae078340c16325069707f286cdf28a6
if [ "${2:-}" = vectors ]; then
get dred_testvectors.tar.gz 0af7a068783d9d1397a67ed7896615d0777fb69fa258e4f192dea4f61226ad31
if [ ! -d "$dir/dred_testvectors" ]; then
tar -xzf "$dir/dred_testvectors.tar.gz" -C "$dir"
fi
fi
echo "fetch.sh: $dir holds the pinned files"