change from mirror to migrate (copy or mirror)

This commit is contained in:
Trevor Batley 2023-05-11 10:48:31 +10:00
parent c58aec524d
commit a11a00eb25
3 changed files with 79 additions and 37 deletions

View File

@ -19,12 +19,14 @@ bring down current git repository and run mockbuild\
git-get-and-build.sh \<repository\> \<organisation\> \[\<local\>\]\
\<local\> will build from local GITEA (in config) otherwise from remote GITEA
* git-mirror-repo.sh\
create mirror of src.koozali.org repository in a local GITEA instance\
git-mirror-repo.sh \<repository\> \<organisation\> \[\<target organisation\>\]\
* git-migrate-repo.sh\
create mirror or copy of src.koozali.org repository in a local GITEA instance\
git-mirror-repo.sh \<repository\> \<organisation\> \[\<copy|mirror\> \<target organisation\>\]\
\<copy|mirror\> will create local repo as either a copy or a mirror of the remote repo (default = copy)
\<target organisation\> within your local GITEA, otherwise local user
* git-mirror-org.sh\
* git-migrate-org.sh\
create mirrors of all repos for an organisation in a local GITEA instance\
git-mirror-org.sh \<organisation\> \[\<target organisation\>\]\
git-mirror-org.sh \<organisation\> \[\<copy|mirror\> \<target organisation\>\]\
\<copy|mirror\> will create local repos as either a copy or a mirror of the remote repos (default = copy)
\<target organisation\> within your local GITEA, otherwise local user

View File

@ -37,18 +37,32 @@ if [[ -z $1 ]] ; then
exit 0
fi
DEBUG=
if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi
if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi
curlsilent="-s"
if [ $DEBUG ] ; then curlsilent= ; fi
if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi
if [ $DEBUG ] ; then
echo "found ini file: $inifilename"
curlsilent=
fi
MIRROR="copy"
TARGETORG=
#if [ $2 ] ; then TARGETORG=$2 ; fi
for $param in {$2 $3} ; do
if [ $PARAM ] ; then
if [ $param == "copy" || $param == "mirror" ] ; then
$MIRROR=$param
else
$TARGETORG=$param
fi
else
break
fi
done
REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
REMOTEGITEAHOST=${remote_GITEAHOST}
LOCALGITEAHOST=${local_GITEAHOST}
TARGETORG=
if [ $2 ] ; then TARGETORG=$2 ; fi
if [ $DEBUG ] ; then echo "TARGETORG=$TARGETORG" ; fi
# check that the target organisation exists locally
@ -75,8 +89,8 @@ for page in {1..10} ; do
break
else
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
if [ $DEBUG ] ; then echo "git-mirror-repo.sh ${repo} $1 $TARGETORG" ; fi
git-mirror-repo.sh ${repo} $1 $TARGETORG
if [ $DEBUG ] ; then echo "git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR" ; fi
git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR
done
fi
done

View File

@ -41,7 +41,7 @@ if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi
if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi
curlsilent="-s"
if [ $DEBUG ] ; then curlsilent= ; fi
if [ $DEBUG ] ; then curlsilent="-v" ; fi
REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
@ -49,7 +49,23 @@ REMOTEGITEAHOST=${remote_GITEAHOST}
CLONEADDRESS=$REMOTEGITEAHOST/$2/$1.git
LOCALGITEAHOST=${local_GITEAHOST}
TARGETORG=${local_USER}
if [ $3 ] ; then TARGETORG=$3 ; fi
#if [ $3 ] ; then TARGETORG=$3 ; fi
MIRROR="false"
for param in $3 $4 ; do
if [ $param ] ; then
if [[ $param == "copy" || $param == "mirror" ]] ; then
if [ $param == "mirror" ] ; then MIRROR="true" ; fi
else
TARGETORG=$param
fi
else
break
fi
done
if [ $DEBUG ] ; then
echo "MIRROR=$MIRROR"
echo "TARGETORG=$TARGETORG"
fi
# check that the TARGETORG exists
if [ $DEBUG ] ; then echo "checking if $TARGETORG exists on $LOCALGITEAHOST" ; fi
@ -69,30 +85,34 @@ if [ "$RESPONSE" == "200" ] ; then
exit 1
fi
if [ $DEBUG ] ; then echo "Mirroring $2/$1 as $TARGETORG/$1 on $LOCALGITEAHOST" ; fi
DATA=$(cat << EOT
"auth_token": "$REMOTEACCESSTOKEN",
"clone_addr": "$CLONEADDRESS",
"issues": true,
"labels": true,
"lfs": true,
"milestones": true,
"mirror": $MIRROR,
"private": false,
"pull_requests": true,
"releases": true,
"repo_name": "$1",
"repo_owner": "$TARGETORG",
"service": "git",
"uid": 0,
"wiki": true
EOT
)
if [ $DEBUG ] ; then echo "JSON DATA=$DATA" ; fi
if [ $DEBUG ] ; then echo "Migrating $2/$1 as $TARGETORG/$1 on $LOCALGITEAHOST MIRROR=$MIRROR" ; fi
RESPONSE=$(curl $curlsilent -k -X 'POST' \
"$LOCALGITEAHOST/api/v1/repos/migrate" \
-H 'accept: application/json' \
-H "Authorization: token $LOCALACCESSTOKEN" \
-H 'Content-Type: application/json' \
-d '{
"auth_token": "'"$REMOTEACCESSTOKEN"'",
"clone_addr": "'"$CLONEADDRESS"'",
"issues": true,
"labels": true,
"lfs": true,
"milestones": true,
"mirror": true,
"private": false,
"pull_requests": true,
"releases": true,
"repo_name": "'"$1"'",
"repo_owner": "'"$TARGETORG"'",
"service": "git",
"uid": 0,
"wiki": true
}')
-d "{ $DATA }"
)
if [ $DEBUG ] ; then echo $? $RESPONSE ; fi
# And check if this repo is there
@ -100,7 +120,13 @@ if [ $DEBUG ] ; then echo "checking that $TARGETORG/$1 exists" ; fi
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1)
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
if [ "$RESPONSE" == "200" ] ; then
echo "Repository $TARGETORG/$1 has been created and mirrors $2/$1"
msg="Repository $TARGETORG/$1 has been created"
if [ $MIRROR == "true" ] ; then
msg=$msg" and mirrors $2/$1"
else
msg=$msg" and is a copy of $2/$1"
fi
echo $msg
else
echo "migrate-repo was unable to migrate $2/$1 sucessfully"
exit 1