# #
###############################################################################
-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
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
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..."
}
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 $?