#!/bin/sh

version=""
fallback="0.x-unknown"

SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
version_file="$SCRIPT_DIR/../.version.txt"

git_rootdir()
{
    printf "%s" "$(git rev-parse --show-toplevel 2>/dev/null)"
}


if [ -f "$version_file" ]; then
    version=$(cat "$version_file") || version=""
fi

if [ "$version" = "" ]; then
    if [ -d "$(git_rootdir)" ]; then
        version=$(git describe --abbrev=4 --dirty --always --tags)
    fi
fi

if [ "$version" = "" ]; then
    version=$fallback
fi

printf "%s" "$version"
