#! /bin/sh

: ${YEAR_FILE:=$1}
: ${DEFAULT_YEAR:=$2}

year=

[ -n "${YEAR_FILE}" ] || {
	echo >&2 "$0 $(dirname "$0")/.year [DEFAULT_YEAR]"
	exit 1
}

[ -f "${YEAR_FILE}" ] && year="$(cat "${YEAR_FILE}")"

[ -n "${year}" ] ||
	year="$(date +%Y -d "$(git show --format=format:%cD --no-patch)")"

[ -n "${year}" ] || year="${DEFAULT_YEAR}"

[ -n "${year}" ] || year="$(date "+%Y")"

[ -n "${year}" ] || {
	echo >&2 'Undefined year.'
	exit 1
}

printf "%s" "${year}"
