aboutsummaryrefslogtreecommitdiff
path: root/scripts/get_version.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/get_version.sh')
-rwxr-xr-xscripts/get_version.sh33
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
3VERSION=
4if test -f ".version"; then
5 VERSION=$(cat .version)
6fi
7if [ -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
14fi
15if test "x$VERSION" = "x"; then
16 VERSION="unknown"
17fi
18case $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"
33esac