diff options
Diffstat (limited to 'scripts/get_version.sh')
-rwxr-xr-x | scripts/get_version.sh | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/scripts/get_version.sh b/scripts/get_version.sh new file mode 100755 index 000000000..00f418f3c --- /dev/null +++ b/scripts/get_version.sh | |||
@@ -0,0 +1,33 @@ | |||
1 | #!/bin/sh | ||
2 | # Gets the version number from git, or from the contents of .version | ||
3 | VERSION= | ||
4 | if test -f ".version"; then | ||
5 | VERSION=$(cat .version) | ||
6 | fi | ||
7 | if [ -e ./.git ]; then | ||
8 | # With sparse checkouts, we have a .git dir but possibly no tags | ||
9 | gitver=$(git describe --tags 2>/dev/null || echo no-git-version) | ||
10 | if test "$gitver" != "no-git-version"; then | ||
11 | VERSION=${gitver#v} | ||
12 | echo "$VERSION" > .version | ||
13 | fi | ||
14 | fi | ||
15 | if test "x$VERSION" = "x"; then | ||
16 | VERSION="unknown" | ||
17 | fi | ||
18 | case $1 in | ||
19 | "--major") | ||
20 | echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/g' | ||
21 | ;; | ||
22 | "--minor") | ||
23 | echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/g' | ||
24 | ;; | ||
25 | "--micro") | ||
26 | echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/g' | ||
27 | ;; | ||
28 | "--git") | ||
29 | echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\(.*\)/\4/g' | ||
30 | ;; | ||
31 | *) | ||
32 | echo "$VERSION" | ||
33 | esac | ||