af4472869123f0c488ce48a9fde8a7506126ca30
[vpp.git] / build-root / scripts / version
1 #!/bin/bash
2
3 path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
4
5 cd "$path"
6
7 git rev-parse 2> /dev/null
8 if [ $? == 0 ]; then
9     vstring=$(git describe)
10 elif [ -f .version ]; then
11     vstring=$(cat .version)
12 else
13     if [ -f ../rpm/*.gz ]; then
14         vstring=$(ls ../rpm/*.gz)
15     else
16         exit 1
17     fi
18 fi
19
20 TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//')
21 ADD=$(echo ${vstring} | cut -s -d- -f2)
22
23 git rev-parse 2> /dev/null
24 if [ $? == 0 ]; then
25     CMT=$(git describe --dirty --match 'v*'| cut -s -d- -f3,4)
26 else
27     CMT=$(echo ${vstring} | cut -s -d- -f3,4)
28 fi
29 CMTR=$(echo $CMT | sed 's/-/_/')
30
31 if [ -n "${BUILD_NUMBER}" ]; then
32        BLD="~b${BUILD_NUMBER}"
33 fi
34
35 if [ "$1" = "rpm-version" ]; then
36   echo ${TAG}
37   exit
38 fi
39
40 if [ "$1" = "rpm-release" ]; then
41   [ -z "${ADD}" ] && echo release && exit
42   echo ${ADD}${CMTR:+~${CMTR}}${BLD}
43   exit
44 fi
45
46   if [ -n "${ADD}" ]; then
47     if [ "$1" = "rpm-string" ]; then
48       echo ${TAG}-${ADD}${CMTR:+~${CMTR}}${BLD}
49     else
50       echo ${TAG}-${ADD}${CMT:+~${CMT}}${BLD}
51     fi
52   else
53     echo ${TAG}
54 fi