add auto_clone script
This commit is contained in:
parent
ef37c540dc
commit
c8f7181aad
45
auto_clone.sh
Normal file
45
auto_clone.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
# repos="$(curl \
|
||||
# -X 'GET' 'https://gitea.finnvanreenen.nl/api/v1/user/repos?token=' \
|
||||
# -H 'accept: application/json'\
|
||||
# )"
|
||||
|
||||
token="b0e7fd2acc222a84e94a81c8de743a8e2a866d80"
|
||||
page=1
|
||||
project_dir="$HOME/projects"
|
||||
|
||||
base_url="https://gitea.finnvanreenen.nl/api/v1"
|
||||
|
||||
while [ "$page" -le 20 ]
|
||||
do
|
||||
echo
|
||||
echo "## get repo list page $page"
|
||||
repos="$(curl -X 'GET' "$base_url/user/repos?page=$page&token=$token" -H 'accept: application/json')"
|
||||
|
||||
if [[ "$repos" != "[]" ]]
|
||||
then
|
||||
for repo in $(echo "$repos" | sed -e 's/^\[{//' -e 's/}]$//' -e 's/},{/\n/g' -e 's/ /%20/g')
|
||||
do
|
||||
full_name="$(echo "$repo" | sed -e 's/^.*"full_name":"\([^"]*\)".*$/\1/' -e 's/%20/ /g')"
|
||||
ssh_url="$(echo "$repo" | sed -e 's/^.*"ssh_url":"\([^"]*\)".*$/\1/' -e 's/%20/ /g')"
|
||||
echo
|
||||
echo "### $full_name"
|
||||
|
||||
if [ -d "$project_dir/$full_name" ]
|
||||
then
|
||||
cd "$project_dir/$full_name"
|
||||
git fetch
|
||||
git status
|
||||
else
|
||||
git clone "$ssh_url" "$project_dir/$full_name"
|
||||
fi
|
||||
|
||||
done
|
||||
else
|
||||
echo "No more repositories found."
|
||||
page=200
|
||||
fi
|
||||
|
||||
page=$(( $page + 1 ))
|
||||
done
|
||||
Loading…
x
Reference in New Issue
Block a user