altosdroid: match only the current version tag
[fw/altos] / altosdroid / buildinfo.sh
1 #!/bin/sh
2 #
3 # Author: Mike Beattie <mike@ethernal.org>
4 #
5 # Script to parse result from git describe, and push values into
6 # BuildInfo.java for use within altosdroid (to display the current
7 # version and build information, primarily).
8 #
9
10 infile=src/org/altusmetrum/AltosDroid/BuildInfo.java.in
11 outfile=src/org/altusmetrum/AltosDroid/BuildInfo.java
12
13 . ../src/Version
14 version=$VERSION
15 commitnum=''
16 commithash=''
17 builddate=$(date "+%Y-%m-%d")
18 buildtime=$(date "+%H:%M")
19
20
21 describe=$(git describe --match "$version" --long --always 2>/dev/null || echo '')
22 if [ -n "$describe" ]; then
23    commitdetails=$(echo $describe | sed -e "s/^$version-//")
24    commitnum=$(echo $commitdetails | cut -d- -f1)
25    commithash=$(echo $commitdetails | cut -d- -f2)
26 fi
27
28
29 echo "Version $describe, built on $builddate, $buildtime"
30
31 sed -e "s/@DESCRIBE@/$describe/" \
32     -e "s/@VERSION@/$version/" \
33     -e "s/@COMMITNUM@/$commitnum/" \
34     -e "s/@COMMITHASH@/$commithash/" \
35     -e "s/@BUILDDATE@/$builddate/" \
36     -e "s/@BUILDTIME@/$buildtime/" \
37  $infile > $outfile