Created
February 4, 2015 20:07
-
-
Save fbatroni/2b8128f0081dbaaef84b to your computer and use it in GitHub Desktop.
Shell script that pulls down and clones all available repos for an organization - can be used as a "backup" utility
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#Shell script that pulls down and clones all available repos for an organization - can be used as a "backup" utility | |
#Pre-reqs = jsawk https://github.com/micha/jsawk | |
#don't forget to export out your username and password as variables or maybe add a couple of parameters to accept them as input args | |
#export GITHUB_USERNAME=my_github_username | |
#export GITHUB_PASSWORD=my_github_password | |
echo "getting list of available repos" | |
PAGE_NUMBER=1 | |
ORG=$1 | |
DESTINATION_DIR=$2 || "/d/local/dev" | |
for (( ; ; )) | |
do | |
has_repos=`curl "https://${GITHUB_USERNAME}:${GITHUB_PASSWORD}@api.github.com/orgs/${ORG}/repos?page=${PAGE_NUMBER}&per_page=100" | jsawk 'return this.html_url' ` | |
if [ "$has_repos" != "[]" ] ; then #check for an "empty" array | |
repos=$(echo $has_repos | sed 's/\[//g' | sed 's/\]//g' | sed 's/\"//g' ) | |
repos=$(echo $repos | tr "," "\n") | |
for repo in $repos | |
do | |
echo $repo > "${DESTINATION_DIR}/repo_page_${PAGE_NUMBER}.txt" | |
done | |
cat "${DESTINATION_DIR}/repo_page_${PAGE_NUMBER}.txt" | while read LINE | |
do | |
repo_destination=$(echo $LINE | sed -e 's/https\:\/\/github.com\/${ORG}\///g' ) | |
echo "cloning into: ${repo_destination}" | |
git clone $LINE "${DESTINATION_DIR}/${repo_destination}" | |
done | |
echo "page: $((PAGE_NUMBER++))" | |
else | |
break; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment