Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 3 | path=$( cd "$(dirname "${BASH_SOURCE}")" ; pwd -P ) |
| 4 | |
| 5 | cd "$path" |
| 6 | |
Damjan Marion | c06eeb0 | 2017-04-18 15:26:39 +0200 | [diff] [blame] | 7 | if [ -f .version ]; then |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 8 | vstring=$(cat .version) |
| 9 | else |
Damjan Marion | c06eeb0 | 2017-04-18 15:26:39 +0200 | [diff] [blame] | 10 | vstring=$(git describe) |
| 11 | if [ $? != 0 ]; then |
| 12 | exit 1 |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 13 | fi |
| 14 | fi |
| 15 | |
| 16 | TAG=$(echo ${vstring} | cut -d- -f1 | sed -e 's/^v//') |
| 17 | ADD=$(echo ${vstring} | cut -s -d- -f2) |
| 18 | |
| 19 | git rev-parse 2> /dev/null |
| 20 | if [ $? == 0 ]; then |
| 21 | CMT=$(git describe --dirty --match 'v*'| cut -s -d- -f3,4) |
| 22 | else |
| 23 | CMT=$(echo ${vstring} | cut -s -d- -f3,4) |
| 24 | fi |
| 25 | CMTR=$(echo $CMT | sed 's/-/_/') |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 26 | |
Damjan Marion | 4e6be68 | 2016-05-16 15:55:36 +0200 | [diff] [blame] | 27 | if [ -n "${BUILD_NUMBER}" ]; then |
| 28 | BLD="~b${BUILD_NUMBER}" |
| 29 | fi |
| 30 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 31 | if [ "$1" = "rpm-version" ]; then |
| 32 | echo ${TAG} |
| 33 | exit |
| 34 | fi |
| 35 | |
| 36 | if [ "$1" = "rpm-release" ]; then |
| 37 | [ -z "${ADD}" ] && echo release && exit |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 38 | echo ${ADD}${CMTR:+~${CMTR}}${BLD} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 39 | exit |
| 40 | fi |
| 41 | |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 42 | 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 Marion | 926c706 | 2017-01-21 00:04:30 +0100 | [diff] [blame] | 49 | echo ${TAG}-release |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 50 | fi |