blob: d8728a9f6a8f94e8d0f6381ba6db5a2613ed9258 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001#!/bin/bash
2
Thomas F Herbert20a29c72016-10-13 18:36:50 -04003path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P )
4
5cd "$path"
6
Damjan Marionc06eeb02017-04-18 15:26:39 +02007if [ -f .version ]; then
Thomas F Herbert20a29c72016-10-13 18:36:50 -04008 vstring=$(cat .version)
9else
Damjan Marionc06eeb02017-04-18 15:26:39 +020010 vstring=$(git describe)
11 if [ $? != 0 ]; then
12 exit 1
Thomas F Herbert20a29c72016-10-13 18:36:50 -040013 fi
14fi
15
16TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//')
17ADD=$(echo ${vstring} | cut -s -d- -f2)
18
19git rev-parse 2> /dev/null
20if [ $? == 0 ]; then
21 CMT=$(git describe --dirty --match 'v*'| cut -s -d- -f3,4)
22else
23 CMT=$(echo ${vstring} | cut -s -d- -f3,4)
24fi
25CMTR=$(echo $CMT | sed 's/-/_/')
Ed Warnickecb9cada2015-12-08 15:45:58 -070026
Damjan Marion4e6be682016-05-16 15:55:36 +020027if [ -n "${BUILD_NUMBER}" ]; then
28 BLD="~b${BUILD_NUMBER}"
29fi
30
Ed Warnickecb9cada2015-12-08 15:45:58 -070031if [ "$1" = "rpm-version" ]; then
32 echo ${TAG}
33 exit
34fi
35
36if [ "$1" = "rpm-release" ]; then
37 [ -z "${ADD}" ] && echo release && exit
Thomas F Herbert20a29c72016-10-13 18:36:50 -040038 echo ${ADD}${CMTR:+~${CMTR}}${BLD}
Ed Warnickecb9cada2015-12-08 15:45:58 -070039 exit
40fi
41
Thomas F Herbert20a29c72016-10-13 18:36:50 -040042 if [ -n "${ADD}" ]; then
43 if [ "$1" = "rpm-string" ]; then
44 echo ${TAG}-${ADD}${CMTR:+~${CMTR}}${BLD}
45 else
46 echo ${TAG}-${ADD}${CMT:+~${CMT}}${BLD}
47 fi
48 else
Damjan Marion926c7062017-01-21 00:04:30 +010049 echo ${TAG}-release
Ed Warnickecb9cada2015-12-08 15:45:58 -070050fi