anope- supernets anope source code & configuration |
git clone git://git.acid.vegas/anope.git |
Log | Files | Refs | Archive | README |
geoipupdate.sh (3128B)
1 #!/bin/bash 2 3 # This script is a helper script for the irc2sql module. 4 # It downloads the configured geoip databases and inserts 5 # them into existing mysql tables. The tables are created 6 # by the irc2sql module on the first load. 7 8 # Don't forget to rename this file or your changes 9 # will be overwritten on the next 'make install' 10 11 ############################ 12 # Config 13 ############################ 14 15 16 geoip_database="country" # available options: "country" and "city" 17 mysql_host="localhost" 18 mysql_user="anope" 19 mysql_password="anope" 20 mysql_database="anope" 21 prefix="anope_" 22 die="yes" 23 24 ########################### 25 26 # The GeoIP data is created by MaxMind, available from www.maxmind.com. 27 geoip_country_source="https://geolite.maxmind.com/download/geoip/database/GeoIPCountryCSV.zip" 28 geoip_city_source="https://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/GeoLiteCity-latest.zip" 29 geoip_region_source="https://www.maxmind.com/download/geoip/misc/region_codes.csv" 30 31 ########################### 32 LOGIN="--host=$mysql_host --user=$mysql_user --password=$mysql_password $mysql_database" 33 PARAMS="--delete --local --fields-terminated-by=, --fields-enclosed-by=\" --lines-terminated-by=\n $LOGIN" 34 35 download() { 36 local url=$1 37 local desc=$2 38 echo -n " $desc " 39 wget --progress=dot $url 2>&1 | grep --line-buffered "%" | sed -u -e "s,\.,,g" | awk '{printf("\b\b\b\b%4s", $2)}' 40 echo -ne " Done\n" 41 } 42 43 44 if test $die = "yes"; then 45 echo "You have to edit and configure this script first." 46 exit 47 fi 48 49 50 if test $geoip_database = "country"; then 51 echo "Downloading..." 52 download "$geoip_country_source" "Country Database:" 53 echo "Unpacking..." 54 unzip -jo GeoIPCountryCSV.zip 55 rm GeoIPCountryCSV.zip 56 echo "Converting to UTF-8..." 57 iconv -f ISO-8859-1 -t UTF-8 GeoIPCountryWhois.csv -o $prefix"geoip_country.csv" 58 rm GeoIPCountryWhois.csv 59 echo "Importing..." 60 mysqlimport --columns=@x,@x,start,end,countrycode,countryname $PARAMS $prefix"geoip_country.csv" 61 rm $prefix"geoip_country.csv" $prefix"geoip_country6.csv" 62 echo "Done..." 63 elif test $geoip_database = "city"; then 64 echo "Downloading..." 65 download "$geoip_city_source" "City Database:" 66 download "$geoip_region_source" "Region Database:" 67 echo "Unpacking..." 68 unzip -jo GeoLiteCity-latest.zip 69 rm GeoLiteCity-latest.zip 70 echo "Converting to utf-8..." 71 iconv -f ISO-8859-1 -t UTF-8 GeoLiteCity-Blocks.csv -o $prefix"geoip_city_blocks.csv" 72 iconv -f ISO-8859-1 -t UTF-8 GeoLiteCity-Location.csv -o $prefix"geoip_city_location.csv" 73 iconv -f ISO-8859-1 -t UTF-8 region.csv -o $prefix"geoip_city_region.csv" 74 rm GeoLiteCity-Blocks.csv GeoLiteCity-Location.csv region.csv 75 echo "Importing..." 76 mysqlimport --columns=start,end,locID --ignore-lines=2 $PARAMS $prefix"geoip_city_blocks.csv" 77 mysqlimport --columns=locID,country,region,city,@x,latitude,longitude,@x,areaCode --ignore-lines=2 $PARAMS $prefix"geoip_city_location.csv" 78 mysqlimport --columns=country,region,regionname $PARAMS $prefix"geoip_city_region.csv" 79 rm $prefix"geoip_city_blocks.csv" $prefix"geoip_city_location.csv" $prefix"geoip_city_region.csv" $prefix"geoip_country6.csv" 80 echo "Done..." 81 fi