From 4d96e52f13acf810f9f65a760b53d0febb9aa4c1 Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Jun 10 2014 14:10:53 +0000 Subject: --- diff --git a/return_disttag.sh b/return_disttag.sh new file mode 100755 index 0000000..cc4829c --- /dev/null +++ b/return_disttag.sh @@ -0,0 +1,71 @@ +#!/bin/bash -u +# +# Extracts what appears to be the value of %{dist} from the commit message +# +# Might want to drop this in ~/bin/ and chmod u+x it + +##################################################################### +usage() { + echo '' >&2 + echo "$0 [-hr]" >&2 + echo '' >&2 + echo ' -h: This help message' >&2 + echo ' -r: Use the Redhat tag rather than centos tag' >&2 + echo '' >&2 + echo ' Attempt to extract what appears to be the value of %{dist}' >&2 + echo ' from the git.centos.org commit message' >&2 + exit 1 +} + + +##################################################################### +# setup args in the right order for making getopt evaluation +# nice and easy. You'll need to read the manpages for more info +args=$(getopt -o hr -- "$@") +if [[ $? -ne 0 ]]; then + usage +fi +eval set -- "$args" + +RHELTAG=0 +for arg in $@; do + case $1 in + -- ) + # end of getopt args, shift off the -- and get out of the loop + shift + break 2 + ;; + -r ) + # skip any package with 'centos' in the dist area + RHELTAG=1 + ;; + -h ) + # get help + usage + ;; + esac +done + +packagename=$(basename `pwd`) +metadata=.${packagename}.metadata + +if [[ ! -e ${metadata} ]] || [[ ! -d .git ]] || [[ ! -d SOURCES ]]; then + echo 'You need to run this from inside a sources git repo' + exit 1 +fi + +msg=$(git log --pretty=format:"%s") +pkg=$(echo ${msg} | cut -d' ' -f2) + +if [[ ${RHELTAG} -eq 0 ]]; then + thispkg=(echo ${pkg} | head -1) +elif [[ ${RHELTAG} -eq 1 ]]; then + thispkg=(echo ${pkg} grep -v centos | head -1) +else + echo 'Something went terribly wrong' + exit 1 +fi + +tag=$(echo ${thispkg} | awk -F"-" '{print $NF}' | tr '.' '\012'| grep -e el[[:digit:]]) + +echo ${tag}