This repository has been archived on 2021-04-14. You can view files and clone it, but cannot push or open issues/pull-requests.
2020-05-26 12:55:20 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
GITEA_HOST=$1
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2020-05-27 11:44:27 -04:00
|
|
|
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
|
2020-05-26 12:55:20 -04:00
|
|
|
OLDIFS=$IFS
|
|
|
|
IFS=','
|
|
|
|
set -- $i
|
2020-05-27 11:44:27 -04:00
|
|
|
if [ "$3" == "true" ] ; then
|
|
|
|
if [ -d $1 ] ; then
|
|
|
|
echo "Moving $1 into archived/$1..."
|
|
|
|
mv $1 archived/
|
|
|
|
else
|
|
|
|
if [ -d "archived/$1" ] ; then
|
|
|
|
echo "Archived repo $1 already exists, skipping."
|
|
|
|
else
|
|
|
|
echo "Cloning archived/$1 from $2"
|
|
|
|
git clone -q $2 archived/$1
|
|
|
|
fi
|
|
|
|
fi
|
2020-05-26 12:55:20 -04:00
|
|
|
else
|
2020-05-27 11:44:27 -04:00
|
|
|
if [ -d $1 ] ; then
|
|
|
|
echo "Repo $1 already exists, skipping."
|
|
|
|
else
|
|
|
|
echo "Cloning $1 from $2"
|
|
|
|
git clone -q $2
|
|
|
|
fi
|
2020-05-26 12:55:20 -04:00
|
|
|
fi
|
|
|
|
IFS=$OLDIFS
|
|
|
|
done
|