65 lines
2.3 KiB
Bash
Executable File
65 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
SOURCE_DIR=${BONGO_TEST_SOURCE_ZONEINFO:-}
|
|
ZONEINFO_DIR=${BONGO_TEST_INSTALLED_ZONEINFO:-/usr/share/bongo/zoneinfo}
|
|
CACHE_FILE=${BONGO_TEST_TIMEZONE_CACHE:-/var/lib/bongo/dbf/bongo-tz.cache}
|
|
CONFIG_TOOL=${BONGO_TEST_CONFIG_TOOL:-/usr/bin/bongo-config}
|
|
MINIMUM_ZONES=${BONGO_TEST_MINIMUM_ZONES:-500}
|
|
|
|
version=$(sed -n '1p' "$ZONEINFO_DIR/IANA_VERSION")
|
|
case "$version" in
|
|
[0-9][0-9][0-9][0-9][a-z]) ;;
|
|
*)
|
|
echo "invalid installed IANA version: $version" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
zone_count=$(find "$ZONEINFO_DIR" -maxdepth 1 -type f -name '*.zone' |
|
|
wc -l)
|
|
if [ "$zone_count" -lt "$MINIMUM_ZONES" ]; then
|
|
echo "installed snapshot has only $zone_count zones" >&2
|
|
exit 1
|
|
fi
|
|
if find "$ZONEINFO_DIR" -maxdepth 1 -type f -name '*.zone' -size 0 |
|
|
grep -q .; then
|
|
echo "installed snapshot contains an empty zone file" >&2
|
|
exit 1
|
|
fi
|
|
echo "PASS installed IANA $version snapshot contains $zone_count non-empty zones"
|
|
|
|
if [ -n "$SOURCE_DIR" ]; then
|
|
source_version=$(sed -n '1p' "$SOURCE_DIR/IANA_VERSION")
|
|
source_count=$(find "$SOURCE_DIR" -maxdepth 1 -type f -name '*.zone' |
|
|
wc -l)
|
|
if [ "$source_version" != "$version" ] ||
|
|
[ "$source_count" -ne "$zone_count" ]; then
|
|
echo "source and installed timezone snapshots differ in version or count" >&2
|
|
exit 1
|
|
fi
|
|
for source_file in "$SOURCE_DIR"/*.zone; do
|
|
installed_file=$ZONEINFO_DIR/${source_file##*/}
|
|
if ! cmp -s "$source_file" "$installed_file"; then
|
|
echo "installed timezone differs from source: ${source_file##*/}" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
echo "PASS installed zone files are byte-identical to the checked-in snapshot"
|
|
fi
|
|
|
|
before_inode=$(sudo -n /usr/bin/stat -c '%i' "$CACHE_FILE" 2>/dev/null || true)
|
|
sudo -n "$CONFIG_TOOL" tzcache
|
|
cache_state=$(sudo -n /usr/bin/stat -c '%a %U:%G %s %i' "$CACHE_FILE")
|
|
set -- $cache_state
|
|
if [ "$1" != 644 ] || [ "$2" != bongo:bongo ] || [ "$3" -le 0 ]; then
|
|
echo "unsafe or empty rebuilt timezone cache: $cache_state" >&2
|
|
exit 1
|
|
fi
|
|
if [ -n "$before_inode" ] && [ "$before_inode" = "$4" ]; then
|
|
echo "timezone cache inode did not change during atomic rebuild" >&2
|
|
exit 1
|
|
fi
|
|
echo "PASS atomic cache rebuild produced $3 bytes as $1 $2 (inode $4)"
|
|
echo "PASS timezone cache uses installed checked-in snapshot"
|