From db6884d2455554bbffefaf3369b22002824e0a58 Mon Sep 17 00:00:00 2001 From: Trevor Batley Date: Thu, 1 Jun 2023 09:20:55 +1000 Subject: [PATCH] add force and debug options --- rename-e-smith-pkg.sh | 46 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/rename-e-smith-pkg.sh b/rename-e-smith-pkg.sh index 8511599..11675d6 100755 --- a/rename-e-smith-pkg.sh +++ b/rename-e-smith-pkg.sh @@ -3,19 +3,21 @@ # $1 = Module name e.g. e-smith-dnscache # $2 = Organisation (smeserver or user - defaults to smeserver) # $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) # 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! # if [[ -z $1 ]] ; then - echo "************rename-e-smith-pkg.sh [ ]" + echo "************rename-e-smith-pkg.sh [ ]" exit 0 fi clear 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 "**************************************************************************************************" @@ -74,15 +76,21 @@ SOURCEHOST=${remote_GITEAHOST} SOURCEACCESSTOKEN=${remote_GITEAACCESSTOKEN} SOURCEORG="smeserver" TARGETORG=${remote_USER} -for param in $2 $3 ; do +DELETEIT= +for param in $2 $3 $4 $5; do if [ $param ] ; then - if [[ $param == "local" ]] ; then - SOURCEHOST=${local_GITEAHOST} + case $param in + local ) + SOURCEHOST=${local_GITEAHOST} SOURCEACCESSTOKEN=${local_GITEAACCESSTOKEN} - TARGETORG=${local_USER} - else - SOURCEORGORG=$param - fi + TARGETORG=${local_USER} ;; + force ) + DELETIT=true ;; + debug ) + DEBUG=true ;; + * ) + SOURCEORGORG=$param ;; + esac else break fi @@ -105,23 +113,25 @@ fi if [ $DEBUG ] ; then echo "Check if $TARGETORG/$TARGETPKG is there!" ; fi RESPONSE=$(curl $SILENT -o /dev/null -w "%{http_code}" "$SOURCEHOST/api/v1/repos/$TARGETORG/$TARGETPKG") if [ "$RESPONSE" == "200" ]; then - echo "Repository for $TARGETORG/$TARGETPKG exists!" - while true; do + echo "Repository for $TARGETORG/$TARGETPKG exists!" + while true; do read -p "Do you wish to delete it and continue?(y/n) " yn case $yn in [Yy]* ) - RESPONSE=$(curl "$checkSSL" "$SILENT" -X 'DELETE' \ - "$SOURCEHOST/api/v1/repos/$TARGETORG/$TARGETPKG" \ - -H 'accept: application/json' \ - -H "Authorization: token $SOURCEACCESSTOKEN" ) - break;; + DELETEIT=true + break ;; [Nn]* ) echo "************Abandoning Fork of $SOURCEORG/$SOURCEPKG on $SOURCEHOST ($RESPONSE)" - exit 1;; + exit 1 ;; * ) echo "Please answer yes or no.";; esac 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 if [ $DEBUG ] ; then echo "Repository for $TARGETORG/$TARGETPKG does not exist on $SOURCEHOST" ; fi fi