From 8ab69301558b8cea4228e3944a185ee174c7a687 Mon Sep 17 00:00:00 2001 From: Trevor Batley Date: Thu, 1 Jun 2023 09:07:39 +1000 Subject: [PATCH] abort on failed delete of existing repo --- git-cvs2git.sh | 62 +++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/git-cvs2git.sh b/git-cvs2git.sh index 25582e9..bf7c1e1 100755 --- a/git-cvs2git.sh +++ b/git-cvs2git.sh @@ -257,13 +257,26 @@ fi cd $GITFiles #git init $QUIET $1 -# Now delete the remote repo and re-create it and clone it in to local +# Work out if it is an SMEServer package or a 3rd party one +if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then + PACKAGETYPE="SMEServer Koozali developed" +else + PACKAGETYPE="3rd Party (Maintained by Koozali)" +fi + +# Now delete the repo, re-create it and clone it in to local if [ $DEBUG ] ; then echo "Delete $ORGGITEA/$1" ; fi -curl "$checkSSL" "$curlsilent" -X 'DELETE' \ +RESPONSE=$(curl "$checkSSL" "$curlsilent" -X 'DELETE' \ "$GITEAHOST/api/v1/repos/$ORGGITEA/$1" \ -H 'accept: application/json' \ - -H "Authorization: token $GITEAACCESSTOKEN" - + -H "Authorization: token $GITEAACCESSTOKEN") +if [[ $RESPONSE == "204" ]] ; then + if [ $DEBUG ] ; then echo "************Repository $ORGGITEA/$1 deleted or does not exist" ; fi +else + echo "************Can NOT delete Repository $ORGGITEA/$1 - results will be unknown - Aborting!" + echo "RESPONSE=$RESPONSE" + exit 1 +fi # and check if it is here. if [ $DEBUG ] ; then echo "Check if $ORGGITEA/$1 is there!" ; fi RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$1") @@ -275,21 +288,11 @@ else GOTREPO=1 fi -# Work out if it is an SMEServer package or a 3rd party one -if [[ "$NAME" =~ ^(smeserver-|e-smith-).* ]]; then - PACKAGETYPE="SMEServer Koozali developed" -else - PACKAGETYPE="3rd Party (Maintained by Koozali)" -fi - # -# Use the API interface to create the remote repo +# Create the repo # if [ $DEBUG ] ; then echo "************Creating repo for $1 $PACKAGETYPE" ; fi - -if [[ $GOTREPO -eq 1 ]] ; then - #Create it if it does not exist - JSONREPO=$(curl "$checkSSL" "$curlsilent" -X 'POST' "$GITEAHOST/api/v1/orgs/$ORGGITEA/repos" \ +RESPONSE=$(curl "$checkSSL" "$curlsilent" -X 'POST' "$GITEAHOST/api/v1/orgs/$ORGGITEA/repos" \ -H 'accept: application/json' \ -H "Authorization: token $GITEAACCESSTOKEN" \ -H 'Content-Type: application/json' \ @@ -306,31 +309,24 @@ if [[ $GOTREPO -eq 1 ]] ; then "template": false, "trust_model": "Default Trust Model" }') - - if [ $DEBUG ] ; then echo $JSONREPO ; fi +if [ $DEBUG ] ; then echo $RESPONSE ; fi - # and extract the http URL for it - HTTP_URL=`echo $JSONREPO | jq -r '.html_url'` +# and extract the http URL for it +HTTP_URL=`echo $RESPONSE | jq -r '.html_url'` - if [ $DEBUG ] ; then echo $HTTP_URL ; fi - - if [[ -z "${HTTP_URL}" ]]; then - echo "ERROR*******Repo for $1 appears NOT to have been created " - echo "$JSONREQ" - exit 1 - fi -else - # Already there - HTTP_URL=$RemoteRepoURL - JSONREQ="$1 Already exists" -fi +if [ $DEBUG ] ; then echo $HTTP_URL ; fi +if [[ -z "${HTTP_URL}" ]]; then + echo "ERROR*******Repo for $1 appears NOT to have been created " + echo "$RESPONSE" + exit 1 +fi # And check it now exists RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$GITEAHOST/api/v1/repos/$ORGGITEA/$1") if [[ "$RESPONSE" == "200" ]]; then if [ $DEBUG ] ; then echo "************Repository for $1 exists" ; fi else - echo "ERROR*******Repository for $1 has not been created ($JSONREQ)" + echo "ERROR*******Repository for $1 has not been created ($RESPONSE)" exit 1 fi