vxlan: vxlan/vxlan.api API cleanup
[vpp.git] / src / scripts / version
1 #!/bin/bash
2
3 # Copyright (c) 2015 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
17
18 cd "$path"
19
20 if [ -f .version ]; then
21     vstring=$(cat .version)
22 else
23     vstring=$(git describe)
24     if [ $? != 0 ]; then
25       exit 1
26     fi
27 fi
28
29 TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//')
30 ADD=$(echo ${vstring} | cut -s -d- -f2)
31
32 git rev-parse 2> /dev/null
33 if [ $? == 0 ]; then
34     CMT=$(git describe --dirty --match 'v*'| cut -s -d- -f3,4)
35 else
36     CMT=$(echo ${vstring} | cut -s -d- -f3,4)
37 fi
38 CMTR=$(echo $CMT | sed 's/-/_/')
39
40 if [ -n "${BUILD_NUMBER}" ]; then
41        BLD="~b${BUILD_NUMBER}"
42 fi
43
44 if [ "$1" = "rpm-version" ]; then
45   echo ${TAG}
46   exit
47 fi
48
49 if [ "$1" = "rpm-release" ]; then
50   [ -z "${ADD}" ] && echo release && exit
51   echo ${ADD}${CMTR:+~${CMTR}}${BLD}
52   exit
53 fi
54
55   if [ -n "${ADD}" ]; then
56     if [ "$1" = "rpm-string" ]; then
57       echo ${TAG}-${ADD}${CMTR:+~${CMTR}}${BLD}
58     else
59       echo ${TAG}-${ADD}${CMT:+~${CMT}}${BLD}
60     fi
61   else
62     echo ${TAG}-release
63 fi