From 4ec9ee15aa9234893b915127527de1134df56e6c Mon Sep 17 00:00:00 2001 From: nomad Date: Mon, 31 Mar 2025 13:43:40 +0300 Subject: [PATCH] init --- syncRepos.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 syncRepos.sh diff --git a/syncRepos.sh b/syncRepos.sh new file mode 100755 index 0000000..5840818 --- /dev/null +++ b/syncRepos.sh @@ -0,0 +1,42 @@ +#!/usr/bin/env bash + +# CONFIGURATION +GITHUB_USER="nomadics9" +FORGEJO_USER="nomad" +FORGEJO_URL="git@git.askar.tv" +FORGEJO_API="https://git.askar.tv/api/v1" +FORGEJO_TOKEN="TOKEN" +TMP_DIR="github-to-forgejo" + +mkdir -p "$TMP_DIR" +cd "$TMP_DIR" || exit 1 + +# 🧠 Fetch public GitHub repos via API +repos=$(curl -s "https://api.github.com/users/$GITHUB_USER/repos?per_page=1000" | + jq -r '.[] | "\(.name) false"') # Always false = public + +# 📦 Select repos +selected=$(echo "$repos" | fzf --multi --prompt="Select repos to sync: ") +[ -z "$selected" ] && echo "No repos selected. Exiting." && exit 1 + +# 🔁 Clone & Push +while read -r line; do + name=$(echo "$line" | awk '{print $1}') + echo "==> Syncing $name..." + + # Clone from GitHub + git clone --mirror "https://github.com/$GITHUB_USER/$name.git" + cd "$name.git" || continue + + # Create on Forgejo + curl -s -X POST "$FORGEJO_API/user/repos" \ + -H "Authorization: token $FORGEJO_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"name\":\"$name\",\"private\":false,\"auto_init\":false}" + + # Push to Forgejo + git remote add forgejo "$FORGEJO_URL:$FORGEJO_USER/$name.git" + git push --mirror forgejo + + cd .. +done <<< "$selected"