[CentOS-devel] [PATCH 2/3] Added script to show srpms contained within a given repo

Fri Jun 13 21:53:40 UTC 2014
Pat Riehecky <riehecky at fnal.gov>

From: Pat Riehecky <riehecky at fnal.gov>

---
 show_possible_srpms.sh |  104 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 104 insertions(+), 0 deletions(-)
 create mode 100755 show_possible_srpms.sh

diff --git a/show_possible_srpms.sh b/show_possible_srpms.sh
new file mode 100755
index 0000000..dc31c65
--- /dev/null
+++ b/show_possible_srpms.sh
@@ -0,0 +1,104 @@
+#!/bin/bash -u
+#
+# Finds all possible srpms for a given repo
+#
+# Might want to drop this in ~/bin/ and chmod u+x it
+
+#####################################################################
+usage() {
+    echo ''                                               >&2
+    echo "$0 [-hrcq]"                                     >&2
+    echo ''                                               >&2
+    echo ' -h: This help message'                         >&2
+    echo ' -r: Use the Redhat tag rather than centos tag' >&2
+    echo ' -c: Return in sha:srpm format'                 >&2
+    echo ' -q: Suppress warnings'                         >&2
+    echo ''                                               >&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
+# or review getopt-parse.bash under /usr/share/doc from which much was borrowed
+args=$(getopt -o hrcq -- "$@")
+if [[ $? -ne 0 ]]; then
+    usage
+fi
+eval set -- "$args"
+
+RHELTAG=0
+QUIET=0
+WITHCOMMITHASH=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
+           ;;
+         -c )
+            # return with the commit hash as a prefix of the resulting srpm
+            WITHCOMMITHASH=1
+           ;;
+         -q )
+            # suppress warnings
+            QUIET=1
+           ;;
+         -h )
+            # get help
+            usage
+           ;;
+    esac
+done
+
+warn () {
+    [[ ${QUIET} -eq 1 ]] && return
+    echo 1>&2 "$@"
+}
+
+if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then
+    echo 'You need to run this from inside a sources git repo'
+    exit 1
+fi
+
+filter () {
+    # filter used for log messages
+    if [[ ${RHELTAG} -eq 1 ]]
+    then
+        grep -v centos | grep import
+    else
+        grep import
+    fi
+}
+
+# commit message contains white space, set IFS to \n
+IFS='
+'
+
+# flag for if nothing is found
+FOUND=False
+for entry in $(git log --pretty="%H|%s" | filter); do
+    FOUND=True
+
+    pkg=$(echo ${entry} | cut -d' ' -f2)
+    # strip .src.rpm if present
+    nvr="${pkg%.src.rpm}"
+    if [[ ${WITHCOMMITHASH} -eq 1 ]]; then
+        shasum=$(echo ${entry} | cut -d'|' -f1)
+        echo "${shasum}:${nvr}"
+    else
+        echo "${nvr}"
+    fi
+done
+
+if [ "${FOUND}" != "True" ]
+then
+    warn "No SRPMs found"
+fi
+
-- 
1.7.1