-
Notifications
You must be signed in to change notification settings - Fork 2
/
ipinfo.sh
31 lines (28 loc) · 1.09 KB
/
ipinfo.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
#!/bin/sh
while true; do
for DATABASE in ${IPINFO_DATABASES}; do
if [ -f ${DATABASE}.mmdb ]; then
LOCAL=$(sha256sum ${DATABASE}.mmdb | awk '{print $1}')
REMOTE=$(curl --silent https://ipinfo.io/data/free/${DATABASE}.mmdb/checksums?token=${IPINFO_TOKEN} \
| sed -n 's/.*"sha256": *"\([a-f0-9]*\)".*/\1/p')
if [ "$LOCAL" = "$REMOTE" ]; then
echo "${DATABASE}.mmdb is up-to-date."
continue
fi
fi
RESPONSE=$(curl \
-s -w '%{http_code}' -L -o "${DATABASE}.mmdb.new" \
"https://ipinfo.io/data/free/${DATABASE}.mmdb?token=${IPINFO_TOKEN}")
if [ "$RESPONSE" != "200" ]; then
echo "$RESPONSE Failed to download ${DATABASE}.mmdb database."
rm "${DATABASE}.mmdb.new" 2> /dev/null
else
echo "${DATABASE}.mmdb database downloaded in /data volume."
mv "${DATABASE}.mmdb.new" "${DATABASE}.mmdb"
fi
done
if [ $UPDATE_FREQUENCY == 0 ]; then
break
fi
sleep "$UPDATE_FREQUENCY"
done