add force and debug options

This commit is contained in:
Trevor Batley 2023-06-01 09:20:55 +10:00
parent 8ab6930155
commit db6884d245

View File

@ -3,19 +3,21 @@
# $1 = Module name e.g. e-smith-dnscache # $1 = Module name e.g. e-smith-dnscache
# $2 = Organisation (smeserver or user - defaults to smeserver) # $2 = Organisation (smeserver or user - defaults to smeserver)
# $3 = "local" will use parameters set for local repository else it will use remote # $3 = "local" will use parameters set for local repository else it will use remote
# $4 = "force" will automagically delete an existing repo, otherwise it will prompt
# $5 = "debug" run in debug mode
# This works whether the repo and local files exist of not (it deletes them if necessary) # This works whether the repo and local files exist of not (it deletes them if necessary)
# However if the remote repo exists, it preserves the README.md file so that edits are not lost # However if the remote repo exists, it preserves the README.md file so that edits are not lost
# Also note: I have had difficulty deleting all the link files in the source tree! # Also note: I have had difficulty deleting all the link files in the source tree!
# #
if [[ -z $1 ]] ; then if [[ -z $1 ]] ; then
echo "************rename-e-smith-pkg.sh <modulename> [<organization> <local>]" echo "************rename-e-smith-pkg.sh <modulename> [<organization> <local> <force> <debug>]"
exit 0 exit 0
fi fi
clear clear
echo "**************************************************************************************************" echo "**************************************************************************************************"
echo "* *" echo "* *"
echo "* SMEServer - rename-e-smith-pkg.sh $1 $2 $3 `date` *" echo "* SMEServer - rename-e-smith-pkg.sh $1 $2 $3 $4 $5 `date` *"
echo "* *" echo "* *"
echo "**************************************************************************************************" echo "**************************************************************************************************"
@ -74,15 +76,21 @@ SOURCEHOST=${remote_GITEAHOST}
SOURCEACCESSTOKEN=${remote_GITEAACCESSTOKEN} SOURCEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
SOURCEORG="smeserver" SOURCEORG="smeserver"
TARGETORG=${remote_USER} TARGETORG=${remote_USER}
for param in $2 $3 ; do DELETEIT=
for param in $2 $3 $4 $5; do
if [ $param ] ; then if [ $param ] ; then
if [[ $param == "local" ]] ; then case $param in
local )
SOURCEHOST=${local_GITEAHOST} SOURCEHOST=${local_GITEAHOST}
SOURCEACCESSTOKEN=${local_GITEAACCESSTOKEN} SOURCEACCESSTOKEN=${local_GITEAACCESSTOKEN}
TARGETORG=${local_USER} TARGETORG=${local_USER} ;;
else force )
SOURCEORGORG=$param DELETIT=true ;;
fi debug )
DEBUG=true ;;
* )
SOURCEORGORG=$param ;;
esac
else else
break break
fi fi
@ -110,10 +118,7 @@ if [ "$RESPONSE" == "200" ]; then
read -p "Do you wish to delete it and continue?(y/n) " yn read -p "Do you wish to delete it and continue?(y/n) " yn
case $yn in case $yn in
[Yy]* ) [Yy]* )
RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \ DELETEIT=true
"$SOURCEHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
-H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" )
break ;; break ;;
[Nn]* ) [Nn]* )
echo "************Abandoning Fork of $SOURCEORG/$SOURCEPKG on $SOURCEHOST ($RESPONSE)" echo "************Abandoning Fork of $SOURCEORG/$SOURCEPKG on $SOURCEHOST ($RESPONSE)"
@ -121,7 +126,12 @@ if [ "$RESPONSE" == "200" ]; then
* ) echo "Please answer yes or no.";; * ) echo "Please answer yes or no.";;
esac esac
done done
if [ $DELETEIT ] ; then
RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \
"$SOURCEHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \
-H 'accept: application/json' \
-H "Authorization: token $SOURCEACCESSTOKEN" )
fi
else else
if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $SOURCEHOST" ; fi if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $SOURCEHOST" ; fi
fi fi