change from mirror to migrate (copy or mirror)
This commit is contained in:
parent
c58aec524d
commit
a11a00eb25
12
README.md
12
README.md
@ -19,12 +19,14 @@ bring down current git repository and run mockbuild\
|
|||||||
git-get-and-build.sh \<repository\> \<organisation\> \[\<local\>\]\
|
git-get-and-build.sh \<repository\> \<organisation\> \[\<local\>\]\
|
||||||
\<local\> will build from local GITEA (in config) otherwise from remote GITEA
|
\<local\> will build from local GITEA (in config) otherwise from remote GITEA
|
||||||
|
|
||||||
* git-mirror-repo.sh\
|
* git-migrate-repo.sh\
|
||||||
create mirror of src.koozali.org repository in a local GITEA instance\
|
create mirror or copy of src.koozali.org repository in a local GITEA instance\
|
||||||
git-mirror-repo.sh \<repository\> \<organisation\> \[\<target organisation\>\]\
|
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
|
\<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\
|
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
|
\<target organisation\> within your local GITEA, otherwise local user
|
@ -37,18 +37,32 @@ if [[ -z $1 ]] ; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
DEBUG=
|
DEBUG=
|
||||||
if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi
|
|
||||||
if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi
|
|
||||||
|
|
||||||
curlsilent="-s"
|
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}
|
REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
||||||
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
||||||
REMOTEGITEAHOST=${remote_GITEAHOST}
|
REMOTEGITEAHOST=${remote_GITEAHOST}
|
||||||
LOCALGITEAHOST=${local_GITEAHOST}
|
LOCALGITEAHOST=${local_GITEAHOST}
|
||||||
TARGETORG=
|
|
||||||
if [ $2 ] ; then TARGETORG=$2 ; fi
|
|
||||||
if [ $DEBUG ] ; then echo "TARGETORG=$TARGETORG" ; fi
|
if [ $DEBUG ] ; then echo "TARGETORG=$TARGETORG" ; fi
|
||||||
|
|
||||||
# check that the target organisation exists locally
|
# check that the target organisation exists locally
|
||||||
@ -75,8 +89,8 @@ for page in {1..10} ; do
|
|||||||
break
|
break
|
||||||
else
|
else
|
||||||
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
|
echo $RESPONSE | grep -oP '(?<="name":").+?(?=")' | while read repo; do
|
||||||
if [ $DEBUG ] ; then echo "git-mirror-repo.sh ${repo} $1 $TARGETORG" ; fi
|
if [ $DEBUG ] ; then echo "git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR" ; fi
|
||||||
git-mirror-repo.sh ${repo} $1 $TARGETORG
|
git-migrate-repo.sh ${repo} $1 $TARGETORG $MIRROR
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
done
|
done
|
@ -41,7 +41,7 @@ if [ ${smegit_DEBUG} == true ] ; then DEBUG=true ; fi
|
|||||||
if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi
|
if [ $DEBUG ] ; then echo "found ini file: $inifilename" ; fi
|
||||||
|
|
||||||
curlsilent="-s"
|
curlsilent="-s"
|
||||||
if [ $DEBUG ] ; then curlsilent= ; fi
|
if [ $DEBUG ] ; then curlsilent="-v" ; fi
|
||||||
|
|
||||||
REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
REMOTEACCESSTOKEN=${remote_GITEAACCESSTOKEN}
|
||||||
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
LOCALACCESSTOKEN=${local_GITEAACCESSTOKEN}
|
||||||
@ -49,7 +49,23 @@ REMOTEGITEAHOST=${remote_GITEAHOST}
|
|||||||
CLONEADDRESS=$REMOTEGITEAHOST/$2/$1.git
|
CLONEADDRESS=$REMOTEGITEAHOST/$2/$1.git
|
||||||
LOCALGITEAHOST=${local_GITEAHOST}
|
LOCALGITEAHOST=${local_GITEAHOST}
|
||||||
TARGETORG=${local_USER}
|
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
|
# check that the TARGETORG exists
|
||||||
if [ $DEBUG ] ; then echo "checking if $TARGETORG exists on $LOCALGITEAHOST" ; fi
|
if [ $DEBUG ] ; then echo "checking if $TARGETORG exists on $LOCALGITEAHOST" ; fi
|
||||||
@ -69,30 +85,34 @@ if [ "$RESPONSE" == "200" ] ; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
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' \
|
RESPONSE=$(curl $curlsilent -k -X 'POST' \
|
||||||
"$LOCALGITEAHOST/api/v1/repos/migrate" \
|
"$LOCALGITEAHOST/api/v1/repos/migrate" \
|
||||||
-H 'accept: application/json' \
|
-H 'accept: application/json' \
|
||||||
-H "Authorization: token $LOCALACCESSTOKEN" \
|
-H "Authorization: token $LOCALACCESSTOKEN" \
|
||||||
-H 'Content-Type: application/json' \
|
-H 'Content-Type: application/json' \
|
||||||
-d '{
|
-d "{ $DATA }"
|
||||||
"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
|
|
||||||
}')
|
|
||||||
|
|
||||||
if [ $DEBUG ] ; then echo $? $RESPONSE ; fi
|
if [ $DEBUG ] ; then echo $? $RESPONSE ; fi
|
||||||
|
|
||||||
# And check if this repo is there
|
# And check if this repo is there
|
||||||
@ -100,9 +120,15 @@ if [ $DEBUG ] ; then echo "checking that $TARGETORG/$1 exists" ; fi
|
|||||||
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1)
|
RESPONSE=$(curl $curlsilent -o /dev/null -w "%{http_code}" $LOCALGITEAHOST/$TARGETORG/$1)
|
||||||
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
if [ $DEBUG ] ; then echo "RESPONSE=$RESPONSE" ; fi
|
||||||
if [ "$RESPONSE" == "200" ] ; then
|
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
|
else
|
||||||
echo "migrate-repo was unable to migrate $2/$1 sucessfully"
|
echo "migrate-repo was unable to migrate $2/$1 sucessfully"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user