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_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 #!/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 if [ -z "$GITEA_HOST" ] || [ -z "$GITEA_ACCESS_TOKEN" ] ; then
echo "Clones all repos that you have access to into the current directory." echo "Clones all repos that you have access to into the current directory."
@ -11,28 +12,25 @@ fi
mkdir -p archived 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 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=',' read -ra fields <<< "$i"
IFS=',' if [ "${fields[2]}" == "true" ] ; then
set -- "$i" if [ -d "${fields[0]}" ] ; then
if [ "$3" == "true" ] ; then echo "Moving ${fields[0]} into archived/${fields[0]}..."
if [ -d "$1" ] ; then mv "${fields[0]}" archived/
echo "Moving $1 into archived/$1..."
mv "$1" archived/
else else
if [ -d "archived/$1" ] ; then if [ -d "archived/${fields[0]}" ] ; then
echo "Archived repo $1 already exists, skipping." echo "Archived repo ${fields[0]} already exists, skipping."
else else
echo "Cloning archived/$1 from $2" echo "Cloning archived/${fields[0]} from ${fields[1]}"
git clone -q "$2" "archived/$1" git clone -q "${fields[1]}" "archived/${fields[0]}"
fi fi
fi fi
else else
if [ -d "$1" ] ; then if [ -d "${fields[1]}" ] ; then
echo "Repo $1 already exists, skipping." echo "Repo ${fields[1]} already exists, skipping."
else else
echo "Cloning $1 from $2" echo "Cloning ${fields[1]} from ${fields[2]}"
git clone -q "$2" git clone -q "${fields[2]}"
fi fi
fi fi
IFS=$OLDIFS
done done