version/0.3
[cdimgtools.git] / version.sh
blobbba96d594e9bbf0f2d12a288b3bfe007c07bd64a
1 #!/bin/sh
2 # version.sh - execute in the root of the project to get the version
3 # Unlimited permission to copy, distribute and modify this file is granted.
4 # This file is offered as-is, without any warranty.
6 test $# -gt 0 && PACKAGE_NAME=$1
7 PACKAGE_NAME=${PACKAGE_NAME=cdimgtools}
8 DEF_VER="unknown_version"
10 NL='
13 # First try git-describe, then see if there is a VERSION file (included in
14 # release tarballs), then see if the project directory matches the project
15 # name, then use the default.
17 test -d .git || test -f .git &&
18 VN=$(git describe --abbrev=7 --match "version/*" --tags HEAD --always 2>/dev/null) &&
19 case $VN in
20 *$NL*)
21 false ;;
22 version/*)
23 git update-index -q --refresh
24 test -z "$(git diff-index --name-only HEAD --)" ||
25 VN="$VN.dirty" ;;
26 esac
27 then
28 VN=$(echo "$VN" | sed -e 's#^[vV][eE][rR][a-zA-Z]\{0,\}/##' -e 's/-/+/' -e 's/-/_/')
29 # <tag>+<num-of-commits>_g<hash>.dirty
30 elif
31 test -f VERSION && test -s VERSION
32 then
33 VN=$(cat VERSION) || VN=$DEF_VER
34 elif
35 VN=$(pwd | sed -e 's#^.\{0,\}/##') &&
36 test x"$VN" != x"${VN#"$PACKAGE_NAME-"}"
37 then
38 VN=${VN#"$PACKAGE_NAME-"}
39 else
40 VN=$DEF_VER
43 echo "$VN"