Compare commits
9 Commits
f813ae279f
...
master
Author | SHA1 | Date | |
---|---|---|---|
13fbaf6cc2
|
|||
07ad60f40d
|
|||
44f2233c25
|
|||
d572c90470 | |||
4ee6612388 | |||
363d4cbf20 | |||
6d2fa1d87b | |||
8649480230 | |||
67581dd30c |
41
sync.sh
41
sync.sh
@@ -6,11 +6,13 @@ GITEA_TOKEN=${GITEA_TOKEN:?is not set}
|
|||||||
GITHUB_TOKEN=${GITHUB_TOKEN:?is not set}
|
GITHUB_TOKEN=${GITHUB_TOKEN:?is not set}
|
||||||
BITBUCKET_TOKEN=${BITBUCKET_TOKEN:?is not set}
|
BITBUCKET_TOKEN=${BITBUCKET_TOKEN:?is not set}
|
||||||
GITLAB_TOKEN=${GITLAB_TOKEN:?is not set}
|
GITLAB_TOKEN=${GITLAB_TOKEN:?is not set}
|
||||||
|
CODEBERG_TOKEN=${CODEBERG_TOKEN:?is not set}
|
||||||
|
|
||||||
GITEA_BASE="https://averagemarcus:${GITEA_TOKEN}@git.cluster.fun/AverageMarcus/"
|
GITEA_BASE="https://averagemarcus:${GITEA_TOKEN}@git.cluster.fun/AverageMarcus/"
|
||||||
GITHUB_BASE="https://averagemarcus:${GITHUB_TOKEN}@github.com/AverageMarcus/"
|
GITHUB_BASE="https://averagemarcus:${GITHUB_TOKEN}@github.com/AverageMarcus/"
|
||||||
BITBUCKET_BASE="https://averagemarcus:${BITBUCKET_TOKEN}@bitbucket.org/AverageMarcus/"
|
BITBUCKET_BASE="https://averagemarcus:${BITBUCKET_TOKEN}@bitbucket.org/AverageMarcus/"
|
||||||
GITLAB_BASE="https://averagemarcus:${GITLAB_TOKEN}@gitlab.com/AverageMarcus/"
|
GITLAB_BASE="https://averagemarcus:${GITLAB_TOKEN}@gitlab.com/AverageMarcus/"
|
||||||
|
CODEBERG_BASE="https://averagemarcus:${CODEBERG_TOKEN}@codeberg.org/AverageMarcus/"
|
||||||
|
|
||||||
REPOS=$(curl -X GET "https://git.cluster.fun/api/v1/user/repos?page=1&limit=50&access_token=${GITEA_TOKEN}" -H "accept: application/json" --silent | jq -r '.[] | select(.private!=true) | .name')
|
REPOS=$(curl -X GET "https://git.cluster.fun/api/v1/user/repos?page=1&limit=50&access_token=${GITEA_TOKEN}" -H "accept: application/json" --silent | jq -r '.[] | select(.private!=true) | .name')
|
||||||
|
|
||||||
@@ -40,15 +42,29 @@ gitlabGetRepo() {
|
|||||||
gitlabMakeRepo() {
|
gitlabMakeRepo() {
|
||||||
echo "Creating gitlab repo"
|
echo "Creating gitlab repo"
|
||||||
curl -X POST --header "Content-Type: application/json" "https://gitlab.com/api/v4/projects?private_token=${GITLAB_TOKEN}" -d '{"name": "'${1}'", "visibility": "public"}' --silent 1> /dev/null
|
curl -X POST --header "Content-Type: application/json" "https://gitlab.com/api/v4/projects?private_token=${GITLAB_TOKEN}" -d '{"name": "'${1}'", "visibility": "public"}' --silent 1> /dev/null
|
||||||
|
|
||||||
|
PROJECT_ID=$(curl --header "PRIVATE-TOKEN: $GITLAB_TOKEN" "https://gitlab.com/api/v4/projects/averagemarcus%2F${1}" | jq .id -r)
|
||||||
|
curl --request POST --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" "https://gitlab.com/api/v4/projects/${PROJECT_ID}/protected_branches?name=master&push_access_level=40&merge_access_level=40&allow_force_push=true"
|
||||||
|
curl --request POST --header "PRIVATE-TOKEN: ${GITLAB_TOKEN}" --header "Content-Type: application/json" "https://gitlab.com/api/v4/projects/${PROJECT_ID}/protected_branches?name=main&push_access_level=40&merge_access_level=40&allow_force_push=true"
|
||||||
|
}
|
||||||
|
|
||||||
|
codebergGetRepo() {
|
||||||
|
curl -f -X GET "https://codeberg.org/api/v1/repos/averagemarcus/${1}?access_token=${CODEBERG_TOKEN}" -H 'accept: application/json' --silent 1> /dev/null
|
||||||
|
}
|
||||||
|
codebergMakeRepo() {
|
||||||
|
echo "Creating codeberg repo"
|
||||||
|
curl -X POST "https://codeberg.org/api/v1/user/repos?access_token=${CODEBERG_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" -H 'accept: application/json' \
|
||||||
|
-d '{"auto_init": false, "private": false, "name": "'${1}'"}' --silent 1> /dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
for REPO in ${REPOS}; do
|
for REPO in ${REPOS}; do
|
||||||
printf "\nSyncing ${REPO}"
|
printf "\n🔄 Syncing ${REPO}\n\n"
|
||||||
|
|
||||||
rm -rf ${REPO}
|
rm -rf ${REPO}
|
||||||
mkdir -p ${REPO}
|
|
||||||
|
git clone "${GITEA_BASE}${REPO}" ${REPO}
|
||||||
cd ${REPO}
|
cd ${REPO}
|
||||||
git init 1> /dev/null
|
|
||||||
|
|
||||||
BRANCH=$(getDefaultBranch ${REPO})
|
BRANCH=$(getDefaultBranch ${REPO})
|
||||||
|
|
||||||
@@ -56,28 +72,31 @@ for REPO in ${REPOS}; do
|
|||||||
git remote add github "${GITHUB_BASE}${REPO}" 1> /dev/null
|
git remote add github "${GITHUB_BASE}${REPO}" 1> /dev/null
|
||||||
git remote add bitbucket "${BITBUCKET_BASE}${REPO}" 1> /dev/null
|
git remote add bitbucket "${BITBUCKET_BASE}${REPO}" 1> /dev/null
|
||||||
git remote add gitlab "${GITLAB_BASE}$(echo ${REPO} |tr "." "-")" 1> /dev/null
|
git remote add gitlab "${GITLAB_BASE}$(echo ${REPO} |tr "." "-")" 1> /dev/null
|
||||||
|
# git remote add codeberg "${CODEBERG_BASE}${REPO}" 1> /dev/null
|
||||||
|
|
||||||
failed() {
|
failed() {
|
||||||
printf "\n⚠️ Failed to sync ${REPO}\n\n"
|
printf "\n⚠️ Failed to sync ${REPO} to ${1}\n\n"
|
||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
FAILED_MESSAGE="${FAILED_MESSAGE}\n⚠️ Failed to sync ${REPO}\n\n"
|
FAILED_MESSAGE="${FAILED_MESSAGE}\n⚠️ Failed to sync ${REPO} to ${1}\n\n"
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
githubGetRepo ${REPO} || githubMakeRepo ${REPO}
|
githubGetRepo ${REPO} || githubMakeRepo ${REPO}
|
||||||
gitlabGetRepo ${REPO} || gitlabMakeRepo ${REPO}
|
gitlabGetRepo ${REPO} || gitlabMakeRepo ${REPO}
|
||||||
bitbucketGetRepo ${REPO} || bitbucketMakeRepo ${REPO}
|
bitbucketGetRepo ${REPO} || bitbucketMakeRepo ${REPO}
|
||||||
|
# codebergGetRepo ${REPO} || codebergMakeRepo ${REPO}
|
||||||
|
|
||||||
git pull --ff-only gitea ${BRANCH} 1> /dev/null || failed
|
git pull --ff-only gitea ${BRANCH} 1> /dev/null || { failed; continue; }
|
||||||
git pull --ff-only github ${BRANCH} 1> /dev/null || printf "\nℹ️ Unable to pull from GitHub\n\n"
|
git pull --ff-only github ${BRANCH} 1> /dev/null || printf "\nℹ️ Unable to pull from GitHub\n\n"
|
||||||
git pull --ff-only bitbucket ${BRANCH} 1> /dev/null || printf "\nℹ️ Unable to pull from BitBucket\n\n"
|
git pull --ff-only bitbucket ${BRANCH} 1> /dev/null || printf "\nℹ️ Unable to pull from BitBucket\n\n"
|
||||||
git pull --ff-only gitlab ${BRANCH} 1> /dev/null || printf "\nℹ️ Unable to pull from Gitlab\n\n"
|
git pull --ff-only gitlab ${BRANCH} 1> /dev/null || printf "\nℹ️ Unable to pull from Gitlab\n\n"
|
||||||
|
# git pull --ff-only codeberg ${BRANCH} 1> /dev/null || printf "\nℹ️ Unable to pull from Codeberg\n\n"
|
||||||
|
|
||||||
git push gitea ${BRANCH} 1> /dev/null || failed
|
git push -f --set-upstream github ${BRANCH} 1> /dev/null || { failed "github"; }
|
||||||
git push github ${BRANCH} 1> /dev/null || failed
|
git push -f --set-upstream bitbucket ${BRANCH} 1> /dev/null || { failed "bitbucket"; }
|
||||||
git push bitbucket ${BRANCH} 1> /dev/null || failed
|
git push -f --set-upstream gitlab ${BRANCH} 1> /dev/null || { failed "gitlab"; }
|
||||||
git push gitlab ${BRANCH} 1> /dev/null || failed
|
# git push -f --set-upstream codeberg ${BRANCH} 1> /dev/null || { failed "codeberg"; }
|
||||||
|
git push --set-upstream gitea ${BRANCH} 1> /dev/null || { failed "gitea"; }
|
||||||
|
|
||||||
cd ..
|
cd ..
|
||||||
rm -rf ${REPO}
|
rm -rf ${REPO}
|
||||||
|
Reference in New Issue
Block a user