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
36ca69
msg=$(git log --pretty=format:"%s" | grep import | head -n 1)
4d96e5
pkg=$(echo ${msg} | cut -d' ' -f2)
4d96e5
4d96e5
if [[ ${RHELTAG} -eq 0 ]]; then
0ec59d
    thispkg=$(echo ${pkg} | head -1)
4d96e5
elif [[ ${RHELTAG} -eq 1 ]]; then
0ec59d
    thispkg=$(echo ${pkg} grep -v centos | head -1)
4d96e5
else
4d96e5
    echo 'Something went terribly wrong'
4d96e5
    exit 1
4d96e5
fi
4d96e5
a6a9e5
# strip .src.rpm if present
a6a9e5
nvr1="${pkg%.src.rpm}"
4d96e5
a6a9e5
#now get nvr from spec with placeholder dist
a6a9e5
mydist="XXXjsdf9ur7qlkasdh4gygXXX"
a6a9e5
nvr2=$(rpm --define "dist $mydist" -q --specfile "SPECS/$packagename.spec" --qf '%{n}-%{v}-%{r}\n' 2>/dev/null | head -n 1)
a6a9e5
a6a9e5
#use our placeholder dist to split the nvr
a6a9e5
head=${nvr2%$mydist*}
a6a9e5
a6a9e5
if [ ".$head" = ".$nvr2" ]
a6a9e5
then
a6a9e5
    #no dist tag
a6a9e5
    echo ""
a6a9e5
    exit
a6a9e5
fi
a6a9e5
a6a9e5
tail=${nvr2#*$mydist}
a6a9e5
a6a9e5
frag=${nvr1#$head}
a6a9e5
dist=${frag%$tail}
a6a9e5
a6a9e5
echo "$dist"