60 lines
2.8 KiB
Bash
Executable File
60 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
if [ "$#" -ne 4 ] || [ -z "$1" ]; then
|
|
echo "usage: update-zoneinfo.sh TZDATA_DIR VZIC IMPORTER OUTPUT_DIR" >&2
|
|
echo "CMake users: configure -DBONGO_TZDATA_DIR=/path/to/tzdata, then build update-zoneinfo" >&2
|
|
exit 2
|
|
fi
|
|
|
|
olson_dir=$1
|
|
vzic=$2
|
|
importer=$3
|
|
output_dir=$4
|
|
|
|
[ -d "$olson_dir" ] || { echo "tzdata directory not found: $olson_dir" >&2; exit 2; }
|
|
[ -r "$olson_dir/africa" ] || { echo "not an unpacked IANA tzdata tree: $olson_dir" >&2; exit 2; }
|
|
[ -r "$olson_dir/version" ] || { echo "IANA tzdata version file not found: $olson_dir/version" >&2; exit 2; }
|
|
[ -x "$vzic" ] || { echo "vzic executable not found: $vzic" >&2; exit 2; }
|
|
[ -x "$importer" ] || { echo "timezone importer not found: $importer" >&2; exit 2; }
|
|
[ -d "$output_dir" ] || { echo "output directory not found: $output_dir" >&2; exit 2; }
|
|
|
|
staging=$(mktemp -d "${TMPDIR:-/tmp}/bongo-zoneinfo.XXXXXX")
|
|
trap 'rm -rf "$staging"' EXIT HUP INT TERM
|
|
mkdir "$staging/ics" "$staging/zones"
|
|
|
|
iana_version=$(sed -n '1p' "$olson_dir/version")
|
|
case "$iana_version" in
|
|
[0-9][0-9][0-9][0-9][a-z]) ;;
|
|
*) echo "invalid IANA tzdata version: $iana_version" >&2; exit 2 ;;
|
|
esac
|
|
release_date=$(awk -v version="$iana_version" \
|
|
'$1 == "Release" && $2 == version && $3 == "-" { print $4; exit }' \
|
|
"$olson_dir/NEWS")
|
|
case "$release_date" in
|
|
[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]) ;;
|
|
*) echo "release date for IANA tzdata $iana_version not found in NEWS" >&2; exit 2 ;;
|
|
esac
|
|
release_stamp=$(printf '%s' "$release_date" | tr -d '-')T000000Z
|
|
|
|
"$vzic" --pure --output-dir "$staging/ics" --olson-dir "$olson_dir"
|
|
# vzic records the wall-clock conversion time in every VTIMEZONE. Normalize
|
|
# it to the IANA release date so that repeated snapshot updates are identical.
|
|
find "$staging/ics" -type f -name '*.ics' \
|
|
-exec sed -i "s/^LAST-MODIFIED:.*/LAST-MODIFIED:${release_stamp}\\r/" '{}' +
|
|
: > "$staging/zones/generated.tznames"
|
|
find "$staging/ics" -type f -name '*.ics' -exec "$importer" '{}' "$staging/zones" ';'
|
|
LC_ALL=C sort -u "$staging/zones/generated.tznames" > "$staging/generated.tznames"
|
|
mv "$staging/generated.tznames" "$staging/zones/generated.tznames"
|
|
printf '%s\n' "$iana_version" > "$staging/zones/IANA_VERSION"
|
|
|
|
count=$(find "$staging/zones" -type f -name '*.zone' | wc -l)
|
|
[ "$count" -gt 0 ] || { echo "timezone conversion produced no zone files" >&2; exit 1; }
|
|
|
|
# Replace the checked-in snapshot only after conversion completed successfully.
|
|
find "$output_dir" -maxdepth 1 -type f -name '*.zone' -delete
|
|
find "$staging/zones" -maxdepth 1 -type f -name '*.zone' -exec cp '{}' "$output_dir/" ';'
|
|
cp "$staging/zones/generated.tznames" "$output_dir/generated.tznames"
|
|
cp "$staging/zones/IANA_VERSION" "$output_dir/IANA_VERSION"
|
|
echo "Updated $count Bongo timezone files from IANA tzdata $iana_version in $output_dir"
|