ctdbd: Add new runstate CTDB_RUNSTATE_FIRST_RECOVERY
[obnox/ctdb.git] / packaging / mkversion.sh
1 #!/bin/sh
2 #
3 # mkversion.sh - extract version string from git branch
4 #
5 # Copyright (C) Amitay Isaacs 2012
6 #
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by the Free
9 # Software Foundation; either version 3 of the License, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful, but WITHOUT
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15 # more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # this program; if not, see <http://www.gnu.org/licenses/>.
19 #
20
21 #
22 # Common code to generate CTDB version string
23 #
24
25 OUTPUT=$1
26
27 if [ -z "$OUTPUT" ]; then
28     OUTPUT="include/ctdb_version.h"
29 fi
30
31 # We use tags and determine the version, as follows:
32 # ctdb-0.9.1  (First release of 0.9).
33 # ctdb-0.9.23 (23rd minor release of the 112 version)
34 #
35 # If we're not directly on a tag, this is a devel release; we append
36 # .0.<patchnum>.<checksum>.devel to the release.
37 TAG=`git describe`
38 case "$TAG" in
39     ctdb-*)
40         TAG=${TAG##ctdb-}
41         case "$TAG" in
42             *-*-g*) # 0.9-168-ge6cf0e8
43                 # Not exactly on tag: devel version.
44                 VERSION=`echo "$TAG" | sed 's/\([^-]\+\)-\([0-9]\+\)-\(g[0-9a-f]\+\)/\1.0.\2.\3.devel/'`
45                 ;;
46             *)
47                 # An actual release version
48                 VERSION=$TAG
49                 ;;
50         esac
51         ;;
52     *)
53         echo Invalid tag "$TAG" >&2
54         ;;
55 esac
56
57 cat > "$OUTPUT" <<EOF
58 /* This file is auto-genrated by packaging/mkversion.sh */
59
60 #define CTDB_VERSION_STRING "$VERSION"
61
62 EOF
63
64 echo $VERSION