aboutsummaryrefslogtreecommitdiff
path: root/contrib/get_version.sh
blob: 6e3ab5141649ae5acdfc52cc23a530b3a164476c (plain) (blame)
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
#!/bin/sh
# Gets the version number from git, or from the contents of .version
VERSION=
if test -f ".version"
then
  VERSION=$(cat .version)
fi
if [ -e ./.git ]
then
  VERSION=$(git describe --tags)
  VERSION=${VERSION#v}
  echo $VERSION > .version
fi
if test "x$VERSION" = "x"
then
  VERSION="unknown"
fi
case $1 in
"--major")
  echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1/g'
  ;;
"--minor")
  echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\2/g'
  ;;
"--micro")
  echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\3/g'
  ;;
"--git")
  echo "$VERSION" | sed 's/\(^[0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\(.*\)/\4/g'
  ;;
*)
  echo "$VERSION"
esac