update some scripts
This commit is contained in:
@@ -5,35 +5,54 @@ page=1
|
||||
project_dir="$HOME/projects"
|
||||
|
||||
base_url="https://gitea.finnvanreenen.nl/api/v1"
|
||||
git_url="git@gitea.finnvanreenen.nl"
|
||||
|
||||
function process_repo() {
|
||||
json="$1"
|
||||
|
||||
checkout="$project_dir"
|
||||
|
||||
if [[ "$(echo "$json" | jq -r '.name')" == 'dotfiles' ]]; then
|
||||
return # do not clone dotfiles
|
||||
fi
|
||||
|
||||
full_name="$(echo "$json" | jq -r '.full_name')"
|
||||
clone_url="$(echo "$json" | jq -r '.clone_url')"
|
||||
ssh_url="$(echo "$json" | jq -r '.ssh_url')"
|
||||
|
||||
echo "$full_name"
|
||||
|
||||
if [[ "$(echo "$json" | jq -r '.archived')" == 'true' ]]; then
|
||||
echo " archived"
|
||||
checkout="$checkout/archive"
|
||||
elif [[ "$(echo "$json" | jq -r '.template')" == 'true' ]]; then
|
||||
echo " template"
|
||||
checkout="$checkout/templates"
|
||||
fi
|
||||
|
||||
if [ -d "$checkout/$full_name" ]
|
||||
then
|
||||
echo " already exists"
|
||||
else
|
||||
echo " clone to $checkout/$full_name"
|
||||
url="$(echo "$clone_url" | sed "s|://|://$token@|")"
|
||||
git clone "$clone_url" "$project_dir/$full_name"
|
||||
git -C "$project_dir/$full_name" remote set-url origin "$ssh_url"
|
||||
fi
|
||||
}
|
||||
|
||||
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/')"
|
||||
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/%/%p/g' -e 's/ /%20/g')
|
||||
for repo in $(echo "$repos" | jq -c '.[]' | sed -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
|
||||
|
||||
repo="$( echo "$repo" | sed -e 's/%20;/ /g' )"
|
||||
process_repo "$repo"
|
||||
done
|
||||
else
|
||||
echo "No more repositories found."
|
||||
|
||||
Reference in New Issue
Block a user