set -euo pipefail
case "$#.$1" in
1.[^-]*) ;;
*) echo >&2 'bad usage'; exit 8 ;;
esac
url="$1"; shift
root="$(git rev-parse --show-toplevel)"
out="$root/crates/tor-netdoc/testdata2"
cd "$root"
rm -rf tmp
mkdir tmp
cd tmp
wget -O ci.zip "$url"
unzip -q ci.zip shadow.chutney.data/hosts/host/nodes.\*
cd shadow.chutney.data/hosts/host
cd nodes.* cd 000a
rm -rf -- *.log diff-cache
cat >README <<END
All files in this directory are automatically maintained.
Downloaded and massaged by $0
From CI data at "$url"
Changing the files in this directory may lead tests to fail.
This is because they hardcode certain values expected to appear in certain
netdocs. The way to solve this should be a simple copy-and-paste of the
relevant data into the failing tests.
END
split-file () {
local f=$1
local headline=$2
perl -wpe '
BEGIN { $seq = 0; }
if (m{^'"$headline"' }) {
open STDOUT, ">", "$ARGV--".(++$seq) or die $!;
}
' "$f"
}
split-file v3-status-votes network-status-version
split-file cached-certs dir-key-certificate-version
patch_atline () {
local f=$1
sed -i '' '/^@/d' "$f"
}
patch_atline cached-descriptors.new
patch_atline cached-microdescs.new
chmod -R a+r,u+w .
rm -rf "$out"
mkdir "$out"
mv -- * "$out"
cd "$root"
rm -rf tmp
echo "Updated $out. Don't forget to git add."