]> git.ipfire.org Git - ipfire-2.x.git/blobdiff - src/scripts/xt_geoip_update
ovpn: Fix LZO checkbox restore
[ipfire-2.x.git] / src / scripts / xt_geoip_update
index 93884dcf5b67de12467c467b67a4af0f0cca32dd..ebd2665331c75ac5863e2d455e8cda6a5c37cb07 100644 (file)
 #                                                                             #
 ###############################################################################
 
-TMP_PATH=$(mktemp -d)
+TMP_PATH=$(mktemp -dp /var/tmp)
 TMP_FILE=$(mktemp -p $TMP_PATH)
 
 SCRIPT_PATH=/usr/local/bin
 DEST_PATH=/usr/share/xt_geoip
 DB_PATH=/var/lib/GeoIP
+DB1_PATH=/usr/share/GeoIP
 
 DL_URL=https://geolite.maxmind.com/download/geoip/database
 DL_FILE=GeoLite2-Country-CSV.zip
@@ -34,9 +35,6 @@ eval $(/usr/local/bin/readhash /var/ipfire/proxy/settings)
 function download() {
        echo "Downloading latest GeoIP ruleset..."
 
-       # Create temporary directory.
-       mkdir -pv $TMP_PATH
-
        # Proxy settings.
        # Check if a proxy should be used.
        if [[ $UPSTREAM_PROXY ]]; then
@@ -82,6 +80,19 @@ function install() {
        return 0
 }
 
+function build_legacy() {
+       echo "Convert database to legacy GeoIP.dat ..."
+       cat $DB_PATH/GeoLite2-Country-Blocks-IPv4.csv | \
+           $DB1_PATH/bin/geolite2-to-legacy-csv.sh $DB1_PATH/bin/countryInfo.txt > \
+           $TMP_FILE
+       $DB1_PATH/bin/geoip-generator -v -4 --info="$(date -u +'GEO-106FREE %Y%m%d Build -IPFire-' \
+           -r $DB_PATH/GeoLite2-Country-Blocks-IPv4.csv) $(<$DB_PATH/COPYRIGHT.txt)" -o \
+           $DB1_PATH/GeoIP.dat $TMP_FILE
+
+       return 0
+}
+
+
 function build() {
        echo "Convert database..."
 
@@ -106,23 +117,22 @@ function cleanup() {
 }
 
 function main() {
-       # Download ruleset.
-       download || exit $?
-
-       if ! install; then
-               # Do cleanup.
-               cleanup || exit $?
-               exit 1
-       fi
+       local func
+       for func in download install build build_legacy; do
+               if ! ${func}; then
+                       # Cleanup any temporary data
+                       cleanup
 
-       # Remove temporary files.
-       cleanup || exit $?
+                       return 1
+               fi
+       done
 
-       # Convert the ruleset.
-       build || exit $?
+       # Cleanup
+       cleanup || return $?
 
+       # All done
        return 0
 }
 
 # Run the main function.
-main
+main || exit $?