Update repo_sync.sh

This commit is contained in:
2025-01-06 18:54:32 +03:00
committed by GitHub
parent 1fc7561dea
commit c94e7b7961
+11 -25
View File
@@ -1,45 +1,31 @@
#!/bin/bash
GITHUB_USERNAME="andwati"
DESTINATION_FOLDER=~/cloned
clone_repositories() {
local parent_dir=$1
local url=$2
local repo_name=$2
# Extract the repository name from the URL
local repo_name=$(basename "${url%.git}")
gh repo clone "$GITHUB_USERNAME/$repo_name" "$parent_dir/$repo_name"
# Clone the repository into the specified folder
git clone "$url" "$parent_dir/$repo_name"
# Move into the cloned repository folder
cd "$parent_dir/$repo_name" || exit
# If there are submodules, initialize and update them
if [ -f ".gitmodules" ]; then
git submodule init
git submodule update
fi
# Recursively clone submodules if any
if [ -f ".gitmodules" ]; then
git submodule foreach --recursive "$0" "$parent_dir/$repo_name"
fi
# Move back to the parent folder
cd "$parent_dir" || exit
}
repositories=$(curl -s "https://api.github.com/users/$GITHUB_USERNAME/repos?per_page=100" | grep -o 'git@[^"]*')
main() {
mkdir -p "$DESTINATION_FOLDER"
mkdir -p $DESTINATION_FOLDER
repos=$(gh repo list "$GITHUB_USERNAME" --visibility all --limit 100 --json name -q '.[].name')
for repo in $repos; do
echo "Cloning repository: $repo"
clone_repositories "$DESTINATION_FOLDER" "$repo"
done
}
cd "$DESTINATION_FOLDER" || exit
for repository in $repositories; do
clone_repositories "$DESTINATION_FOLDER" "$repository"
done
main