-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-repos-parallel.sh
More file actions
executable file
·35 lines (28 loc) · 839 Bytes
/
sync-repos-parallel.sh
File metadata and controls
executable file
·35 lines (28 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
REPO_DIR="${HOME}/repos"
mkdir -p "$REPO_DIR"
echo "Fetching repo list..."
gh repo list --limit 500 --json name,sshUrl --jq '.[] | .name + "|" + .sshUrl' > "$HYPATIA_TMPDIR/repos.txt"
TOTAL=$(wc -l < "$HYPATIA_TMPDIR/repos.txt")
echo "Found $TOTAL repos"
sync_repo() {
local line="$1"
local name="${line%%|*}"
local url="${line##*|}"
local target="${REPO_DIR}/${name}"
if [[ -d "$target/.git" ]]; then
echo "[OK] $name (exists)"
else
if git clone --depth 1 -q "$url" "$target" 2>/dev/null; then
echo "[OK] $name (cloned)"
else
echo "[FAIL] $name"
fi
fi
}
export -f sync_repo
export REPO_DIR
cat "$HYPATIA_TMPDIR/repos.txt" | xargs -P 8 -I {} bash -c 'sync_repo "$@"' _ {}
echo ""
echo "Done! Repos in $REPO_DIR:"
ls "$REPO_DIR" | wc -l