2026-10-19 11:00:10 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
# Fetches the DB-IP Lite City geolocation databases (CC BY 4.0, MaxMind DB format, via the
|
|
|
|
|
# ip-location-db package on unpkg) when they are missing or older than 35 days, then
|
2026-10-19 11:11:32 +03:00
|
|
|
# starts the server as the unprivileged user "site". Without them the site works and
|
|
|
|
|
# downloads are stored without a country.
|
2026-10-19 11:00:10 +03:00
|
|
|
set -u
|
2026-10-19 11:11:32 +03:00
|
|
|
# A bind-mounted ./data is created by Docker as root: hand it to "site".
|
|
|
|
|
if [ "$(id -u)" = 0 ]; then
|
|
|
|
|
chown -R site /app/data
|
|
|
|
|
exec setpriv --reuid=site --regid=site --init-groups "$0" "$@"
|
|
|
|
|
fi
|
2026-10-19 11:00:10 +03:00
|
|
|
base="${GEOIP_URL:-https://unpkg.com/@ip-location-db/dbip-city-mmdb}"
|
|
|
|
|
for v in ipv4 ipv6; do
|
|
|
|
|
f="/app/data/dbip-city-${v}.mmdb"
|
|
|
|
|
if [ ! -s "$f" ] || [ -n "$(find "$f" -mtime +35 2>/dev/null)" ]; then
|
|
|
|
|
echo "downloading ${f##*/}"
|
|
|
|
|
if curl -fsSL --retry 3 --max-time 600 -o "$f.part" "$base/dbip-city-${v}.mmdb"; then
|
|
|
|
|
mv "$f.part" "$f"
|
|
|
|
|
else
|
|
|
|
|
rm -f "$f.part"
|
|
|
|
|
echo "geolocation download failed; keeping what is there"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
exec chesspenguin-site
|