From 2edef6eb76c4d98277051fd8ca2278152de89d82 Mon Sep 17 00:00:00 2001 From: Trevor Batley Date: Wed, 10 May 2023 10:17:35 +1000 Subject: [PATCH] add system default ini and allow ~ in workdir --- git-cvs2git.sh | 25 +++++++++++++++++------- git-get-repo-and-build.sh | 25 +++++++++++++++++------- git-mirror-org.sh | 14 ++++++++----- git-mirror-repo.sh | 41 +++++++++++++++++++++------------------ 4 files changed, 67 insertions(+), 38 deletions(-) diff --git a/git-cvs2git.sh b/git-cvs2git.sh index 69f804d..58495f7 100755 --- a/git-cvs2git.sh +++ b/git-cvs2git.sh @@ -9,25 +9,29 @@ # if [[ -z $1 ]] ; then - echo "************git_cvs2git.sh []" + echo "************git-cvs2git.sh []" exit 0 fi clear echo "**************************************************************************************************" echo "* *" -echo "* SMEServer - git_cvs2git $1 $2 $3 `date` *" +echo "* SMEServer - git-cvs2git $1 $2 $3 `date` *" echo "* *" echo "**************************************************************************************************" # # Pull in parameters from a config file ~/.smegit/config # -#inifilename=$(find ~/GITFiles -name cvs2git.ini 2>/dev/null | head -n 1) inifilename=$(echo ~)"/.smegit/config" if [ ! -e $inifilename ] ; then - # Not here - echo "ERROR*******No ini file found $inifilename" - exit 1 + # Not here, look at system default + if [ ! -e /etc/smegit.ini ] ; then + echo "No ini file found $inifiename or /etc/smegit.ini" + echo "git-cvs2git.sh []" + exit 1 + else + initfilename="/etc/smegit.ini" + fi fi while read -r line || [[ -n "$line" ]]; do @@ -59,7 +63,14 @@ fi checkSSL="-k" LOCALUser=${local_USER} -WORKDIR=$(echo ~)/${smegit_WORKDIR} +if [[ $smegit_WORKDIR == ~* ]] ; then + # relative to users home dir + WORKDIR=$(echo ~)${smegit_WORKDIR:1} +else + # absolute path + WORKDIR=${smegit_WORKDIR} +fi +if [ $DEBUG ] ; then echo "WORKDIR=$WORKDIR" ; fi GITEAUser=${remote_USER} GITEAACCESSTOKEN=${remote_GITEAACCESSTOKEN} GITEAHOST=${remote_GITEAHOST} diff --git a/git-get-repo-and-build.sh b/git-get-repo-and-build.sh index 9eeb54a..bed3ca2 100755 --- a/git-get-repo-and-build.sh +++ b/git-get-repo-and-build.sh @@ -4,12 +4,16 @@ # monitor results and log # inifilename=$(echo ~)"/.smegit/config" -if [ -z $inifilename ] ; then - # Not here, look a bit further up - echo "No ini file found $inifiename" - echo "get-repo-and-build.sh []" - exit 1 -fi +if [ ! -e $inifilename ] ; then + # Not here, look at system default + if [ ! -e /etc/smegit.ini ] ; then + echo "No ini file found $inifiename or /etc/smegit.ini" + echo "get-repo-and-build.sh []" + exit 1 + else + initfilename="/etc/smegit.ini" + fi +fi while read -r line || [[ -n "$line" ]]; do if [[ $line =~ ^\[.*\]$ ]] then @@ -47,7 +51,14 @@ if [ $3 ] ; then fi ORG_NAME="$1" REPO_NAME="$2" -WORKDIR=$(echo ~)${smegit_WORKDIR} +if [[ $smegit_WORKDIR == ~* ]] ; then + # relative to users home dir + WORKDIR=$(echo ~)${smegit_WORKDIR:1} +else + # absolute path + WORKDIR=${smegit_WORKDIR} +fi +if [ $DEBUG ] ; then echo "WORKDIR=$WORKDIR" ; fi GITFiles=$WORKDIR/GITFiles/$ORG_NAME REPOURL="$GITEAHOST/$ORG_NAME/$REPO_NAME.git" diff --git a/git-mirror-org.sh b/git-mirror-org.sh index 0f93662..176e979 100755 --- a/git-mirror-org.sh +++ b/git-mirror-org.sh @@ -5,11 +5,15 @@ # migrate-repo.sh [] # inifilename=$(echo ~)"/.smegit/config" -if [ -z $inifilename ] ; then - # Not here, look a bit further up - echo "No ini file found $inifilename" - echo "git-mirror-org.sh []" - exit 1 +if [ ! -e $inifilename ] ; then + # Not here, look at system default + if [ ! -e /etc/smegit.ini ] ; then + echo "No ini file found $inifiename or /etc/smegit.ini" + echo "git-mirror-org.sh []" + exit 1 + else + initfilename="/etc/smegit.ini" + fi fi while read -r line || [[ -n "$line" ]]; do diff --git a/git-mirror-repo.sh b/git-mirror-repo.sh index 91e3b4a..ee9b3b5 100755 --- a/git-mirror-repo.sh +++ b/git-mirror-repo.sh @@ -5,11 +5,15 @@ # migrate-repo.sh [] # inifilename=$(echo ~)"/.smegit/config" -if [ -z $inifilename ] ; then - # Not here - echo "No ini file found $inifilename" - echo "git_mirror-repo.sh []" - exit 1 +if [ ! -e $inifilename ] ; then + # Not here, look at system default + if [ ! -e /etc/smegit.ini ] ; then + echo "No ini file found $inifiename or /etc/smegit.ini" + echo "git_mirror-repo.sh []" + exit 1 + else + initfilename="/etc/smegit.ini" + fi fi while read -r line || [[ -n "$line" ]]; do @@ -29,7 +33,7 @@ done < $inifilename if [[ -z $1 ]] ; then echo "git_migrate-repo.sh []" - echo "will migrate repo to ${local_USER} unless specified" + echo "will migrate repo to local user unless specified" exit 0 fi DEBUG= @@ -39,30 +43,29 @@ if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi curlsilent="-s" if [ $DEBUG ] ; then curlsilent= ; fi -REMOTEUser=${remote_USER} REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN} LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN} REMOTEGITEAHOST=${remote_GITEAHOST} CLONEADDRESS=$REMOTEGITEAHOST/$2/$1.git LOCALGITEAHOST=${local_GITEAHOST} -NEWORG=${local_USER} -if [ $3 ] ; then NEWORG=$3 ; fi +TARGETORG=${local_USER} +if [ $3 ] ; then TARGETORG=$3 ; fi -# check that the NEWORG exists -RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$NEWORG) +# check that the TARGETORG exists +RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG) if [[ "$RESPONSE" != "200" ]] ; then - echo "$NEWORG does not exist on $LOCALGITEAHOST" + echo "$TARGETORG does not exist on $LOCALGITEAHOST" exit 1 fi # And check if this repo already exists on the target -RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$NEWORG/$1) +RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1) if [ "$RESPONSE" == "200" ] ; then - echo "Repository $NEWORG/$1 already exists on $LOCALGITEAHOST - cannot migrate" + echo "Repository $TARGETORG/$1 already exists on $LOCALGITEAHOST - cannot migrate" exit 1 fi -if [ $DEBUG ] ; then echo "Mirroring $2/$1 as $NEWORG/$1 on $LOCALGITEAHOST" ; fi +if [ $DEBUG ] ; then echo "Mirroring $2/$1 as $TARGETORG/$1 on $LOCALGITEAHOST" ; fi RESPONSE=$(curl $curlsilent -k -X 'POST' \ "$LOCALGITEAHOST/api/v1/repos/migrate" \ -H 'accept: application/json' \ @@ -80,7 +83,7 @@ RESPONSE=$(curl $curlsilent -k -X 'POST' \ "pull_requests": true, "releases": true, "repo_name": "'"$1"'", - "repo_owner": "'"$NEWORG"'", + "repo_owner": "'"$TARGETORG"'", "service": "git", "uid": 0, "wiki": true @@ -89,10 +92,10 @@ RESPONSE=$(curl $curlsilent -k -X 'POST' \ if [ $DEBUG ] ; then echo $? $RESPONSE ; fi # And check if this repo is there -if [ $DEBUG ] ; then echo "checking that $NEWORG/$1 exists" ; fi -RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$NEWORG/$1) +if [ $DEBUG ] ; then echo "checking that $TARGETORG/$1 exists" ; fi +RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1) if [ "$RESPONSE" == "200" ] ; then - echo "Repository $NEWORG/$1 has been created and mirrors $2/$1" + echo "Repository $TARGETORG/$1 has been created and mirrors $2/$1" else echo "migrate-repo was unable to migrate $2/$1 sucessfully" exit 1