Skip to content

Instantly share code, notes, and snippets.

@ItsMeooooooo
Last active December 21, 2015 19:29
Show Gist options
  • Select an option

  • Save ItsMeooooooo/6354382 to your computer and use it in GitHub Desktop.

Select an option

Save ItsMeooooooo/6354382 to your computer and use it in GitHub Desktop.
get the GeoIP.dat and decompress it into a given folder
#!/usr/bin/env bash
#
# OK lets work
geoIPPath='/home/urbanterror/geoip/'
IPAddress='http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz'
zcat=/bin/zcat
wget=/usr/bin/wget
echo 'Checking if the remote File is available...'
httpResponse=$(curl --write-out %{http_code} --silent --output /dev/null $IPAddress)
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
if [ $httpResponse -eq 200 ]
then
echo "We're in luck they still provide the file"
sleep 1
echo 'Let me take a look if we have an existing GeoIP.dat'
if [ -e $geoIPPath/GeoIP.dat ]
then
echo "Got one - I'll do a backup of it"
mv $geoIPPath/GeoIP.dat $geoIPPath/GeoIP.dat_backup
sleep 1
echo 'Done!'
else
echo "No file found - I'll proceed further"
fi
echo 'receiving and extract the new file'
$zcat < <($wget -q -O - $IPAddress) > $geoIPPath/GeoIP.dat
echo -ne '##### (33%)\r'
sleep 1
echo -ne '############# (66%)\r'
sleep 1
echo -ne '####################### (100%)\r'
echo -ne '\n'
echo 'Got it!'
sleep 1
echo 'Cleaning up'
rm -rf $geoIPPath/GeoIP.dat_backup
else
echo "I'm sorry to inform you that the file isn't on that address anymore"
echo "The HTTP error was: $httpResponse"
fi
# EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment