#!/bin/sh
# Download free "IP to Country Lite Database" from db-ip.com, licensed under CC-BY-4.0

# try to download this month file
wget -O dbip-country-lite.csv.gz "https://download.db-ip.com/free/dbip-country-lite-$(date +'%Y-%m').csv.gz"

# in case of error try to download previous month file
if [ $? -ne 0 ]; then
  wget -O dbip-country-lite.csv.gz "https://download.db-ip.com/free/dbip-country-lite-$(date -d '-1 month' +'%Y-%m').csv.gz"
fi

# uncompress and exit
gunzip dbip-country-lite.csv.gz
exit $?
