#!/usr/bin/env bash
# Based on git's GIT-VERSION-GEN.

VF=VERSION-FILE
DEF_VER=v0.0.0

if test -d .git -o -f .git &&
	VN=$(git describe --dirty --tags 2>/dev/null)
then
	VN=${VN//-/.}
else
	VN="$DEF_VER"
fi

VN=$(expr "$VN" : v*'\(.*\)')

if test -r "$VF"
then
	VC=$(sed -e 's/^VERSION=//' <"$VF")
else
	VC=unset
fi
test "$VN" = "$VC" || {
	echo >&2 "VERSION=$VN"
	echo "VERSION=$VN" >"$VF"
}
