pgreco / centos-git-common

Forked from centos-git-common 5 years ago
Clone

Blame show_possible_srpms.sh

d02a8a
#!/bin/bash -u
d02a8a
#
d02a8a
# Might want to drop this in ~/bin/ and chmod u+x it
e1634f
#
d02a8a
d02a8a
#####################################################################
d02a8a
usage() {
d02a8a
    echo ''                                               >&2
d02a8a
    echo "$0 [-hrcq] [-b branch]"                         >&2
d02a8a
    echo ''                                               >&2
e1634f
    echo ' Finds all possible srpms for a given repo'     >&2
e1634f
    echo ' based on the commit log'                       >&2
e1634f
    echo ''                                               >&2
d02a8a
    echo 'You need to run this from inside a sources git repo' >&2
d02a8a
    echo ''                                               >&2
d02a8a
    echo ' -h: This help message'                         >&2
Pat Riehecky 8be9a2
    echo ' -r: Use the Redhat commits only'               >&2
d02a8a
    echo ' -c: Return in sha:srpm format'                 >&2
d02a8a
    echo ' -q: Suppress warnings'                         >&2
d02a8a
    echo ''                                               >&2
d02a8a
    echo ' -b: specify a branch to examine'               >&2
d02a8a
    echo "     defaults to repo's current branch"         >&2
d02a8a
    echo ''                                               >&2
a2c711
    echo "  $0"                                           >&2
d02a8a
    echo "  $0 -b c7"                                     >&2
d02a8a
    echo "  $0 -r -b c7"                                  >&2
d02a8a
    echo "  $0 -c -b remotes/origin/c7"                   >&2
Pat Riehecky 8be9a2
    echo "  $0 -c -r -b remotes/origin/c7"                >&2
d02a8a
    exit 1
d02a8a
}
d02a8a
d02a8a
#####################################################################
d02a8a
warn () {
d02a8a
    [[ ${QUIET} -eq 1 ]] && return
d02a8a
    echo 1>&2 "$@"
d02a8a
}
d02a8a
d02a8a
#####################################################################
d02a8a
Pat Riehecky 8be9a2
RHELAUTHOR="CentOS Buildsys <bugs@centos.org>"
d02a8a
Pat Riehecky 8be9a2
RHELONLY=0
d02a8a
QUIET=0
d02a8a
WITHCOMMITHASH=0
d02a8a
BRANCH=""
d02a8a
828874
# for setting any overrides, such as RHELAUTHOR or default BRANCH
828874
if [ -f /etc/centos-git-common ]; then
828874
  . /etc/centos-git-common
828874
fi
828874
d02a8a
#####################################################################
d02a8a
# setup args in the right order for making getopt evaluation
d02a8a
# nice and easy.  You'll need to read the manpages for more info
d02a8a
# utilizing 'while' construct rather than 'for arg' to avoid unnecessary
d02a8a
# shifting of program args
d02a8a
args=$(getopt -o hrcqb: -- "$@")
d02a8a
eval set -- "$args"
d02a8a
d02a8a
while [[ 0 -eq 0 ]]; do
d02a8a
    case $1 in
d02a8a
        -- )
d02a8a
            # end of getopt args, shift off the -- and get out of the loop
d02a8a
            shift
d02a8a
            break
d02a8a
           ;;
d02a8a
         -r )
Pat Riehecky 8be9a2
            # Only look at commits by RHEL
Pat Riehecky 8be9a2
            RHELONLY=1
d02a8a
            shift
d02a8a
           ;;
d02a8a
         -c )
d02a8a
            # return with the commit hash as a prefix of the resulting srpm
d02a8a
            WITHCOMMITHASH=1
d02a8a
            shift
d02a8a
           ;;
d02a8a
         -q )
d02a8a
            # suppress warnings
d02a8a
            QUIET=1
d02a8a
            shift
d02a8a
           ;;
d02a8a
         -b )
d02a8a
            # Check this particular branch 
d02a8a
            BRANCH=$2
d02a8a
            shift
d02a8a
            shift
d02a8a
           ;;
d02a8a
         -h )
d02a8a
            # get help
d02a8a
            usage
d02a8a
           ;;
d02a8a
    esac
d02a8a
done
d02a8a
a2c711
if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then
7520e4
    echo 'You need to run this from inside a sources git repo' >&2
a2c711
    exit 1
a2c711
fi
a2c711
d02a8a
# commit message contains white space, set IFS to \n
d02a8a
IFS='
d02a8a
'
d02a8a
Pat Riehecky 8be9a2
LOGARGS="--pretty=%H|\%s"
Pat Riehecky 8be9a2
if [[ ${RHELONLY} -eq 1 ]]; then
Pat Riehecky 8be9a2
    LOGARGS="${LOGARGS} --author='${RHELAUTHOR}'"
Pat Riehecky 8be9a2
fi
Pat Riehecky 8be9a2
d02a8a
if [[ "x${BRANCH}" != 'x' ]]; then
Pat Riehecky 8be9a2
    LOGARGS="${LOGARGS} ${BRANCH}"
Pat Riehecky 8be9a2
fi
Pat Riehecky 8be9a2
Pat Riehecky 8be9a2
loglist=$(git log ${LOGARGS} |grep import)
Pat Riehecky 8be9a2
if [[ $? -ne 0 ]]; then
Pat Riehecky 8be9a2
    exit 1
d02a8a
fi
d02a8a
d02a8a
# flag for if nothing is found
d02a8a
FOUND=False
d02a8a
for entry in $loglist; do
d02a8a
    FOUND=True
d02a8a
d02a8a
    pkg=$(echo ${entry} | cut -d' ' -f2)
d02a8a
    # strip .src.rpm if present
d02a8a
    nvr="${pkg%.src.rpm}"
d02a8a
    if [[ ${WITHCOMMITHASH} -eq 1 ]]; then
d02a8a
        shasum=$(echo ${entry} | cut -d'|' -f1)
d02a8a
        echo "${shasum}:${nvr}.src.rpm"
d02a8a
    else
d02a8a
        echo "${nvr}.src.rpm"
d02a8a
    fi
d02a8a
done
d02a8a
d02a8a
if [ "${FOUND}" != "True" ]
d02a8a
then
d02a8a
    warn "No SRPMs found"
d02a8a
fi
d02a8a