]> git.ipfire.org Git - people/ummeegge/ipfire-2.x.git/blame - config/pmacct/geoip-updater
Pmacctd: New addon
[people/ummeegge/ipfire-2.x.git] / config / pmacct / geoip-updater
CommitLineData
2efe7c9e
EK
1#!/bin/bash -
2
3#
4# Cronjob script to update GeoIP for pmacct daily
5#
6# $author: ummeegge ipfire org ; $date: 21.10.2019
7########################################################
8#
9
10# Locations
11WORKDIR="/tmp/geoip";
12GEOIPDIR="/usr/share/pmacct/geoip";
13URLS="
14http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz
15";
16
17# Check if Pmacct is running, else exit here
18if ! pgrep 'pmacct'; then
19 logger -t pmacct "Pmacct is nor running. GeoIP updater script in /etc/fcron.daily/ is useless."
20 exit 1
21fi
22# Create temporary work dir and switch to it
23/bin/mkdir -p ${WORKDIR} && cd ${WORKDIR};
24# Download GeoIP with download log. If download fails write it to messages
25if ! /usr/bin/wget --no-check-certificate ${URLS} -o /tmp/geoip_update_dwn.log; then
26 /usr/bin/logger -t pmacct "Error: Downloading GeoIP database has been failed";
27 exit 1;
28 /bin/rm -rfv ${WORKDIR};
29fi
30# CleanUP GeoIP dir
31/bin/rm -rf ${GEOIPDIR}/*.mmdb
32# Unpack GeoIP mmdb
33tar xfvz GeoLite2-City.tar.gz --strip 1 --wildcards "**/*.mmdb"
34# Move GeoIP dats to ntopng
35/bin/mv ./*.mmdb ${GEOIPDIR}/ 2>/dev/null;
36# Restart ntopng
37/etc/init.d/pmacct restart;
38# Write to messages
39/usr/bin/logger -t pmacct "GeoIP database has been updated";
40# CleanUP
41/bin/rm -rf ${WORKDIR} 2>/dev/null;
42
43# EOF
44