From 7229f4292fb98d9f831f57c4ceb30c3716b687f7 Mon Sep 17 00:00:00 2001 From: User Ggo Date: Tue, 7 Jul 2015 11:48:11 +0000 Subject: [PATCH] GeoLiteCity has a new URL. Updated the script to reflect this change As the new URL no longer contains the date of release, I have been able to remove much of the date calculation code. --- scripts/GeoLiteCity/GeoLite_Import.sh | 46 +++++++++------------------ 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/scripts/GeoLiteCity/GeoLite_Import.sh b/scripts/GeoLiteCity/GeoLite_Import.sh index 2ce1f2e..ce4ad53 100644 --- a/scripts/GeoLiteCity/GeoLite_Import.sh +++ b/scripts/GeoLiteCity/GeoLite_Import.sh @@ -41,46 +41,30 @@ LINUX_OTHER="0" # Login information for your MySQL server DBHOST="localhost" -DBNAME="" -DBUSER="" -DBPASS="" +DBNAME="hlstatsx" +DBUSER="hlxuser" +DBPASS="SQL_PASSWORD_HERE" # # Nothing to change below here. # -# database is updated every first tuesday of any month, so download it with that specific date and import it -TODAY_MONTH=$( date +%m ) -TODAY_YEAR=$( date +%Y ) -if [ $LINUX_OTHER == "1" ] - then CAL_COMMAND="cal -s" - else CAL_COMMAND="cal" -fi -FIRST_TUESDAY_MONTH=$( $CAL_COMMAND $TODAY_MONTH $TODAY_YEAR | - awk ' - NR == 1 { next } - NR == 2 { next } - NF <= 4 { next } - NF == 5 { print $1 ; exit } - NF == 6 { print $2 ; exit } - NF == 7 { print $3 ; exit } - ' ) - -DATE=""$TODAY_YEAR""$TODAY_MONTH"0"$FIRST_TUESDAY_MONTH"" -DIR="GeoLiteCity_$DATE" -FILE="GeoLiteCity_$DATE.zip" -ls *.csv &>/dev/null && rm *.csv +FILE="GeoLiteCity-latest.zip" +rm -f geoLiteCity_Blocks.csv +rm -f geoLiteCity_Location.csv +rm -f geoLiteCity_Location.csv.temp +rm -f $FILE [ -f $FILE ] || wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/$FILE || exit 1 -unzip -o $FILE || exit 1 -mv $DIR/GeoLiteCity-Blocks.csv geoLiteCity_Blocks.csv -mv $DIR/GeoLiteCity-Location.csv geoLiteCity_Location.csv.temp +unzip -jo $FILE || exit 1 +mv GeoLiteCity-Blocks.csv geoLiteCity_Blocks.csv +mv GeoLiteCity-Location.csv geoLiteCity_Location.csv.temp iconv -f ISO-8859-1 -t UTF-8 geoLiteCity_Location.csv.temp > geoLiteCity_Location.csv mysqlimport -C -d --fields-terminated-by=, --fields-enclosed-by=\" --ignore-lines=2 --default-character-set=utf8 -L -i -h $DBHOST -u $DBUSER --password=$DBPASS $DBNAME geoLiteCity_Blocks.csv mysqlimport -C -d --fields-terminated-by=, --fields-enclosed-by=\" --ignore-lines=2 --default-character-set=utf8 -L -i -h $DBHOST -u $DBUSER --password=$DBPASS $DBNAME geoLiteCity_Location.csv # Cleanup -ls *.csv &>/dev/null && rm *.csv -ls *.csv.temp &>/dev/null && rm *.csv.temp -rm $FILE -rmdir $DIR +rm -f geoLiteCity_Blocks.csv +rm -f geoLiteCity_Location.csv +rm -f geoLiteCity_Location.csv.temp +rm -f $FILE