From: Pat Riehecky riehecky@fnal.gov
I was looking for some automated tooling to determine what SRPMS can be generated by a given git repo. Since none was out there, I've tossed this together.
Pat Riehecky (3): Minor updates to some doc, nothing of real interest Added script to show srpms contained within a given repo Added switches for setting branch to check, alas I've no idea how to do this
return_disttag.sh | 3 +- show_possible_srpms.sh | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletions(-) create mode 100755 show_possible_srpms.sh
From: Pat Riehecky riehecky@fnal.gov
--- return_disttag.sh | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/return_disttag.sh b/return_disttag.sh index d0ae030..5f9d9d9 100755 --- a/return_disttag.sh +++ b/return_disttag.sh @@ -7,7 +7,7 @@ ##################################################################### usage() { echo '' >&2 - echo "$0 [-hr]" >&2 + echo "$0 [-hrq]" >&2 echo '' >&2 echo ' -h: This help message' >&2 echo ' -r: Use the Redhat tag rather than centos tag' >&2 @@ -22,6 +22,7 @@ usage() { ##################################################################### # 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 hrq -- "$@") if [[ $? -ne 0 ]]; then usage
From: Pat Riehecky riehecky@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 +
From: Pat Riehecky riehecky@fnal.gov
--- show_possible_srpms.sh | 23 ++++++++++++++++++++--- 1 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/show_possible_srpms.sh b/show_possible_srpms.sh index dc31c65..413204c 100755 --- a/show_possible_srpms.sh +++ b/show_possible_srpms.sh @@ -7,13 +7,16 @@ ##################################################################### usage() { echo '' >&2 - echo "$0 [-hrcq]" >&2 + echo "$0 [-hrcq] [-b branch]" >&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 + echo ' -b: specify a branch to examine' >&2 + echo " defaults to repo's current branch" >&2 + echo '' >&2 exit 1 }
@@ -22,7 +25,7 @@ usage() { # 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 -- "$@") +args=$(getopt -o hrcqb: -- "$@") if [[ $? -ne 0 ]]; then usage fi @@ -31,6 +34,7 @@ eval set -- "$args" RHELTAG=0 QUIET=0 WITHCOMMITHASH=0 +BRANCH="" for arg in "$@"; do case $1 in -- ) @@ -50,6 +54,12 @@ for arg in "$@"; do # suppress warnings QUIET=1 ;; + -b ) + # Check this particular branch + BRANCH=$2 + shift + shift + ;; -h ) # get help usage @@ -81,9 +91,16 @@ filter () { IFS=' '
+if [[ "x${BRANCH}" != 'x' ]]; then + echo "Someone with git-foo, a little help?" + exit 1 +else + loglist=$(git log --pretty="%H|%s" | filter) +fi + # flag for if nothing is found FOUND=False -for entry in $(git log --pretty="%H|%s" | filter); do +for entry in $loglist; do FOUND=True
pkg=$(echo ${entry} | cut -d' ' -f2)
On 2014-06-13 23:53, Pat Riehecky wrote: <snip>
+# 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
This should be a while loop. `shift` alters the script's parameter list, not the list looped over by `for`. (The getopt-parse.bash example should probably have emphasised that as well as the need for quoting...)
Potential problem cases with this structure as it stands right now:
$0 -r -b c7 ... # BRANCH=-b (I think) $0 -b -b c7 # will probably trip unset variable error
In other words, do `while true`, shift the appropriate amount in each case, and make sure to break / exit where appropriate (including a catch-all should-not-happen case, as in the sample).
- case $1 in
-- )
# end of getopt args, shift off the -- and get out of the loop
shift
break 2
Not that it's likely to matter, but you only have one loop to break out of here.
;;
-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
;;
-b )
# Check this particular branch
BRANCH=$2
shift
shift
;;
-h )
# get help
usage
;;
- esac
+done
<snip>
+if [[ "x${BRANCH}" != 'x' ]]; then
- echo "Someone with git-foo, a little help?"
- exit 1
See Mike's additions to get_sources [1] for a way to find branches containing HEAD and/or the current branch.
+else
- loglist=$(git log --pretty="%H|%s" | filter)
+fi
[1] https://git.centos.org/blobdiff/centos-git-common.git/c61c1ca/get_sources.sh lines 62 to 86
From: Pat Riehecky riehecky@fnal.gov
This is a fixed up version based on feedback from the devel list.
Pat Riehecky (1): Added script to show srpms contained within a given repo
show_possible_srpms.sh | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 139 insertions(+), 0 deletions(-) create mode 100755 show_possible_srpms.sh
From: Pat Riehecky riehecky@fnal.gov
Plus, fixes based on suggestions from Elias Persson http://lists.centos.org/pipermail/centos-devel/2014-June/010690.html --- show_possible_srpms.sh | 139 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 139 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..f8c5eac --- /dev/null +++ b/show_possible_srpms.sh @@ -0,0 +1,139 @@ +#!/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] [-b branch]" >&2 + echo '' >&2 + echo 'You need to run this from inside a sources git repo' >&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 + echo ' -b: specify a branch to examine' >&2 + echo " defaults to repo's current branch" >&2 + echo '' >&2 + echo " $0 -b c7" >&2 + echo " $0 -r -b c7" >&2 + echo " $0 -c -b remotes/origin/c7" >&2 + exit 1 +} + +##################################################################### +warn () { + [[ ${QUIET} -eq 1 ]] && return + echo 1>&2 "$@" +} + +##################################################################### +filter () { + # filter used for log messages + if [[ ${RHELTAG} -eq 1 ]] + then + grep -v centos | grep import + else + grep import + fi +} + +##################################################################### +if [[ $? -ne 0 ]]; then + usage +fi + +if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then + echo 'You need to run this from inside a sources git repo' + exit 1 +fi + +RHELTAG=0 +QUIET=0 +WITHCOMMITHASH=0 +BRANCH="" + +##################################################################### +# setup args in the right order for making getopt evaluation +# nice and easy. You'll need to read the manpages for more info +# utilizing 'while' construct rather than 'for arg' to avoid unnecessary +# shifting of program args +args=$(getopt -o hrcqb: -- "$@") +eval set -- "$args" + +while [[ 0 -eq 0 ]]; do + case $1 in + -- ) + # end of getopt args, shift off the -- and get out of the loop + shift + break + ;; + -r ) + # skip any package with 'centos' in the dist area + RHELTAG=1 + shift + ;; + -c ) + # return with the commit hash as a prefix of the resulting srpm + WITHCOMMITHASH=1 + shift + ;; + -q ) + # suppress warnings + QUIET=1 + shift + ;; + -b ) + # Check this particular branch + BRANCH=$2 + shift + shift + ;; + -h ) + # get help + usage + ;; + esac +done + +# commit message contains white space, set IFS to \n +IFS=' +' + +if [[ "x${BRANCH}" != 'x' ]]; then + loglist=$(git log ${BRANCH} --pretty="%H|%s" | filter) + if [[ $? -ne 0 ]]; then + exit 1 + fi +else + loglist=$(git log --pretty="%H|%s" | filter) + if [[ $? -ne 0 ]]; then + exit 1 + fi +fi + +# flag for if nothing is found +FOUND=False +for entry in $loglist; 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}.src.rpm" + else + echo "${nvr}.src.rpm" + fi +done + +if [ "${FOUND}" != "True" ] +then + warn "No SRPMs found" +fi +
On 06/16/2014 03:45 PM, Pat Riehecky wrote:
From: Pat Riehecky riehecky@fnal.gov
Plus, fixes based on suggestions from Elias Persson http://lists.centos.org/pipermail/centos-devel/2014-June/010690.html
ack/ pushed.
From: Pat Riehecky riehecky@fnal.gov
--- show_possible_srpms.sh | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
diff --git a/show_possible_srpms.sh b/show_possible_srpms.sh index f8c5eac..3092172 100755 --- a/show_possible_srpms.sh +++ b/show_possible_srpms.sh @@ -19,6 +19,7 @@ usage() { echo ' -b: specify a branch to examine' >&2 echo " defaults to repo's current branch" >&2 echo '' >&2 + echo " $0" >&2 echo " $0 -b c7" >&2 echo " $0 -r -b c7" >&2 echo " $0 -c -b remotes/origin/c7" >&2 @@ -43,14 +44,6 @@ filter () { }
##################################################################### -if [[ $? -ne 0 ]]; then - usage -fi - -if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then - echo 'You need to run this from inside a sources git repo' - exit 1 -fi
RHELTAG=0 QUIET=0 @@ -100,6 +93,11 @@ while [[ 0 -eq 0 ]]; do esac done
+if [[ ! -d .git ]] || [[ ! -d SPECS ]]; then + echo 'You need to run this from inside a sources git repo' + exit 1 +fi + # commit message contains white space, set IFS to \n IFS=' '
On 06/17/2014 05:49 PM, Pat Riehecky wrote:
From: Pat Riehecky riehecky@fnal.gov
show_possible_srpms.sh | 14 ++++++-------- 1 files changed, 6 insertions(+), 8 deletions(-)
pushed