forked from beefproject/beef
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-geoipdb
executable file
·82 lines (64 loc) · 1.7 KB
/
update-geoipdb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
#
# Copyright (c) 2006-2019 Wade Alcorn - [email protected]
# Browser Exploitation Framework (BeEF) - http://beefproject.com
# See the file 'doc/COPYING' for copying permission
#
# Install the MaxMind GeoIP database
set -euo pipefail
IFS=$'\n\t'
GEOIP_PATH="/opt/GeoIP"
info() { echo -e "\\033[1;36m[INFO]\\033[0m $*"; }
warn() { echo -e "\\033[1;33m[WARNING]\\033[0m $*"; }
fatal() { echo -e "\\033[1;31m[FATAL]\\033[0m $*"; exit 1 ; }
command_exists () {
command -v "${1}" >/dev/null 2>&1
}
get_permission () {
warn "This script will install the MaxMind GeoLite database in ${GEOIP_PATH}"
read -rp "Are you sure you wish to continue (Y/n)? "
if [ "$(echo "${REPLY}" | tr "[:upper:]" "[:lower:]")" = "n" ] ; then
fatal 'Installation aborted'
fi
}
check_deps() {
if ! command_exists /usr/bin/curl
then
fatal "/usr/bin/curl is not installed"
fi
if ! command_exists /bin/gunzip
then
fatal "/bin/gunzip is not installed"
fi
if ! command_exists /bin/tar
then
fatal "/bin/tar is not installed"
fi
}
check_perms() {
/bin/mkdir -p "${GEOIP_PATH}"
if ! [ -w "${GEOIP_PATH}" ]
then
fatal "${GEOIP_PATH} is not writable"
fi
}
install() {
info 'Downloading MaxMind GeoLite2-City database ...'
/usr/bin/curl -O https://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
info 'Extracting GeoLite2-City.tar.gz ...'
/bin/gunzip GeoLite2-City.tar.gz
/bin/tar xvf GeoLite2-City.tar
info "Installing to ${GEOIP_PATH} ..."
/bin/mv GeoLite2-City_*/* "${GEOIP_PATH}"
info 'Cleaning up ...'
/bin/rm GeoLite2-City.tar
/bin/rmdir GeoLite2-City_*
info 'Done!'
}
main() {
get_permission
check_deps
check_perms
install
}
main "$@"