update_geoip.sh 563 B

1234567891011121314151617181920212223242526
  1. #!/bin/sh
  2. set -e
  3. DIR=$(cd "$(dirname "$0")" && pwd)
  4. TMP=$(mktemp -d)
  5. DB_PATH="/var/lib/location/database.db"
  6. # In case it exists as a dead symlink.
  7. if [ -h "$DB_PATH" ]; then
  8. unlink "$DB_PATH"
  9. elif [ -e "$DB_PATH" ]; then
  10. rm -f "$DB_PATH"
  11. fi
  12. curl -o "$DB_PATH.xz" "https://location.ipfire.org/databases/1/location.db.xz"
  13. xz -d "$DB_PATH.xz"
  14. location dump "$TMP/geoip-dump.txt"
  15. OLDDIR=$(pwd)
  16. cd "$DIR/geoip-db-tool/"
  17. cargo build --release --target-dir "target"
  18. cd "$OLDDIR"
  19. "$DIR/geoip-db-tool/target/release/geoip-db-tool" -i "$TMP/geoip-dump.txt"