37 lines
1.1 KiB
Bash
Executable file
37 lines
1.1 KiB
Bash
Executable file
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
# GeoIP Database Updater
|
|
# Downloads DB-IP City Lite database (free, no license key required)
|
|
# More info: https://db-ip.com/db/lite.php
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
CODEBASE_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
|
|
|
|
# Get current year and month for the URL
|
|
YEAR=$(date +%Y)
|
|
MONTH=$(date +%m)
|
|
|
|
DB_URL="https://download.db-ip.com/free/dbip-city-lite-${YEAR}-${MONTH}.mmdb.gz"
|
|
DB_DIR="$CODEBASE_ROOT/features/platform-analytics/backend-api/data"
|
|
DB_FILE="$DB_DIR/dbip-city-lite.mmdb"
|
|
|
|
# Ensure data directory exists
|
|
mkdir -p "$DB_DIR"
|
|
|
|
echo "Downloading DB-IP City Lite database..."
|
|
echo "URL: $DB_URL"
|
|
|
|
# Download and decompress
|
|
if curl -fsSL "$DB_URL" | gunzip > "$DB_FILE.tmp"; then
|
|
mv "$DB_FILE.tmp" "$DB_FILE"
|
|
echo "Downloaded: $(ls -lh "$DB_FILE" | awk '{print $5}')"
|
|
echo "Location: $DB_FILE"
|
|
echo "Done."
|
|
else
|
|
rm -f "$DB_FILE.tmp"
|
|
echo "ERROR: Failed to download database"
|
|
echo "The current month's database may not be available yet."
|
|
echo "Try using last month's URL manually."
|
|
exit 1
|
|
fi
|