#!/bin/sh
OLDDIR=$(pwd)
TMPDIR=$(mktemp -d)
YEARMONTH=$(date +'%Y-%m')
VERSION=$(date +'%Y%m')01
cd ${TMPDIR}
wget https://download.db-ip.com/free/dbip-country-lite-${YEARMONTH}.csv.gz
gunzip dbip-country-lite-${YEARMONTH}.csv.gz
mkdir ${TMPDIR}/geoip-database-${VERSION}
mv dbip-country-lite-${YEARMONTH}.csv ${TMPDIR}/geoip-database-${VERSION}/dbip-country-lite.csv
tar -cJf geoip-database_${VERSION}.orig.tar.xz geoip-database-${VERSION}
mv geoip-database_${VERSION}.orig.tar.xz ${OLDDIR}/../geoip-database_${VERSION}.orig.tar.xz
cd ${OLDDIR}
rm -rf ${TMPDIR}
echo "Saved tarball: ${OLDDIR}/../geoip-database_${VERSION}.orig.tar.xz"
exit 0
