improve script

main
Andrew Coleman 2021-04-16 13:21:23 -04:00
parent 7670ccf799
commit c81c8ecba2
2 changed files with 16 additions and 18 deletions

View File

@ -1,2 +1,2 @@
export GITEA_ACCESS_TOKEN={{- (bitwardenFields "item" "Gitea").token.value }}
export GITEA_HOST=ssh://git@git.penguincoder.org:2222
export GITEA_HOST=https://git.penguincoder.org

View File

@ -1,6 +1,7 @@
#!/usr/bin/env bash
GITEA_HOST=${GITEA_HOST:-1}
set -x
GITEA_HOST=${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."
@ -11,28 +12,25 @@ 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
OLDIFS=$IFS
IFS=','
set -- "$i"
if [ "$3" == "true" ] ; then
if [ -d "$1" ] ; then
echo "Moving $1 into archived/$1..."
mv "$1" archived/
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/
else
if [ -d "archived/$1" ] ; then
echo "Archived repo $1 already exists, skipping."
if [ -d "archived/${fields[0]}" ] ; then
echo "Archived repo ${fields[0]} already exists, skipping."
else
echo "Cloning archived/$1 from $2"
git clone -q "$2" "archived/$1"
echo "Cloning archived/${fields[0]} from ${fields[1]}"
git clone -q "${fields[1]}" "archived/${fields[0]}"
fi
fi
else
if [ -d "$1" ] ; then
echo "Repo $1 already exists, skipping."
if [ -d "${fields[1]}" ] ; then
echo "Repo ${fields[1]} already exists, skipping."
else
echo "Cloning $1 from $2"
git clone -q "$2"
echo "Cloning ${fields[1]} from ${fields[2]}"
git clone -q "${fields[2]}"
fi
fi
IFS=$OLDIFS
done