~chasedouglas/geis/fix-deltas

143 by Stephen M. Webb
Automatically determined the package version string from bzr.
1
#!/bin/sh
2
#
3
# Tool to automatically generate the package version from the bzr tags.
4
#
5
# This tool generates a package version string based on the tags in the bzr
6
# branch.  When an official release is made, the branch should be tagged with a
7
# tag of the form 'vN.N.N'.  This script will then give a version string of
8
# 'N.N.N'.  If any changes are made to the barcnh after tagging, the version
9
# string will be of the form 'N.N.N+rRRR' where RRR is the bzr revno of the
10
# latest commit.
11
#
12
# This scheme allows snapshot releases to be packaged.
13
#
14
15
# Copyright 2011 Canonical Ltd.
16
#
17
# This program is free software: you can redistribute it and/or modify
18
# it under the terms of the GNU General Public License as published by
19
# the Free Software Foundation; either version 3 of the License, or
20
# (at your option) any later version.
21
#
22
# This program is distributed in the hope that it will be useful,
23
# but WITHOUT ANY WARRANTY; without even the implied warranty of
24
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
# GNU General Public License for more details.
26
#
27
# You should have received a copy of the GNU General Public License
28
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
29
30
# Default to some unknown version string.
31
version_string="unknown"
32
33
# Get the cirrent BZR revision number.
34
cur_bzr_rev=$(bzr version-info --custom --template="{revno}")
35
36
# Extract the release version string and BZR revision number.
37
tag_line=$(bzr tags --sort=time \
38
         | grep -E 'v[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' \
39
         | tail -1)
40
tag_version=$(echo $tag_line | sed -n -e 's/v\([^[:space:]]*\).*/\1/p')
41
tag_rev=$(echo $tag_line | cut -d' ' -f2-)
42
43
if [ -n "$tag_version" ]; then
44
  version_string=$tag_version
45
fi
46
47
if [ $cur_bzr_rev -gt $tag_rev ]; then
48
  version_string="${version_string}+r${cur_bzr_rev}"
49
fi
50
51
echo $version_string