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.
This commit is contained in:
User Ggo 2015-07-07 11:48:11 +00:00
parent 1c6d91b818
commit 7229f4292f
1 changed files with 15 additions and 31 deletions

View File

@ -41,46 +41,30 @@ LINUX_OTHER="0"
# Login information for your MySQL server # Login information for your MySQL server
DBHOST="localhost" DBHOST="localhost"
DBNAME="" DBNAME="hlstatsx"
DBUSER="" DBUSER="hlxuser"
DBPASS="" DBPASS="SQL_PASSWORD_HERE"
# #
# Nothing to change below 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 FILE="GeoLiteCity-latest.zip"
TODAY_MONTH=$( date +%m ) rm -f geoLiteCity_Blocks.csv
TODAY_YEAR=$( date +%Y ) rm -f geoLiteCity_Location.csv
if [ $LINUX_OTHER == "1" ] rm -f geoLiteCity_Location.csv.temp
then CAL_COMMAND="cal -s" rm -f $FILE
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
[ -f $FILE ] || wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/$FILE || exit 1 [ -f $FILE ] || wget http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/$FILE || exit 1
unzip -o $FILE || exit 1 unzip -jo $FILE || exit 1
mv $DIR/GeoLiteCity-Blocks.csv geoLiteCity_Blocks.csv mv GeoLiteCity-Blocks.csv geoLiteCity_Blocks.csv
mv $DIR/GeoLiteCity-Location.csv geoLiteCity_Location.csv.temp mv GeoLiteCity-Location.csv geoLiteCity_Location.csv.temp
iconv -f ISO-8859-1 -t UTF-8 geoLiteCity_Location.csv.temp > geoLiteCity_Location.csv 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_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 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 # Cleanup
ls *.csv &>/dev/null && rm *.csv rm -f geoLiteCity_Blocks.csv
ls *.csv.temp &>/dev/null && rm *.csv.temp rm -f geoLiteCity_Location.csv
rm $FILE rm -f geoLiteCity_Location.csv.temp
rmdir $DIR rm -f $FILE