From c81c8ecba21908a46d1db9c19c40364d7194e014 Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Fri, 16 Apr 2021 13:21:23 -0400 Subject: [PATCH] improve script --- dot_bashrc.d/gitea.sh.tmpl | 2 +- .../bin/executable_clone-all-gitea-repos.sh | 32 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/dot_bashrc.d/gitea.sh.tmpl b/dot_bashrc.d/gitea.sh.tmpl index 1c92ad7..f55ffa1 100644 --- a/dot_bashrc.d/gitea.sh.tmpl +++ b/dot_bashrc.d/gitea.sh.tmpl @@ -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 diff --git a/private_dot_local/bin/executable_clone-all-gitea-repos.sh b/private_dot_local/bin/executable_clone-all-gitea-repos.sh index e696a43..f1dd965 100644 --- a/private_dot_local/bin/executable_clone-all-gitea-repos.sh +++ b/private_dot_local/bin/executable_clone-all-gitea-repos.sh @@ -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