set -euo pipefail
case "$#.$1" in
1.[^-]*) ;;
*) echo >&2 'bad usage'; exit 8 ;;
esac
url="$1"; shift
out=crates/tor-netdoc/testdata2
rm -rf tmp
mkdir tmp
cd tmp
wget -O ci.zip "$url"
unzip -q ci.zip nodes.\*
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"
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
chmod -R a+r,u+w .
rm -rf ../../../"$out"
mkdir ../../../"$out"
mv -- * ../../../"$out"
cd ../../..
rm -rf tmp
echo "Updated $out. Don't forget to git add."