Blob Blame History Raw
#!/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}