From e5597e226266ade08b79237b7f0d9b6595e1359a Mon Sep 17 00:00:00 2001 From: Mike McLean Date: Jun 12 2014 00:07:32 +0000 Subject: don't rely on directory name for package name fix -r option fix quoting issues verify %{dist} value --- diff --git a/return_disttag.sh b/return_disttag.sh index f7dc610..d0ae030 100755 --- a/return_disttag.sh +++ b/return_disttag.sh @@ -11,6 +11,7 @@ usage() { echo '' >&2 echo ' -h: This help message' >&2 echo ' -r: Use the Redhat tag rather than centos tag' >&2 + echo ' -q: Suppress warnings' >&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 @@ -21,14 +22,15 @@ usage() { ##################################################################### # 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 -- "$@") +args=$(getopt -o hrq -- "$@") if [[ $? -ne 0 ]]; then usage fi eval set -- "$args" RHELTAG=0 -for arg in $@; do +QUIET=0 +for arg in "$@"; do case $1 in -- ) # end of getopt args, shift off the -- and get out of the loop @@ -39,6 +41,10 @@ for arg in $@; do # skip any package with 'centos' in the dist area RHELTAG=1 ;; + -q ) + # suppress warnings + QUIET=1 + ;; -h ) # get help usage @@ -46,26 +52,50 @@ for arg in $@; do esac done -packagename=$(basename `pwd`) -metadata=.${packagename}.metadata +warn () { + [[ ${QUIET} -eq 1 ]] && return + echo 1>&2 "$@" +} -if [[ ! -e ${metadata} ]] || [[ ! -d .git ]] || [[ ! -d SOURCES ]]; then +if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then echo 'You need to run this from inside a sources git repo' exit 1 fi -msg=$(git log --pretty=format:"%s" | grep import | head -n 1) -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' +# check metadata file and extract package name +packagename="" +shopt -s nullglob +for fn in .*.metadata +do + pn=${fn%.metadata} + pn=${pn#.} + if [ -e "SPECS/$pn.spec" ] + then + packagename="$pn" + break + fi +done +if [ -z "$packagename" ] +then + echo 'Missing metadata or spec. Please run from inside a sources git repo' exit 1 fi +filter () { + # filter used for log messages + if [[ ${RHELTAG} -eq 1 ]] + then + grep -v centos | grep import + else + grep import + fi +} + +# extract nvr from commit message of last import +msg=$(git log --pretty=format:"%s" | filter | head -n 1) +set -- $msg +pkg="$2" + # strip .src.rpm if present nvr1="${pkg%.src.rpm}" @@ -88,4 +118,12 @@ tail=${nvr2#*$mydist} frag=${nvr1#$head} dist=${frag%$tail} +# sanity check +nvr3=$(rpm --define "dist $dist" -q --specfile "SPECS/$packagename.spec" --qf '%{n}-%{v}-%{r}\n' 2>/dev/null | head -n 1) +if [ ".$nvr3" != ".$nvr1" ] +then + warn "Warning: $nvr3 != $nvr1" + warn "Warning: check failed. The %{dist} value may be incorrect" +fi + echo "$dist"