Created
December 24, 2021 13:28
-
-
Save lexisother/caafcd6054e50f9f6c529af51404a3bd to your computer and use it in GitHub Desktop.
Simple script to mirror sourcehut repos from @Cr3atable's sourcehut account to the @Cumcord org.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -euo pipefail | |
BASE_DIR="$(dirname "$(readlink -f "$0")")" | |
MIRROR_DIR="$BASE_DIR/clone" | |
command_exists() { command -v "$1" &>/dev/null } | |
pprint() { | |
print -r -- "$(print -P '%F{8}==>%f') $1" | |
} | |
if ! command_exists jq; then | |
pprint "jq isn't installed!" | |
exit 1 | |
fi | |
for user repo owner in $(jq -r 'to_entries[] | .key as $k | .value | to_entries[] | $k, .key, .value' $BASE_DIR/repos.json); do | |
if [ -d "$MIRROR_DIR/$user/$repo" ]; then | |
pprint "$repo exists." | |
else | |
pprint "$repo doesn't exist." | |
git clone "https://git.sr.ht/~$user/$repo" "$MIRROR_DIR/$user/$repo" | |
fi | |
cd "$MIRROR_DIR/$user/$repo" | |
REMOTE_COUNT=$(git remote | wc -l) | |
if (( REMOTE_COUNT > 1 )); then | |
git pull origin master; | |
git pull github master; | |
else | |
if [[ "$owner" == "creatable" ]]; then | |
git remote add github "git-a:Cumcord/$repo" | |
git push -u github master; | |
elif [[ "$owner" == "lexisother" ]]; then | |
git remote add github "git-a:lexisother/$repo" | |
git push -u github master; | |
else | |
echo "Non standard user, skipping." | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment