-
Notifications
You must be signed in to change notification settings - Fork 0
/
revision-gen
executable file
·39 lines (32 loc) · 1.1 KB
/
revision-gen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
# Calculates the number of revisions since the tag of a given version. Useful as an incremention build sequence
# when git metadata is missing, for example in tarballs, this script uses a fixed file "./tarball-revision" to retrieve
# the revision. Source build therefore should save revision into the tarball
if [ "$#" == "0" ]; then
VERSION="15.06"
else
VERSION=$1
fi
if test -f ./tarball-revision; then
cat ./tarball-revision
exit
fi
# projects that are submodules should add to their parent's revision otherwise
# if there is a rebuild because a dependency triggered a reinstall then package
# wouldn't be a new revision number and not trigger reinstall on update
if test -d ../.git; then
abs_path=`readlink -f $0`
parent=`cd ..; $abs_path $@`
parent_rev=${parent%.*}
fi
VER_REV=`git describe --abbrev=5 --match="v${VERSION}" HEAD`
if [ "$?" != "0" ]; then
echo "Could not find tag v$VERSION" 1>&2
exit 1
fi
REV=`echo "${VER_REV}" | sed -e 's/^v[0-9.]\+-//g' -e 's/-g\?/./g'`
if [ -n "$parent_rev" ]; then
echo $[ ${parent_rev} + ${REV%.*} ].${REV#*.}
else
echo $REV
fi