From 37aa4e3899a47d0fed504dd61120822485ce29c0 Mon Sep 17 00:00:00 2001 From: Mason Payne Date: Mon, 24 Jul 2023 01:57:30 -0600 Subject: [PATCH] add scripts for some restoring --- git-restore.sh | 34 ++++++++++++++++++++++++++++++++++ gitea-api.sh | 5 +++++ 2 files changed, 39 insertions(+) create mode 100644 git-restore.sh create mode 100644 gitea-api.sh diff --git a/git-restore.sh b/git-restore.sh new file mode 100644 index 0000000..954230f --- /dev/null +++ b/git-restore.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# replace these with your own +GITEA_API_KEY=***API_token*** +GITEA_API_ENDPOINT=https://git.sa.vin/api/v1 +REPO_DIR=/home/mason/Desktop/gitea-repositories/masonite-studios #replace it with your old repo path +SSH_REPO=ssh://git@git.sa.vin:2222 +USER=masonite-studios + +for dir in $REPO_DIR/*.git; do + if [ -d "$dir" ]; then + # naming the repo + REPO=$(basename $dir .git) + + # create repo in Gitea + #curl -H "content-type: application/json" -H "Authorization: token $GITEA_API_KEY" -X POST -d '{"Name":"'$REPO'","private":true}' $GITEA_API_ENDPOINT/user/repos + curl -H "content-type: application/json" -H "Authorization: token $GITEA_API_KEY" -X POST -d '{"Name":"'$REPO'","private":true}' $GITEA_API_ENDPOINT/orgs/$USER/repos + + echo "Created $REPO in Gitea." + + # change directory to old repo + cd $dir + + # set new origin + git remote add origin $SSH_REPO/$USER/$REPO.git + git remote set-url origin $SSH_REPO/$USER/$REPO.git + + # push all from old repo to Gitea + git push --all origin + + # change back to home directory + cd ../ + fi +done diff --git a/gitea-api.sh b/gitea-api.sh new file mode 100644 index 0000000..76c66d2 --- /dev/null +++ b/gitea-api.sh @@ -0,0 +1,5 @@ +# Create a token +curl -X POST -H "Content-Type: application/json" -d '{"name":"test", "scopes": ["write:user","write:repository","write:organization"]}' -u payne8:***password*** https://git.sa.vin/api/v1/users/payne8/tokens + +# Delete a token +curl -X DELETE -H "Content-Type: application/json" -u payne8:***password*** https://git.sa.vin/api/v1/users/payne8/tokens/test