From: Pat Riehecky riehecky@fnal.gov
These three patches try and create a generic interface for some basic overrides, drawing from get_sources.sh
I've also updated get_sources.sh to utilize getopt for arg parsing
Pat Riehecky (3): Allow overrides of $RHELAUTHOR May want to set defaults from the override file.... Refactor to use getopt for arg parsing
get_sources.sh | 151 ++++++++++++++++++++++++++++++++++++------------ show_possible_srpms.sh | 11 +++- 2 files changed, 122 insertions(+), 40 deletions(-)
From: Pat Riehecky riehecky@fnal.gov
--- show_possible_srpms.sh | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/show_possible_srpms.sh b/show_possible_srpms.sh index 089412c..1dbf492 100755 --- a/show_possible_srpms.sh +++ b/show_possible_srpms.sh @@ -1,14 +1,16 @@ #!/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 ' Finds all possible srpms for a given repo' >&2 + echo ' based on the commit log' >&2 + echo '' >&2 echo 'You need to run this from inside a sources git repo' >&2 echo '' >&2 echo ' -h: This help message' >&2 @@ -37,6 +39,11 @@ warn () {
RHELAUTHOR="CentOS Buildsys bugs@centos.org"
+# for setting any overrides, such as RHELAUTHOR +if [ -f /etc/centos-git-common ]; then + . /etc/centos-git-common +fi + RHELONLY=0 QUIET=0 WITHCOMMITHASH=0
From: Pat Riehecky riehecky@fnal.gov
--- show_possible_srpms.sh | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/show_possible_srpms.sh b/show_possible_srpms.sh index 1dbf492..5f5fb93 100755 --- a/show_possible_srpms.sh +++ b/show_possible_srpms.sh @@ -39,16 +39,16 @@ warn () {
RHELAUTHOR="CentOS Buildsys bugs@centos.org"
-# for setting any overrides, such as RHELAUTHOR -if [ -f /etc/centos-git-common ]; then - . /etc/centos-git-common -fi - RHELONLY=0 QUIET=0 WITHCOMMITHASH=0 BRANCH=""
+# for setting any overrides, such as RHELAUTHOR or default BRANCH +if [ -f /etc/centos-git-common ]; then + . /etc/centos-git-common +fi + ##################################################################### # setup args in the right order for making getopt evaluation # nice and easy. You'll need to read the manpages for more info
From: Pat Riehecky riehecky@fnal.gov
--- get_sources.sh | 151 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 113 insertions(+), 38 deletions(-)
diff --git a/get_sources.sh b/get_sources.sh index f1dd30c..33ef1aa 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -1,51 +1,125 @@ #!/bin/bash # -# Script to parse the non-text sources metadata file and download -# the required files from the lookaside cache -# -# Please note: this script is non-destructive, it wont replace -# files that already exist, regardless of their state, allowing you -# to have work-in-progress content that wont get overwritten. -# # Might want to drop this in ~/bin/ and chmod u+x it +# + +# Initial Author: Karanbir Singh kbsingh@centos.org +# Updates: +# Mike McLean mikem@redhat.com +# Pat Riehecky riehecky@fnal.gov + + +##################################################################### +usage() { + echo '' >&2 + echo "$0 [-hcq] [-b branch] [--surl url]" >&2 + echo '' >&2 + echo 'Script to parse the non-text sources metadata file' >&2 + echo ' and download the required files from the lookaside' >&2 + echo ' cache.' >&2 + echo '' >&2 + echo 'PLEASE NOTE: this script is non-destructive, it wont' >&2 + echo ' replace files that already exist, regardless of' >&2 + echo ' their state, allowing you to have work-in-progress' >&2 + echo ' content that wont get overwritten.' >&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 '' >&2 + echo " $0 -b c7" >&2 + echo " $0 -q -b c7" >&2 + echo " $0 -c -b remotes/origin/c7" >&2 + echo " $0 -c -b c7 --surl '$SURL'" >&2 + echo " $0" >&2 + exit 1 +}
-surl="https://git.centos.org/sources/" +#####################################################################
-# for setting any overrides, such as surl or f +SURL="https://git.centos.org/sources/" + +QUIET=0 +BRANCH='' +CHECK=0 + +# for setting any overrides, such as SURL, default BRANCH, or force CHECK if [ -f /etc/centos-git-common ]; then . /etc/centos-git-common fi
-#parse command line args -BRANCH='' -QUIET='' -CHECK=0 -while (($# > 0)) -do - case $1 in - --branch) - #specify branch instead of asking git - BRANCH=$2 - shift 2 - ;; - --surl) - #override sources url - surl=$2 - shift 2 - ;; - --check) - #verify the sha1sum of the downloaded file - CHECK=1 - shift - ;; - -q) - # Be less chatty - QUIET='--silent' - shift - ;; - esac +##################################################################### +# 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 hcqb: -l surl: -- "$@") +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 + ;; + -c ) + # verify the sha1sum of the downloaded file + CHECK=1 + shift + ;; + -q ) + # suppress warnings + QUIET=1 + shift + ;; + -b ) + # Check this particular branch + BRANCH=$2 + shift + shift + ;; + --surl ) + # override sources url + SURL=$2 + shift + shift + ;; + -h ) + # get help + usage + ;; + esac done
+# set curl options this way so defaults can be set in /etc/centos-git-common +# across multiple scripts +if [[ ${QUIET} -eq 1 ]]; then + QUIET='--silent' +else + QUIET='' +fi + +which git >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then + echo 'You need git in PATH' >&2 + exit 1 +fi + +which curl >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then + echo 'You need curl in PATH' >&2 + exit 1 +fi + +if [[ ${CHECK} -eq 1 ]]; then + which sha1sum >/dev/null 2>&1 + if [[ $? -ne 0 ]]; then + echo 'You need sha1sum in PATH' >&2 + exit 1 + fi +fi + # check metadata file and extract package name shopt -s nullglob set -- .*.metadata @@ -100,7 +174,8 @@ while read -r fsha fname ; do if [ ! -e "${fname}" ]; then for br in "${branches[@]}" do - curl ${QUIET} -f "${surl}/${pn}/${br}/${fsha}" -o "${fname}" && break + br=$(echo ${br}| sed -e s'|remotes/origin/||') + curl ${QUIET} -f "${SURL}/${pn}/${br}/${fsha}" -o "${fname}" && break done else echo "${fname} exists. skipping"
All 3 patches in this set pushed.
On 06/26/2014 11:11 AM, Pat Riehecky wrote:
From: Pat Riehecky riehecky@fnal.gov
get_sources.sh | 151 ++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 113 insertions(+), 38 deletions(-)
diff --git a/get_sources.sh b/get_sources.sh index f1dd30c..33ef1aa 100755 --- a/get_sources.sh +++ b/get_sources.sh @@ -1,51 +1,125 @@ #!/bin/bash # -# Script to parse the non-text sources metadata file and download -# the required files from the lookaside cache -# -# Please note: this script is non-destructive, it wont replace -# files that already exist, regardless of their state, allowing you -# to have work-in-progress content that wont get overwritten. -# # Might want to drop this in ~/bin/ and chmod u+x it +#
+# Initial Author: Karanbir Singh kbsingh@centos.org +# Updates: +# Mike McLean mikem@redhat.com +# Pat Riehecky riehecky@fnal.gov
+##################################################################### +usage() {
- echo '' >&2
- echo "$0 [-hcq] [-b branch] [--surl url]" >&2
- echo '' >&2
- echo 'Script to parse the non-text sources metadata file' >&2
- echo ' and download the required files from the lookaside' >&2
- echo ' cache.' >&2
- echo '' >&2
- echo 'PLEASE NOTE: this script is non-destructive, it wont' >&2
- echo ' replace files that already exist, regardless of' >&2
- echo ' their state, allowing you to have work-in-progress' >&2
- echo ' content that wont get overwritten.' >&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 '' >&2
- echo " $0 -b c7" >&2
- echo " $0 -q -b c7" >&2
- echo " $0 -c -b remotes/origin/c7" >&2
- echo " $0 -c -b c7 --surl '$SURL'" >&2
- echo " $0" >&2
- exit 1
+}
-surl="https://git.centos.org/sources/" +#####################################################################
-# for setting any overrides, such as surl or f +SURL="https://git.centos.org/sources/"
+QUIET=0 +BRANCH='' +CHECK=0
+# for setting any overrides, such as SURL, default BRANCH, or force CHECK if [ -f /etc/centos-git-common ]; then . /etc/centos-git-common fi
-#parse command line args -BRANCH='' -QUIET='' -CHECK=0 -while (($# > 0)) -do
- case $1 in
- --branch)
#specify branch instead of asking git
BRANCH=$2
shift 2
;;
- --surl)
#override sources url
surl=$2
shift 2
;;
- --check)
#verify the sha1sum of the downloaded file
CHECK=1
shift
;;
-q)
# Be less chatty
QUIET='--silent'
shift
;;
- esac
+##################################################################### +# 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 hcqb: -l surl: -- "$@") +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
;;
-c )
# verify the sha1sum of the downloaded file
CHECK=1
shift
;;
-q )
# suppress warnings
QUIET=1
shift
;;
-b )
# Check this particular branch
BRANCH=$2
shift
shift
;;
--surl )
# override sources url
SURL=$2
shift
shift
;;
-h )
# get help
usage
;;
- esac
done
+# set curl options this way so defaults can be set in /etc/centos-git-common +# across multiple scripts +if [[ ${QUIET} -eq 1 ]]; then
- QUIET='--silent'
+else
- QUIET=''
+fi
+which git >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then
- echo 'You need git in PATH' >&2
- exit 1
+fi
+which curl >/dev/null 2>&1 +if [[ $? -ne 0 ]]; then
- echo 'You need curl in PATH' >&2
- exit 1
+fi
+if [[ ${CHECK} -eq 1 ]]; then
- which sha1sum >/dev/null 2>&1
- if [[ $? -ne 0 ]]; then
echo 'You need sha1sum in PATH' >&2
exit 1
- fi
+fi
# check metadata file and extract package name shopt -s nullglob set -- .*.metadata @@ -100,7 +174,8 @@ while read -r fsha fname ; do if [ ! -e "${fname}" ]; then for br in "${branches[@]}" do
curl ${QUIET} -f "${surl}/${pn}/${br}/${fsha}" -o "${fname}" && break
br=$(echo ${br}| sed -e s'|remotes/origin/||')
else echo "${fname} exists. skipping"curl ${QUIET} -f "${SURL}/${pn}/${br}/${fsha}" -o "${fname}" && break done