dotfiles/private_dot_local/private_bin/executable_clone-all-gitea-...

36 lines
1.2 KiB
Bash
Raw Normal View History

2021-04-14 16:33:20 -04:00
#!/usr/bin/env bash
2021-04-16 13:21:23 -04:00
GITEA_HOST=${GITEA_HOST:-$1}
2021-04-14 16:33:20 -04:00
if [ -z "$GITEA_HOST" ] || [ -z "$GITEA_ACCESS_TOKEN" ] ; then
echo "Clones all repos that you have access to into the current directory."
echo "You must set \$GITEA_ACCESS_TOKEN to a value from the gitea interface."
echo "Usage: $0 <gitea_host>"
exit 1
fi
mkdir -p archived
for i in $(curl -s --header "Authorization: token $GITEA_ACCESS_TOKEN" "${GITEA_HOST}/api/v1/user/repos?limit=50" | jq -r 'map(.name + "," + .ssh_url + "," + (.archived | tostring)) | flatten[]') ; do
2021-04-16 13:21:23 -04:00
IFS=',' read -ra fields <<< "$i"
if [ "${fields[2]}" == "true" ] ; then
if [ -d "${fields[0]}" ] ; then
echo "Moving ${fields[0]} into archived/${fields[0]}..."
mv "${fields[0]}" archived/
2021-04-14 16:33:20 -04:00
else
2021-04-16 13:21:23 -04:00
if [ -d "archived/${fields[0]}" ] ; then
echo "Archived repo ${fields[0]} already exists, skipping."
2021-04-14 16:33:20 -04:00
else
2021-04-16 13:21:23 -04:00
echo "Cloning archived/${fields[0]} from ${fields[1]}"
git clone -q "${fields[1]}" "archived/${fields[0]}"
2021-04-14 16:33:20 -04:00
fi
fi
else
2021-04-16 13:23:52 -04:00
if [ -d "${fields[0]}" ] ; then
echo "Repo ${fields[0]} already exists, skipping."
2021-04-14 16:33:20 -04:00
else
2021-04-16 13:23:52 -04:00
echo "Cloning ${fields[0]} from ${fields[1]}"
git clone -q "${fields[1]}"
2021-04-14 16:33:20 -04:00
fi
fi
done