#! /bin/sh # Update the MaxMind free GeoLite databases # by: Gianluca Toso # # Special version for my Mac OS X aMule GEODBDIR="/opt/local/share/GeoIP"; GEOCOUNTRYURL="http://www.maxmind.com/download/geoip/database/GeoIP.dat.gz"; GEOCITYURL="http://www.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"; # Exit the script on errors: set -e trap 'echo "$0 FAILED at line ${LINENO}"' ERR # Catch unitialized variables: set -u P1=${1:-1} if ! id -Gn | grep -E "(^| )admin( |$)" >/dev/null; then echo -n "Enter an Administrator Login: "; read USER; [ "$USER" ] && id $USER >/dev/null 2>/dev/null || exit 1; SRCDIR="$(cd "$(dirname $0)"; pwd)" exec su - $USER "$SRCDIR/$(basename $0)" $*; fi; if [ ! -d "$GEODBDIR" ]; then echo "Creating $GEODBDIR"; sudo mkdir -p "$GEODBDIR"; #sudo chgrp admin "$GEODBDIR"; sudo chmod g+w "$GEODBDIR"; fi; if $(type wget > /dev/null 2>&1); then DOWN="wget -q -O" else DOWN="/usr/bin/curl -RsS -o" fi; update_country() { cd "$GEODBDIR" echo -n "Downloading GeoIP Country DB... " $DOWN GeoIP.dat.gz $GEOCOUNTRYURL gzip -fd GeoIP.dat.gz echo "OK" } update_city() { cd "$GEODBDIR" echo -n "Downloading GeoIP City DB... " $DOWN GeoIPCity.dat.gz $GEOCITYURL gzip -fd GeoIPCity.dat.gz echo "OK" } case "$P1" in -h|--help) cat << EOF; GeoIPUpdate.sh 0.0.2a for Mac OSX - Copyright 2008 Gianluca Toso A script to updating the MaxMind free GeoLite databases. Special version for my Mac OS X aMule. Usage: $0 [-C | -c | -a] $0 -h|--help Options: -C update Country DB (default). -c update City DB. -a update all DB. -h prints help (this message). Notes: Any incorrect or unknown parameter will be silently ignored. EOF ;; -C) update_country; ;; -c) update_city; ;; -a) update_country; update_city; ;; *) update_country; ;; esac;