nim-eth2-scenarios/download_test_vectors.sh

109 lines
2.8 KiB
Bash
Raw Normal View History

2021-11-15 13:43:05 +00:00
#!/usr/bin/env bash
# Copyright (c) 2019-2023 Status Research & Development GmbH. Licensed under
# either of:
# - Apache License, version 2.0
# - MIT license
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
2023-04-19 15:37:49 +00:00
set -eu
VERSIONS=(
"v1.4.0-beta.7"
)
2019-10-31 16:51:36 +00:00
FLAVOURS=(
2019-11-09 09:02:34 +00:00
"general"
"minimal"
"mainnet"
2019-10-31 16:51:36 +00:00
)
# signal handler (we only care about the Ctrl+C generated SIGINT)
REL_PATH="$(dirname "${BASH_SOURCE[0]}")"
ABS_PATH="$(cd "${REL_PATH}"; pwd)"
cleanup() {
echo -e "\nCtrl+C pressed. Cleaning up."
cd "$ABS_PATH"
rm -rf tarballs tests-*
exit 1
}
trap cleanup SIGINT
2019-10-31 16:51:36 +00:00
dl_version() {
[[ -z "$1" ]] && { echo "usage: dl_version() vX.Y.Z"; exit 1; }
version="$1"
2019-10-31 16:51:36 +00:00
mkdir -p "tarballs/${version}"
pushd "tarballs/${version}" >/dev/null
for flavour in "${FLAVOURS[@]}"; do
if [[ ! -e "${flavour}.tar.gz" ]]; then
echo "Downloading: ${version}/${flavour}.tar.gz"
curl --location --remote-name --silent --show-error --retry 3 --retry-connrefused \
"https://github.com/ethereum/consensus-spec-tests/releases/download/${version}/${flavour}.tar.gz" \
2019-10-31 16:51:36 +00:00
|| {
echo "Curl failed. Aborting"
rm -f "${flavour}.tar.gz"
exit 1
}
fi
done
popd >/dev/null
}
unpack_version() {
[[ -z "$1" ]] && { echo "usage: unpack_version() vX.Y.Z"; exit 1; }
version="$1"
local retries=0 ok=0
while (( !ok && ++retries <= 5 )); do # downloaded tar.gz may be corrupted
dl_version "$version"
2019-10-31 16:51:36 +00:00
# suppress warnings when unpacking with GNU tar an archive created with BSD tar (probably on macOS)
EXTRA_TAR_PARAMS=""
tar --version | grep -qi 'gnu' && EXTRA_TAR_PARAMS="--warning=no-unknown-keyword --ignore-zeros"
2019-10-31 16:51:36 +00:00
ok=1
if [[ ! -d "tests-${version}" ]]; then
for flavour in "${FLAVOURS[@]}"; do
echo "Unpacking: ${version}/${flavour}.tar.gz"
mkdir -p "tests-${version}"
tar -C "tests-${version}" --strip-components 1 ${EXTRA_TAR_PARAMS} --exclude=phase1 -xzf \
"tarballs/${version}/${flavour}.tar.gz" \
|| {
rm -rf "tests-${version}" "tarballs/${version}/${flavour}.tar.gz"
ok=0
}
done
fi
done
if (( !ok )); then
echo "Unpacking failed too often. Aborting."
exit 1
2019-10-31 16:51:36 +00:00
fi
}
# download and unpack
for version in "${VERSIONS[@]}"; do
2019-10-31 16:51:36 +00:00
unpack_version "$version"
done
# delete tarballs and unpacked data from old versions
for tpath in tarballs/*; do
if [[ "$tpath" == "tarballs/slashing-"* ]]; then
continue # avoid interfering with slashing interchange tests
fi
tdir="$(basename "$tpath")"
if [[ ! " ${VERSIONS[@]} " =~ " $tdir " ]]; then
rm -rf "$tpath"
fi
done
for tpath in tests-*; do
if [[ "$tpath" == "tests-slashing-"* ]]; then
continue # avoid interfering with slashing interchange tests
fi
tver="$(echo "$tpath" | sed -e's/^tests-//')"
if [[ ! " ${VERSIONS[@]} " =~ " $tver " ]]; then
rm -rf "$tpath"
fi
done