github_setup 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/github_setup/version.rb +1 -1
- metadata +1 -3
- data/exe/github-connect.sh +0 -189
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06a34687455cbe7d3e625b4aaebbdf0d5c21e299
|
4
|
+
data.tar.gz: 4788d4d318b415ade30e90ecab19ee54092d4389
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb58e37ba8602da902b7a49b778fec07c64040102bd55436fdeeae6f26db50948e46c6dde6d89ee511e9140070e634f4067f29ddcc82b9b1288d9f9c1aaa6705
|
7
|
+
data.tar.gz: 52027357bd0c04673c87f38ea40a738320577830c774237c98f57404d984795d68a691676a3f3c83da4f275ac96799130d0fd9702cd47da23db4ceaaebfe1eb3
|
data/lib/github_setup/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_setup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoshihide Chubachi
|
@@ -56,7 +56,6 @@ description: Automatically setup SSH connection to GitHub if you have the GitHub
|
|
56
56
|
email:
|
57
57
|
- yoshi@chubachi.net
|
58
58
|
executables:
|
59
|
-
- github-connect.sh
|
60
59
|
- github_setup
|
61
60
|
extensions: []
|
62
61
|
extra_rdoc_files: []
|
@@ -69,7 +68,6 @@ files:
|
|
69
68
|
- Rakefile
|
70
69
|
- bin/console
|
71
70
|
- bin/setup
|
72
|
-
- exe/github-connect.sh
|
73
71
|
- exe/github_setup
|
74
72
|
- github_setup.gemspec
|
75
73
|
- lib/github_setup.rb
|
data/exe/github-connect.sh
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
# github-connect.sh
|
4
|
-
# -----------------
|
5
|
-
# Copyright 2012 Andrew Coulton - released under the BSD licence
|
6
|
-
#
|
7
|
-
# A simple command line script to set up and register an SSH key against a
|
8
|
-
# user's github account - for example when provisioning a new virtual
|
9
|
-
# machine for a developer.
|
10
|
-
#
|
11
|
-
# Parameters:
|
12
|
-
# --user=<user> Github username (prompts if not provided)
|
13
|
-
# --passwd=<passwd> Github password (prompts if not provided)
|
14
|
-
# --keyfile=<file> Path to SSH public key file (defaults to ~/.ssh/id_rsa.pub)
|
15
|
-
# --keyname=<name> Name to use for the key on GH (defaults to $(hostname)
|
16
|
-
# --git-email=<email> Committer email address (for git global config)
|
17
|
-
# --git-author=<name> Committer name (for git global config)
|
18
|
-
|
19
|
-
USER=""
|
20
|
-
PASSWD=""
|
21
|
-
KEYFILE=~/.ssh/id_rsa
|
22
|
-
KEYNAME="$(hostname)-$(whoami)-$(date --rfc-3339=seconds)"
|
23
|
-
GIT_EMAIL=""
|
24
|
-
GIT_AUTHOR=""
|
25
|
-
|
26
|
-
# ----------------------------
|
27
|
-
# Parse command line arguments
|
28
|
-
# ----------------------------
|
29
|
-
|
30
|
-
for i in $*
|
31
|
-
do
|
32
|
-
case $i in
|
33
|
-
--user=*)
|
34
|
-
USER=${i#*=}
|
35
|
-
;;
|
36
|
-
--passwd=*)
|
37
|
-
PASSWD=${i#*=}
|
38
|
-
;;
|
39
|
-
--keyfile=*)
|
40
|
-
KEYFILE=${i#*=}
|
41
|
-
;;
|
42
|
-
--keyname=*)
|
43
|
-
KEYNAME=${i#*=}
|
44
|
-
;;
|
45
|
-
--git-email=*)
|
46
|
-
GIT_EMAIL=${i#*=}
|
47
|
-
;;
|
48
|
-
--git-author=*)
|
49
|
-
GIT_AUTHOR=${i#*=}
|
50
|
-
;;
|
51
|
-
esac
|
52
|
-
done
|
53
|
-
|
54
|
-
# --------------------------------------------
|
55
|
-
# Prompt for user and password if not provided
|
56
|
-
# --------------------------------------------
|
57
|
-
if [ -z "$USER" ]
|
58
|
-
then
|
59
|
-
read -p "Enter your github username: " USER
|
60
|
-
fi
|
61
|
-
if [ -z "$PASSWD" ]
|
62
|
-
then
|
63
|
-
read -s -p "Enter your github password: " PASSWD
|
64
|
-
echo
|
65
|
-
fi
|
66
|
-
|
67
|
-
# ----------------------------------------------
|
68
|
-
# Try to get git committer email from git config
|
69
|
-
# ----------------------------------------------
|
70
|
-
GIT_EMAIL_SET=""
|
71
|
-
GIT_AUTHOR_SET=""
|
72
|
-
|
73
|
-
if [ -z "$GIT_EMAIL" ]
|
74
|
-
then
|
75
|
-
GIT_EMAIL=$(git config --get --global user.email)
|
76
|
-
if [ ! -z "$GIT_EMAIL" ]
|
77
|
-
then
|
78
|
-
GIT_EMAIL_SET=1
|
79
|
-
fi
|
80
|
-
fi
|
81
|
-
if [ -z "$GIT_AUTHOR" ]
|
82
|
-
then
|
83
|
-
GIT_AUTHOR=$(git config --get --global user.name)
|
84
|
-
if [ ! -z "$GIT_AUTHOR" ]
|
85
|
-
then
|
86
|
-
GIT_AUTHOR_SET=1
|
87
|
-
fi
|
88
|
-
fi
|
89
|
-
|
90
|
-
# ----------------------------------------------------------------
|
91
|
-
# If not in git config, try to get email and real name from github
|
92
|
-
# ----------------------------------------------------------------
|
93
|
-
if [ -z "$GIT_AUTHOR" ]
|
94
|
-
then
|
95
|
-
GIT_AUTHOR=$(curl --user $USER:$PASSWD --silent --show-error https://api.github.com/user | python -c 'import json,sys;obj=json.loads(sys.stdin.read());print obj["'"name"'"]')
|
96
|
-
fi
|
97
|
-
|
98
|
-
if [ -z "$GIT_EMAIL" ]
|
99
|
-
then
|
100
|
-
GIT_EMAIL=$(curl --user $USER:$PASSWD --silent --show-error https://api.github.com/user/emails | python -c 'import json,sys;obj=json.loads(sys.stdin.read());print obj[0]["'"email"'"]')
|
101
|
-
fi
|
102
|
-
|
103
|
-
|
104
|
-
# -------------------------------------------------------------
|
105
|
-
# Prompt to confirm git details if required, and set git config
|
106
|
-
# -------------------------------------------------------------
|
107
|
-
if [ -z "$GIT_EMAIL_SET" ]
|
108
|
-
then
|
109
|
-
read -p "Set git committer email {$GIT_EMAIL}: " GIT_EMAIL_ANS
|
110
|
-
if [ ! -z "$GIT_EMAIL_ANS" ]
|
111
|
-
then
|
112
|
-
GIT_EMAIL = GIT_EMAIL_ANS
|
113
|
-
fi
|
114
|
-
git config --global user.email "$GIT_EMAIL"
|
115
|
-
else
|
116
|
-
echo "git committer email is set to $GIT_EMAIL"
|
117
|
-
fi
|
118
|
-
|
119
|
-
if [ -z "$GIT_AUTHOR_SET" ]
|
120
|
-
then
|
121
|
-
read -p "Set git committer name {$GIT_AUTHOR}: " GIT_AUTHOR_ANS
|
122
|
-
if [ ! -z "$GIT_AUTHOR_ANS" ]
|
123
|
-
then
|
124
|
-
GIT_AUTHOR = GIT_AUTHOR_ANS
|
125
|
-
fi
|
126
|
-
git config --global user.name "$GIT_AUTHOR"
|
127
|
-
else
|
128
|
-
echo "git committer name is set to $GIT_AUTHOR"
|
129
|
-
fi
|
130
|
-
|
131
|
-
# ----------------------------------
|
132
|
-
# Generate an SSH key if none exists
|
133
|
-
# ----------------------------------
|
134
|
-
|
135
|
-
if [ ! -e "$KEYFILE" ]
|
136
|
-
then
|
137
|
-
ssh-keygen -t rsa -C "$GIT_EMAIL" -f "$KEYFILE"
|
138
|
-
else
|
139
|
-
echo "You already have an SSH key in $KEYFILE - we will set this as your github key"
|
140
|
-
fi
|
141
|
-
|
142
|
-
# ---------------------------------
|
143
|
-
# Load the SSH public key to memory
|
144
|
-
# ---------------------------------
|
145
|
-
|
146
|
-
ssh_key=$(<$KEYFILE".pub")
|
147
|
-
|
148
|
-
|
149
|
-
# -------------------------------------------------
|
150
|
-
# Check if this key is already authorised on github
|
151
|
-
# -------------------------------------------------
|
152
|
-
|
153
|
-
gh_response=$(curl --user $USER:$PASSWD --silent --show-error https://api.github.com/user/keys)
|
154
|
-
|
155
|
-
# the email doesn't appear in the keys returned from github
|
156
|
-
search_key=${ssh_key% *}
|
157
|
-
case $gh_response in
|
158
|
-
*$search_key*)
|
159
|
-
echo -e $(tput setaf 3)
|
160
|
-
echo "Your SSH key is already authorised for your github account"
|
161
|
-
echo -e $(tput setaf 7)
|
162
|
-
exit 0;
|
163
|
-
esac
|
164
|
-
|
165
|
-
# ----------------------------
|
166
|
-
# Authorise this key on github
|
167
|
-
# ----------------------------
|
168
|
-
|
169
|
-
post_data='{"title":"'$KEYNAME'","key":"'$ssh_key'"}'
|
170
|
-
gh_response=$(curl --user $USER:$PASSWD --write-out "\nGithub response code %{http_code} \n" --data "$post_data" --header "Content-Type: application/json" --silent --show-error https://api.github.com/user/keys)
|
171
|
-
|
172
|
-
# --------------------------
|
173
|
-
# Verify the response status
|
174
|
-
# --------------------------
|
175
|
-
case $gh_response in
|
176
|
-
*"response code 201"*)
|
177
|
-
echo -e $(tput setaf 2)
|
178
|
-
echo "Your SSH key was authorised for your github account"
|
179
|
-
echo -e $(tput setaf 7)
|
180
|
-
exit 0
|
181
|
-
esac
|
182
|
-
|
183
|
-
echo -e $(tput setaf 1)
|
184
|
-
echo "********************************************"
|
185
|
-
echo "There was an error authorising your SSH key:"
|
186
|
-
echo "********************************************"
|
187
|
-
echo $gh_response
|
188
|
-
echo -e $(tput setaf 7)
|
189
|
-
exit 1
|