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 | |
| 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/-/_/') |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 30 | |
Damjan Marion | 4e6be68 | 2016-05-16 15:55:36 +0200 | [diff] [blame] | 31 | if [ -n "${BUILD_NUMBER}" ]; then |
| 32 | BLD="~b${BUILD_NUMBER}" |
| 33 | fi |
| 34 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 42 | echo ${ADD}${CMTR:+~${CMTR}}${BLD} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 43 | exit |
| 44 | fi |
| 45 | |
Thomas F Herbert | 20a29c7 | 2016-10-13 18:36:50 -0400 | [diff] [blame] | 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} |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 54 | fi |