Blame return_disttag.sh

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