Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 86 lines (74 sloc) 2.3 KB
#!/bin/bash
# Download all repositories of a User or Org from Github
# Written by Jared Williams <thisis@jared.nyc>
#
#
# If you have any questions or comments, heres the ways to reach me:
# email: thisis@jared.nyc
# slack: https://devopschat.co signing up is free and my username is @jaredwilliams
# github: @jaredmichaelwilliams
# reddit: jaredw
#
#
STARTPATH=`pwd`
read -p "Github Username: " uname
unset githubpass;
echo "Enter Github Password: "
while IFS= read -r -s -n1 pass; do
if [[ -z $pass ]]; then
echo
break
else
echo -n '*'
githubpass+=$pass
fi
done
defaultpath="/git/"
read -p "Where do you want to clone the repositories? [ $defaultpath ]" path
path=${path:-$defaultpath}
read -p "Downloading from User or Organization? U for User, O for Organizaion" -n 1 -r
if [[ $REPLY =~ ^[Uu]$ ]]; then
usertype="users";
elif [[ $REPLY =~ ^[Oo]$ ]]; then
usertype="orgs";
else
echo "You didnt specify User or Org. exiting"
exit 1;
fi
echo -e "\n\n"
read -p "Which Github User or Organization name in which to download all repositories ?" gitOrg
if [ ${#gitOrg} -lt 2 ]; then
echo "Didnt enter a long enough Github User or Organization name."
exit 1;
fi
if [ ! -d $path ]; then
read -p "$path doesnt exist. Would you like to make it? (uses sudo, be prepared to enter computer user password) [Y/n]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo mkdir -vp $path;
sudo chown -R `whoami`:`id -gn` $path;
sudo chmod -R 755 $path;
else
exit 1;
fi
fi
read -p "Do you have an OTP key? y/n " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
read -p "Enter it now: " -n 7 -r otpKey
if [ ${#otpKey} -lt 6 ]; then
echo "One Time Password not long enough."
exit 1;
fi
fi
REPOCOUNT=`curl -u "$uname:$githubpass" -H "X-GitHub-OTP: $otpKey" -s "https://api.github.com/$usertype/$gitOrg/repos?per_page=200" | grep -c ssh_url`
read -p "You are about to download $REPOCOUNT repositories. Continue? [Y/n]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
cd $path
curl -u "$uname:$githubpass" -H "X-GitHub-OTP: $otpKey" -s "https://api.github.com/$usertype/$gitOrg/repos?per_page=200" | ruby -rubygems -e "require 'json'; JSON.parse(STDIN.read).map { |repo| %x[git clone #{repo['ssh_url']} ]}"
else
exit 1;
fi
cd $STARTPATH
echo "Downloading all $gitOrg repos complete!"