2023-06-02 03:38:02 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Run script against every item in input file
|
|
|
|
|
|
|
|
if [[ -z $1 ]] ; then
|
|
|
|
echo "parse a list of parameters and execute script with those parameters"
|
|
|
|
echo "parse-list.sh <param file> <script> [<noisy> <additional> <additional> <additional>]"
|
|
|
|
echo "<param file> = name of file containing parameters"
|
|
|
|
echo "<script> script to run (e.g. rename-e-smith-pkh.sh)"
|
|
|
|
echo "optional params can appear in any order"
|
2023-06-03 08:22:03 +02:00
|
|
|
echo " <org='organisation'> run for each repo in 'organisation' (e.g. org=smeserver)"
|
|
|
|
echo " <review> show line being executed but do NOTHING!"
|
2023-06-02 03:38:02 +02:00
|
|
|
echo " <noisy> show line being executed"
|
|
|
|
echo " <additional> additional params to be passed (up to 3)"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ! -f $1 ]] ; then
|
|
|
|
echo "Can NOT find $1 - Aborting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $(which $2 | grep "no $2") ]] ; then
|
|
|
|
echo "Can NOT find $2 - Aborting"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-06-03 08:22:03 +02:00
|
|
|
REVIEW=
|
2023-06-02 03:38:02 +02:00
|
|
|
NOISY=
|
2023-06-03 08:22:03 +02:00
|
|
|
PROCESSORG=
|
2023-06-02 03:38:02 +02:00
|
|
|
EXTRAPARAMS=
|
|
|
|
for param in $3 $4 $5 $6; do
|
|
|
|
if [ $param ] ; then
|
|
|
|
case $param in
|
2023-06-03 08:22:03 +02:00
|
|
|
review )
|
|
|
|
REVIEW=true ;;
|
2023-06-02 03:38:02 +02:00
|
|
|
noisy )
|
|
|
|
NOISY=true ;;
|
2023-06-03 08:22:03 +02:00
|
|
|
org=* )
|
|
|
|
PROCESSORG=${$param#*=}
|
|
|
|
;;
|
2023-06-02 03:38:02 +02:00
|
|
|
* )
|
|
|
|
EXTRAPARAMS=$EXTRAPARAMS" "$param ;;
|
|
|
|
esac
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-06-03 08:22:03 +02:00
|
|
|
if [ $PROCESSORG ] ; then
|
|
|
|
# cycle through the repos in the specified organisation
|
|
|
|
# get a list of repositories in the source organisation
|
|
|
|
for page in {1..10} ; do
|
|
|
|
if [ $DEBUG ] ; then echo "getting page $page of repos from $GITHOST $1" ; fi
|
|
|
|
RESPONSE=$(curl $curlsilent -X 'GET' \
|
|
|
|
"$GITEAHOST/api/v1/orgs/$1/repos?page=$page" \
|
|
|
|
-H 'accept: application/json' \
|
|
|
|
-H "Authorization: token $ACCESSTOKEN"
|
|
|
|
)
|
|
|
|
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
|
|
|
|
|
|
|
if [[ $RESPONSE == '[]' ]] ; then
|
|
|
|
# we have them all
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
|
|
|
|
if [[ $NOISY || $REVIEW ]] ; then echo "$2 $repo $EXTRAPARAMS" ; fi
|
|
|
|
if [[ ! $REVIEW ]] ; then
|
|
|
|
if [[ $repo ]] ; then $2 $repo $EXTRAPARAMS ; fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
2023-06-02 03:38:02 +02:00
|
|
|
# read through input file and run script using params from file
|
2023-06-03 08:22:03 +02:00
|
|
|
while read -r line
|
|
|
|
do
|
|
|
|
if [[ $NOISY || $REVIEW ]] ; then echo "$2 $line $EXTRAPARAMS" ; fi
|
|
|
|
if [[ ! $REVIEW ]] ; then
|
|
|
|
if [[ $line ]] ; then $2 $line $EXTRAPARAMS ; fi
|
|
|
|
fi
|
|
|
|
done < $1
|
|
|
|
fi
|
2023-06-02 03:38:02 +02:00
|
|
|
exit 0
|