#! /bin/bash # Copyright (C) 2008 Enrico Scholz # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . ### NOTE: this program is part of the Fedora 'tor' package. Hence, file ### bugreports at http://bugzilla.redhat.com, but *NOT* at upstream tor ### webpage/maillists. URL=http://ip-to-country.webhosting.info/downloads/ip-to-country.csv.zip : ${DESTDIR=/var/lib/tor-data} set -e d=$(mktemp -d -t tor-geoip.XXXXXX) trap "rm -rf $d" EXIT cd $d wget "$URL" unzip "$(basename "$URL")" date=$(stat -c '%Y' ip-to-country.csv) date=$(date +"%Y%m%dT%H%M%S" -d "1970-01-01 00:00:00 UTC $date seconds") fname=geoip-$date test ! -e "$DESTDIR/$fname" || exit 0 cut -d, -f1-3 < ip-to-country.csv | sed 's/"//g' > "$fname" rm -f "$DESTDIR/$fname" cp -p "$fname" "$DESTDIR/$fname" rm -f "$DESTDIR/geoip" ln -s "$fname" "$DESTDIR/geoip"