parse input fiile to array before provcessing

This commit is contained in:
Trevor Batley 2023-06-06 11:45:25 +10:00
parent f2b2c021f8
commit 0c2b8da54f

View File

@ -5,14 +5,14 @@
if [[ -z $1 ]] ; then if [[ -z $1 ]] ; then
echo "parse a list of parameters and execute script with those parameters" echo "parse a list of parameters and execute script with those parameters"
echo "parse-list.sh <param file> <script> [<noisy> <additional> <additional> <additional>]" echo "parse-list.sh <param file> <script> [<noisy> <additional> <additional> <additional>]"
echo "<param file|org='organisation'> name of file containing parameters" echo "<param file|org='organisation'> name of file containing parameters"
echo " or the organisation list of repos" echo " or the organisation list of repos"
echo "<script> script to run (e.g. rename-e-smith-pkh.sh)" echo "<script> script to run (e.g. rename-e-smith-pkh.sh)"
echo "optional params can appear in any order" echo "optional params can appear in any order"
echo " <review> show line being executed but do NOTHING!" echo " <review> show line being executed but do NOTHING!"
echo " <noisy> show line being executed" echo " <noisy> show line being executed"
echo " <additional> additional params to be passed (up to 3)" echo " <additional> additional params to be passed (up to 3)"
exit 0 exit 0
fi fi
# parse the command line parameters # parse the command line parameters
@ -86,9 +86,10 @@ for param in $3 $4 $5 $6; do
fi fi
done done
# Build array of parameters to cycle through
PARAMLIST=
if [ $PROCESSORG ] ; then if [ $PROCESSORG ] ; then
# cycle through the repos in the specified organisation # get a list of repositories in the source organisation and store in array of parameters
# get a list of repositories in the source organisation
for page in {1..10} ; do for page in {1..10} ; do
if [ $DEBUG ] ; then echo "getting page $page of repos from $GITEAHOST $PROCESSORG" ; fi if [ $DEBUG ] ; then echo "getting page $page of repos from $GITEAHOST $PROCESSORG" ; fi
RESPONSE=$(curl -s -X 'GET' \ RESPONSE=$(curl -s -X 'GET' \
@ -105,19 +106,23 @@ if [ $PROCESSORG ] ; then
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
if [[ $NOISY || $REVIEW ]] ; then echo "$2 $repo $EXTRAPARAMS" ; fi if [[ $NOISY || $REVIEW ]] ; then echo "$2 $repo $EXTRAPARAMS" ; fi
if [[ ! $REVIEW ]] ; then if [[ ! $REVIEW ]] ; then
if [[ $repo ]] ; then $2 $repo $EXTRAPARAMS ; fi if [[ $repo ]] ; then $PARAMLIST+=$repo ; fi
fi fi
done done
fi fi
done done
else else
# read through input file and run script using params from file # load array of parameters from input file
while read -r line while read -r line ; do $PARAMLIST+=$line ; done < $1
do
if [[ $NOISY || $REVIEW ]] ; then echo "$2 $line $EXTRAPARAMS" ; fi
if [[ ! $REVIEW ]] ; then
if [[ $line ]] ; then $2 $line $EXTRAPARAMS ; fi
fi
done < $1
fi fi
# Cycle through array of parameters and execute script
for param in "${PARAMLIST[@]}"
do
if [[ $NOISY || $REVIEW ]] ; then echo "$2 $param $EXTRAPARAMS" ; fi
if [[ ! $REVIEW ]] ; then
if [[ $line ]] ; then $2 $param $EXTRAPARAMS ; fi
fi
done
exit 0 exit 0