arrfab / centos-git-common

Forked from centos-git-common 5 years ago
Clone

Blame show_possible_srpms.sh

d02a8a
#!/bin/bash -u
d02a8a
#
d02a8a
# Finds all possible srpms for a given repo
d02a8a
#
d02a8a
# Might want to drop this in ~/bin/ and chmod u+x it
d02a8a
d02a8a
#####################################################################
d02a8a
usage() {
d02a8a
    echo ''                                               >&2
d02a8a
    echo "$0 [-hrcq] [-b branch]"                         >&2
d02a8a
    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
d02a8a
    echo ' -r: Use the Redhat tag rather than centos tag' >&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
d02a8a
    exit 1
d02a8a
}
d02a8a
d02a8a
#####################################################################
d02a8a
warn () {
d02a8a
    [[ ${QUIET} -eq 1 ]] && return
d02a8a
    echo 1>&2 "$@"
d02a8a
}
d02a8a
d02a8a
#####################################################################
d02a8a
filter () {
d02a8a
    # filter used for log messages
d02a8a
    if [[ ${RHELTAG} -eq 1 ]]
d02a8a
    then
d02a8a
        grep -v centos | grep import
d02a8a
    else
d02a8a
        grep import
d02a8a
    fi
d02a8a
}
d02a8a
d02a8a
#####################################################################
d02a8a
d02a8a
RHELTAG=0
d02a8a
QUIET=0
d02a8a
WITHCOMMITHASH=0
d02a8a
BRANCH=""
d02a8a
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 )
d02a8a
            # skip any package with 'centos' in the dist area
d02a8a
            RHELTAG=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
a2c711
    echo 'You need to run this from inside a sources git repo'
a2c711
    exit 1
a2c711
fi
a2c711
d02a8a
# commit message contains white space, set IFS to \n
d02a8a
IFS='
d02a8a
'
d02a8a
d02a8a
if [[ "x${BRANCH}" != 'x' ]]; then
d02a8a
    loglist=$(git log ${BRANCH} --pretty="%H|%s" | filter)
d02a8a
    if [[ $? -ne 0 ]]; then
d02a8a
        exit 1
d02a8a
    fi
d02a8a
else
d02a8a
    loglist=$(git log --pretty="%H|%s" | filter)
d02a8a
    if [[ $? -ne 0 ]]; then
d02a8a
        exit 1
d02a8a
    fi
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