Print a warning if an illegal value is used for the spi but continue
[vpnc.git] / mk-version
bloba8ffb746b976243548af353d0acabd7c596434df
1 #!/bin/sh
3 # print vpnc version from file VERSION, appending the string printed
4 # by svnversion(1) if appropriate
6 in_git_repository ()
8 git rev-parse --is-inside-work-tree > /dev/null 2>&1
9 return $?
12 git_svn_version ()
14 # search for svn-remote defined in git configuration
15 svn_url_pattern=""
16 while read key value; do
17 svn_url_pattern="${svn_url_pattern}\\|${value}"
18 done << EOF
19 $(git config --get-regexp '^svn-remote\..*\.url$' 2>/dev/null)
20 EOF
22 # exit if no svn-remote defined
23 if [ -z "${svn_url_pattern}" ]; then
24 return
27 # scan git-log for latest commit from any svn-remote above
28 set -- $(git log --first-parent -1 \
29 --grep="^git-svn-id: \(${svn_url_pattern#??}\)@" 2>/dev/null)
31 # check commit hash is 40 hex digits
32 svn_commit=$2
33 if [ ${#svn_commit} -ne 40 -o -z "${svn_commit##*[!0-9a-f]*}" ]; then
34 return
37 # check svn version is numeric
38 shift $(($# - 2))
39 svn_ver=${1#*@}
40 if [ -z "${svn_ver}" -o -z "${svn_ver##*[!0-9]*}" ]; then
41 return
44 if [ $(git rev-list HEAD...${svn_commit} | wc -l) -eq 0 ]; then
45 if [ `git status -s | grep -vc '^??'` -eq 0 ]; then
46 # no git commits and tree clean
47 echo "${svn_ver}"
48 return
51 # there are local git commits after latest svn commit or tree is dirty
52 echo "${svn_ver}M"
56 _version="`cat VERSION`"
58 if [ -d .svn ]; then
59 if which svnversion > /dev/null; then
60 _version="$_version-`svnversion`"
61 else
62 _version="$_version-`sed -n '/^dir$/{n;p;q;}' .svn/entries`"
64 elif which git > /dev/null && in_git_repository; then
65 git_ext=$(git_svn_version)
66 if [ -n "${git_ext}" ]; then
67 _version="$_version-${git_ext}"
71 echo "$_version"
73 exit 0