Files
routewatch/script/asupdate
T
sneak db7a9494d9
check / check (push) Canceled after 0s
Keep the AS list when the asupdate generator fails (closes #173)
make asupdate piped the generator into gzip, so the target saw gzip's
exit status. A failed download replaced pkg/asinfo/asdata.json.gz with
an empty file and the target still exited 0.

The target now runs the new script/asupdate. It writes the generator's
output to a temporary file and checks that the generator succeeded and
wrote at least one AS. Only then does it compress the list and move it
into place. Otherwise it leaves the file alone and exits non-zero.

The generator reads as.csv from ipverse/as-metadata, the source's new
name. The list it builds there is unchanged, so no new list is
committed.

Model: opus-5-5
2026-10-27 01:19:34 +00:00

44 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# script/asupdate: rebuild the AS list built into RouteWatch from
# as.csv with cmd/asinfo-gen. The new list replaces the old one only
# when the generator succeeds and writes at least one AS. Otherwise
# the old list stays as it was and the script exits non-zero.
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
AS_DATA="pkg/asinfo/asdata.json.gz"
# Next to AS_DATA, so the final mv is a rename on one file system.
AS_DATA_TMP="$AS_DATA.tmp"
main() {
cd "$ROOT"
json="$(mktemp)"
trap 'rm -f "$json" "$AS_DATA_TMP"' EXIT
# A signal exits through the EXIT trap too.
trap 'exit 1' HUP INT TERM
echo "Updating AS info data..."
if ! go run ./cmd/asinfo-gen >"$json"; then
echo "asupdate: the generator failed; $AS_DATA is unchanged" >&2
exit 1
fi
# The generator writes a list of ASes with "[" alone on the first
# line. An empty list is "[]", and no list at all is "null".
first_line=""
read -r first_line <"$json" || true
if [ "$first_line" != "[" ]; then
echo "asupdate: the generator wrote no ASes; $AS_DATA is unchanged" >&2
exit 1
fi
# -n leaves the time out of the file, so an unchanged list gives the
# same bytes.
gzip -n -c <"$json" >"$AS_DATA_TMP"
mv "$AS_DATA_TMP" "$AS_DATA"
}
main "$@"