mirror of
https://github.com/andwati/dotfiles.git
synced 2026-10-18 02:52:52 +00:00
Update repo_sync.sh
This commit is contained in:
+11
-25
@@ -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')
|
||||
|
||||
|
||||
cd "$DESTINATION_FOLDER" || exit
|
||||
|
||||
for repository in $repositories; do
|
||||
clone_repositories "$DESTINATION_FOLDER" "$repository"
|
||||
for repo in $repos; do
|
||||
echo "Cloning repository: $repo"
|
||||
clone_repositories "$DESTINATION_FOLDER" "$repo"
|
||||
done
|
||||
}
|
||||
|
||||
main
|
||||
|
||||
Reference in New Issue
Block a user