blob: 807109e4103465ba0c012fc7510a88e0768659b4 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001#!/bin/bash
2
Dave Barach8d0f2f02018-03-12 09:31:36 -04003# 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
Thomas F Herbert20a29c72016-10-13 18:36:50 -040016path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
17
18cd "$path"
19
Damjan Marionc06eeb02017-04-18 15:26:39 +020020if [ -f .version ]; then
Thomas F Herbert20a29c72016-10-13 18:36:50 -040021 vstring=$(cat .version)
22else
Damjan Marionc06eeb02017-04-18 15:26:39 +020023 vstring=$(git describe)
24 if [ $? != 0 ]; then
25 exit 1
Thomas F Herbert20a29c72016-10-13 18:36:50 -040026 fi
27fi
28
29TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//')
30ADD=$(echo ${vstring} | cut -s -d- -f2)
31
32git rev-parse 2> /dev/null
33if [ $? == 0 ]; then
34 CMT=$(git describe --dirty --match 'v*'| cut -s -d- -f3,4)
35else
36 CMT=$(echo ${vstring} | cut -s -d- -f3,4)
37fi
38CMTR=$(echo $CMT | sed 's/-/_/')
Ed Warnickecb9cada2015-12-08 15:45:58 -070039
Damjan Marion4e6be682016-05-16 15:55:36 +020040if [ -n "${BUILD_NUMBER}" ]; then
41 BLD="~b${BUILD_NUMBER}"
42fi
43
Ed Warnickecb9cada2015-12-08 15:45:58 -070044if [ "$1" = "rpm-version" ]; then
45 echo ${TAG}
46 exit
47fi
48
49if [ "$1" = "rpm-release" ]; then
50 [ -z "${ADD}" ] && echo release && exit
Thomas F Herbert20a29c72016-10-13 18:36:50 -040051 echo ${ADD}${CMTR:+~${CMTR}}${BLD}
Ed Warnickecb9cada2015-12-08 15:45:58 -070052 exit
53fi
54
Thomas F Herbert20a29c72016-10-13 18:36:50 -040055 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
Damjan Marion926c7062017-01-21 00:04:30 +010062 echo ${TAG}-release
Ed Warnickecb9cada2015-12-08 15:45:58 -070063fi