#!/bin/sh
DATE1="$(date +%y%m%d --date='-2 day')"
DATE2="$(date +%y%m%d --date='-1 day')"

for DATE in "${DATE1}" "${DATE2}"; do
	FILENAME="australia-${DATE}.osm.pbf"
	URL="http://download.geofabrik.de/australia-oceania/${FILENAME}"
	if [ ! -f "${FILENAME}" ]; then
		echo "${URL} --> ${FILENAME}"
		wget -c "${URL}" -O "${FILENAME}"
	fi
	if [ -f "${FILENAME}" ]; then
		find "${FILENAME}" -type f -empty -print -delete
	fi
	if [ -f "${FILENAME}" ]; then
		ln -fs "${FILENAME}" "australia-latest.osm.pbf"
	fi
done
