-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-clone-all-on-tag.sh
executable file
·81 lines (65 loc) · 3.06 KB
/
github-clone-all-on-tag.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#! /bin/bash
#Copyrite: Yuri Costa
#Contributors:
#Oct.2017
#github.com/yuric/bash_profile,
#This code is released under the AGPLv3 license.
#Reach out if you have questions/comments [email protected]
# No Warranty, Usage at your own risk. Etc all the AGPLv3 license stuff.
# This script will build a full Github clone environment of github/user or github/organization public and private repos
# How-To
# 1. You will need an Auth Token to pull private as well: Get one here: https://github.com/settings/tokens
#NOTE: A personal token will work for the a user or organization if the user that owns the token has read/clone/list access to the org's private repo.
# 2. Might require you to elavate right when running it: `sudo ./github-clone-all-on-tag.sh`
# 3. Run pullRepo.sh to pull latest code from Github.
echo -n "Enter GitHub Organization or User Tag (github/[tag]):"
read GitHubTag
echo -n "Enter Sub Directory to Create :"
read SubDirectory
echo -n "Enter Github (GH) Username :"
read Username
echo -n "Enter Github (GH) Password :"
read -s Password1
echo -n "Enter GH Auth token (github.com/settings/tokens) :"
read TokenGithub
echo " "
TypeOf=users
echo "Are you cloning a user's or organization's repos?"
echo "1 for personal (users)"
echo -n "2 for organization (AcmeGroup) :"
read InputTypeOf
case "$InputTypeOf" in
1)
TypeOf=users
echo "Tag type set to users."
;;
2)
TypeOf=orgs
echo "Tag type set to Organizations."
;;
*)
echo "Not sure what you want. Defaulting to tag type users: " $InputTypeOf
;;
esac
echo " "
# Confirm all is copacetic
echo "Tag : " $GitHubTag
echo "Directory : " $SubDirectory
echo "Username is : " $Username
echo "User or Org tag is : " $TypeOf
echo "Token: " $TokenGithub
echo " "
echo "Press Enter to confirm and continue.... [Control-C] to Terminate Script"
read GoDoIt
# Attempt to create $SubDirectory, if it already exists use it.
mkdir $SubDirectory
#GO! GO! GO!
curl --user "$Username:$Password1" -H "Authorization: token $TokenGithub" -s "https://api.github.com/$TypeOf/$GitHubTag/repos?per_page=100&page=1" | grep -e 'git_url' | cut -d \" -f 4
curl --user "$Username:$Password1" -H "Authorization: token $TokenGithub" -s "https://api.github.com/$TypeOf/$GitHubTag/repos?per_page=100&page=1" | grep -e 'git_url*' | cut -d \" -f 4 | cut -d / -f 5 | cut -d . -f 1 | awk -v SubDirectory=$SubDirectory -v tag=$GitHubTag -v user=$Username '{print "/usr/bin/git clone ssh://[email protected]/" tag "/" $1 ".git"}' >> $SubDirectory/cloneRepo.sh
curl --user "$Username:$Password1" -H "Authorization: token $TokenGithub" -s "https://api.github.com/$TypeOf/$GitHubTag/repos?per_page=100&page=1" | grep -e 'git_url*' | cut -d \" -f 4 | cut -d / -f 5 | cut -d . -f 1 | awk -v SubDirectory=$SubDirectory -v tag=$GitHubTag -v user=$Username '{print "cd ~/" SubDirectory "/" $1 "\n/usr/bin/git pull ssh://[email protected]/" tag "/" $1 ".git\ncd ~"}' >> $SubDirectory/pullRepo.sh
chmod 777 $SubDirectory/cloneRepo.sh
chmod 777 $SubDirectory/pullRepo.sh
echo " "
cd $SubDirectory
/bin/bash cloneRepo.sh
echo "All done!"