1#!/bin/sh
2# set -xe
3
4# geolite-update.sh -- update GeoIP lite databases.
5# (C) 2017-2019 Ettercap Development Team.
6
7# Ettercap can use MaxMind's GeoIP databases to look up the country for an IP address.
8# This simple shell script helps in downloading and installing the *free* GeoLite
9# country databases, which are needed for this feature to actually work.
10# You can optionally pass an alternative install path to this script.
11# If you rather not, it will install all files to /usr/local/share/GeoIP/.
12# Note: In some distributions/operating systems these databases are available
13# through their package manager.
14# You most likely don't need to use this script if this is the case.
15
16USAGE="USAGE: $(basename $0) [geolite install path]"
17
18# check argument count
19if [ $# -gt 1 ]
20then
21  echo $USAGE
22  exit
23fi
24
25if [ -z $1 ]
26then
27    geolite_path="/usr/share/GeoIP"
28    download_path="/usr/share/GeoIP/download"
29else
30    geolite_path=$1
31    download_path="$1/download"
32
33fi
34
35# prg="curl --remote-name"
36prg="wget --continue --directory-prefix=$download_path"
37
38if [ ! -e $geolite_path ]; then
39        echo "Unable to find GeoIP directory: $geolite_path"
40        exit 1
41fi
42
43echo "Updating/Installing GeoLite databases..."
44echo "Note: Not installing GeoLiteCity database (not used by Ettercap)"
45
46[ -d $download_path ] || mkdir $download_path
47
48$prg http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
49if [ ! -e $download_path/GeoIP.dat.gz ]; then
50        echo "Unable to find GeoIP.dat.gz!"
51        exit 1
52fi
53gunzip -c $download_path/GeoIP.dat.gz > $geolite_path/GeoIP.dat
54rm -f $download_path/GeoIP.dat.gz
55
56# Ettercap doesn't use the GeoLiteCity database... yet.
57# Uncomment the following lines if you want to download and install it anyways.
58# $prg http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz
59# if [ ! -e $download_path/GeoLiteCity.dat.gz ]; then
60#        echo "Unable to find GeoLiteCity.dat.gz!"
61#        exit 1
62# fi
63# gunzip -c $download_path/GeoLiteCity.dat.gz > $geolite_path/GeoLiteCity.dat
64# rm -f $download_path/GeoLiteCity.dat.gz
65
66$prg http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz
67if [ ! -e $download_path/GeoIPv6.dat.gz ]; then
68        echo "Unable to find GeoIPv6.dat.gz!"
69        exit 1
70fi
71gunzip -c $download_path/GeoIPv6.dat.gz > $geolite_path/GeoIPv6.dat
72rm -f $download_path/GeoIPv6.dat.gz
73
74echo "Done."
75