From 2dccaf86a05cd2b9790b6f5f4d3c3fa040d8f889 Mon Sep 17 00:00:00 2001 From: "Peter J. Milanese" Date: Sun, 27 Jan 2019 16:29:01 -0500 Subject: [PATCH] Quick cleanup --- .github2synology.sh.un~ | Bin 0 -> 3603 bytes github2synology.sh | 5 ---- github2synology.sh~ | 61 ++++++++++++++++++++++++++++++++++++++++ private | 0 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 .github2synology.sh.un~ create mode 100644 github2synology.sh~ create mode 100644 private diff --git a/.github2synology.sh.un~ b/.github2synology.sh.un~ new file mode 100644 index 0000000000000000000000000000000000000000..a560f29e964d829eba77939f2fdd4569cd3cb322 GIT binary patch literal 3603 zcmeH~JxBvV5QTS>Q*-`DEd&cwYAva9MiE=nNE9KELW~MI1HsNJy^YukwjwrmVkz2* zq!XjSs?Vqi5E-%qXEesnlE8J6;JE$J zn4Hm^z@^`)0n8vUWlmt+30sjky(Kw~(aXM%EG00IW7)-zHdAsyH((SBtP|wp$T^hg zf=#1gFm0mD(#tSGVw}V=maXj^ZtqoV%|=*m*5~GPN0jW*1f?l*HF;8$zQWGwBBl7d v3aC7bA`RdUGCJ`uMvyZm*8Alb;;L=K literal 0 HcmV?d00001 diff --git a/github2synology.sh b/github2synology.sh index fdb6016..6fb3a40 100644 --- a/github2synology.sh +++ b/github2synology.sh @@ -8,13 +8,11 @@ OAUTH_TOKEN="[PUT YOUR TOKEN HERE BETWEEN THE QUOTES]" # where should the files be saved BACKUP_PATH="/volume1/serverBackups/github/backup" - # you shouldn't need to change anything below here - unless you have over 100 repos: in which case, see the bottom. COUNTER=100 TOTALCOUNTER=0 PAGE=1 GIT="c//volume1/@appstore/git/bin/git" - fetch_fromUrl() { COUNTER=0 API_URL="https://api.github.com/user/repos?type=all&per_page=100&page=${PAGE}" @@ -31,8 +29,6 @@ fetch_fromUrl() { GITURL="${ORIGINALGITURL/git:\/\/github.com\//git@github.com:}" mkdir "${BACKUP_PATH}/${REPONAME}" -p REPOPATH="${BACKUP_PATH}/${REPONAME}/code" - - if [ -d "$REPOPATH" ]; then echo "PULLING Repo URL: ${REPONAME} from url ${GITURL} to ${REPOPATH}" cd ${REPOPATH} @@ -58,7 +54,6 @@ fetch_fromUrl() { fi fi done - } until [ $COUNTER -lt 100 ]; do fetch_fromUrl diff --git a/github2synology.sh~ b/github2synology.sh~ new file mode 100644 index 0000000..b921272 --- /dev/null +++ b/github2synology.sh~ @@ -0,0 +1,61 @@ +#!/bin/sh +# A script to backup Github repositories to a Synology. +# By Richard Bairwell. http://www.bairwell.com +# MIT Licenced. https://github.com/bairwell/github2synology + +# token from https://github.com/settings/tokens +OAUTH_TOKEN="[PUT YOUR TOKEN HERE BETWEEN THE QUOTES]" +# where should the files be saved +BACKUP_PATH="/volume1/serverBackups/github/backup" + + +# you shouldn't need to change anything below here - unless you have over 100 repos: in which case, see the bottom. + +API_URL="https://api.github.com/user/repos?type=all&per_page=100" +GIT="/volume1/@appstore/git/bin/git" + +fetch_fromUrl() { + echo "Fetching from ${API_URL}" + REPOS=`curl -H "Authorization: token ${OAUTH_TOKEN}" -s "${API_URL}" | jq -r 'values[] | "\(.full_name),\(.private),\(.git_url),\(.has_wiki)"'` + for REPO in $REPOS + do + REPONAME=`echo ${REPO} | cut -d ',' -f1` + PRIVATEFLAG=`echo ${REPO} | cut -d ',' -f2` + ORIGINALGITURL=`echo ${REPO} | cut -d ',' -f3` + HASWIKI=`echo ${REPO} | cut -d ',' -f4` + GITURL="${ORIGINALGITURL/git:\/\/github.com\//git@github.com:}" + mkdir "${BACKUP_PATH}/${REPONAME}" -p + REPOPATH="${BACKUP_PATH}/${REPONAME}/code" + + + if [ -d "$REPOPATH" ]; then + echo "PULLING Repo URL: ${REPONAME} from url ${GITURL} to ${REPOPATH}" + cd ${REPOPATH} + ${GIT} pull + else + echo "CLONING Repo URL: ${REPONAME} from url ${GITURL} to ${REPOPATH}" + ${GIT} clone ${GITURL} ${REPOPATH} + if [ "true"===${PRIVATEFLAG} ]; then + `touch ${BACKUP_PATH}/${REPONAME}/private` + fi + fi + if [ "true"===${HASWIKI} ]; then + WIKIPATH="${BACKUP_PATH}/${REPONAME}/wiki" + WIKIURL="${ORIGINALGITURL/git:\/\/github.com\//git@github.com:}" + WIKIURL=`echo ${WIKIURL} | sed -e "s/.git$/.wiki.git/"` + if [ -d "$WIKIPATH" ]; then + echo "PULLING Repo Wiki: ${REPONAME} from url ${WIKIURL}: to ${WIKIPATH}" + cd ${WIKIPATH} + ${GIT} pull + else + echo "CLONING Repo Wiki: ${REPONAME} from url ${WIKIURL}:to ${WIKIPATH}" + ${GIT} clone ${WIKIURL} ${WIKIPATH} + fi + fi + done + +} +fetch_fromUrl +# If you need additional urls adding, put them here. +#API_URL="https://api.github.com/user/repos?type=all&per_page=100&page=2" +#fetch_fromUrl \ No newline at end of file diff --git a/private b/private new file mode 100644 index 0000000..e69de29