move from stow to chezmoi
This commit is contained in:
44
private_dot_local/bin/executable_auto_clone
Executable file
44
private_dot_local/bin/executable_auto_clone
Executable file
@@ -0,0 +1,44 @@
|
||||
#!/bin/bash
|
||||
|
||||
token="$1"
|
||||
page=1
|
||||
project_dir="$HOME/projects"
|
||||
|
||||
base_url="https://gitea.finnvanreenen.nl/api/v1"
|
||||
git_url="git@gitea.finnvanreenen.nl"
|
||||
|
||||
while [[ $page -lt 50 ]]
|
||||
do
|
||||
# echo
|
||||
echo "## get repo list page $page"
|
||||
repos="$(curl -X 'GET' "$base_url/user/repos?page=$page&token=$token" -H 'accept: application/json')"
|
||||
login="$(echo "$repos" | sed -e 's/^.*"login":"\([^"]*\)".*$/\1/')"
|
||||
|
||||
if [[ "$repos" != "[]" ]]
|
||||
then
|
||||
for repo in $(echo "$repos" | sed -e 's/^\[{//' -e 's/}]$//' -e 's/},{/\n/g' -e 's/%/%p/g' -e 's/ /%20/g')
|
||||
do
|
||||
repo_json="$(echo "$repo" | sed -e 's/%20/ /g' -e 's/%p/%/g')"
|
||||
full_name="$(echo "$repo_json" | sed -e 's/^.*"full_name":"\([^"]*\)".*$/\1/')"
|
||||
clone_url="$(echo "$repo_json" | sed -e 's/^.*"clone_url":"\([^"]*\)".*$/\1/')"
|
||||
echo
|
||||
echo "### ${full_name,,}"
|
||||
|
||||
if [ -d "$project_dir/${full_name,,}" ]
|
||||
then
|
||||
cd "$project_dir/${full_name,,}"
|
||||
# git fetch
|
||||
else
|
||||
url="$(echo "$clone_url" | sed "s|://|://$login:$token@|")"
|
||||
git clone "$url" "$project_dir/${full_name,,}"
|
||||
git -C "$project_dir/${full_name,,}" remote set-url origin "$git_url:${full_name,,}.git"
|
||||
fi
|
||||
|
||||
done
|
||||
else
|
||||
echo "No more repositories found."
|
||||
page=999
|
||||
fi
|
||||
|
||||
page="$(( $page + 1 ))"
|
||||
done
|
||||
Reference in New Issue
Block a user