-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathupdate_geoip.sh
executable file
·85 lines (74 loc) · 2.99 KB
/
update_geoip.sh
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
82
83
84
#!/usr/bin/env bash
################################################################
# #
# Geolite2 database update script for: #
# #
# Privex IP Information Tool #
# (C) 2021 Privex Inc. GNU AGPL v3 #
# #
# Privex Site: https://www.privex.io/ #
# #
# Github Repo: https://github.com/Privex/whats-my-ip #
# #
################################################################
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:${PATH}"
export PATH="${HOME}/.local/bin:/snap/bin:${PATH}"
# Types of GeoLite2 databases to download
k=(ASN Country City)
################
# Override the installation directory by specifying on the CLI.
# Make sure the current user actually has permission to place files in that folder.
#
# Example:
#
# user@host ~ $ GEOLITE_DIR='/usr/share/GeoIP' ./update_geoip.sh
#
: ${GEOLITE_DIR='/usr/share/GeoIP'}
: ${REMOTE_SRV='files.privex.io'}
: ${REMOTE_DIR='/cdn/extras/GeoIP'}
find-cmd() {
[[ -f "/usr/bin/$1" || -f "/bin/$1" || -f "/usr/sbin/$1" || -f "/sbin/$1" || -f "/usr/local/bin/$1" ]]
}
xsudo() {
if (( EUID == 0 )); then
while (( $# > 0 )); do
if [[ "$1" == "sudo" || "$1" == "sg-sudo" ]]; then
>&2 echo -e "Attempted to run sudo with sudo!!!!"
return 2
fi
[[ "$1" == "--" ]] && break
if grep -Eq '^\-' <<< "$1"; then
shift
else
break
fi
done
env -- "$@"
return $?
else
if find-cmd sudo; then
sudo "$@"
return $?
elif find-cmd su; then
su -c "$(printf '%q ' "$@")"
return $?
fi
fi
}
#cd /tmp
echo -e "\n >>> Creating GeoIP folder if it doesn't already exist: $GEOLITE_DIR \n\n"
[[ -d "$GEOLITE_DIR" ]] || sudo mkdir -vp "$GEOLITE_DIR"
#echo "Removing any old Geolites from temp folder ..."
#rm -rv GeoLite2-*
echo -e "\n >>>> Downloading new Geolite databases into ${GEOLITE_DIR} \n"
for i in ${k[@]}; do
echo -e "\n\n > Downloading Geolite $i into ${GEOLITE_DIR} ... \n"
#wget -q http://geolite.maxmind.com/download/geoip/database/GeoLite2-${i}.tar.gz
sudo rsync -avch --progress "rsync://${REMOTE_SRV}${REMOTE_DIR}/GeoLite2-${i}.mmdb" "${GEOLITE_DIR}/"
#echo "Extracting Geolite $i ..."
#tar xf GeoLite2-${i}.tar.gz
#echo "Installing Geolite $i into ${GEOLITE_DIR}/GeoLite2-${i}.mmdb ..."
#cp -v GeoLite2-${i}_*/GeoLite2-${i}.mmdb "${GEOLITE_DIR}/"
#cp -v GeoLite2-${i}.mmdb "${GEOLITE_DIR}/"
done
echo -e "\n\n +++++++++ FINISHED +++++++++ \n\n"