Debian Codegraph @

get-version

raw
1 #!/bin/sh
2
3 subst='$Format:%d$'
4
5 # Determine the version string to build into a binary.
6 # When building in the git repository, we can use the output
7 # of "git describe" which gives an unequivocal answer.
8 #
9 # Failing that, we use variable above
10 # which has a set of references substituted into it by git.
11 # If we can find one which matches $v[0-9].* then we assume it's
12 # a version-number tag, else we just use the whole string.
13 # If there is more than one v[0-9].* tag, sort them and use the
14 # first. This favours, eg v2.63 over 2.63rc6.
15
16 if which git >/dev/null 2>&1 && [ -d .git ]; then
17 git describe
18 elif echo $subst | grep '\$Format:%d\$' >/dev/null 2>&1; then
19 # unsubstituted file, but no git available.
20 echo UNKNOWN
21 else
22 vers=`echo $subst | sed 's/[(), ]/,/ g' | tr ',' '\n' | grep $v[0-9]`
23
24 if [ $? -eq 0 ]; then
25 echo "${vers}" | sort | head -n 1 | sed 's/^v//'
26 else
27 echo $subst
28 fi
29 fi
30
31 exit 0
32