github_setup 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bad1d0d2c76783aeaa5d8d86bd0de2e99a7b2ed
4
- data.tar.gz: 0d279682d475a934bc3859cce87d4975192df283
3
+ metadata.gz: 712cb46003531e05e16f433dfdc4f77bbf4fdb93
4
+ data.tar.gz: 9caf566c2cda7e24668218f1db8ee898dcb39e50
5
5
  SHA512:
6
- metadata.gz: 80e0d5559d3a6450f7f92692bde01f167b0bad9fb23c1859a63acedbdddf93a662f1b5b768b79d6e41ebfc614b88b7ebe9a091a78d9314a459a6ad4b37640f1e
7
- data.tar.gz: 14a65024836b9e95f652d10e9d02583224c6521d9c644a0198e0f6cd085476efadc27c4f4f2f83e0a595841441338f425c00a2abcf934ada3b2ac9142b7d7f08
6
+ metadata.gz: bd9d1e843eb9ea7fd5f762bbac97a73d07008e99ba68ab8e7a30e64f386e924fda844e9c90e31d1a1fdee22a652d8ea6d8387c47a1f30d18b732a2207e3085dd
7
+ data.tar.gz: 011bc4fd8a9c0ba7e4a984049114d0c2402fab00d8f75e215764edf87518c23dfd54548ac2cfaa78c19ab90029b218a6add94629d06e79bc47e9df239d203a1d
data/.travis.yml CHANGED
@@ -1,4 +1,6 @@
1
1
  sudo: false
2
+ notifications:
3
+ email: false
2
4
  language: ruby
3
5
  rvm:
4
6
  - 2.3.1
@@ -0,0 +1,189 @@
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
@@ -1,3 +1,3 @@
1
1
  module GithubSetup
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_setup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yoshihide Chubachi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-16 00:00:00.000000000 Z
11
+ date: 2016-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,6 +56,7 @@ 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
59
60
  - github_setup
60
61
  extensions: []
61
62
  extra_rdoc_files: []
@@ -68,6 +69,7 @@ files:
68
69
  - Rakefile
69
70
  - bin/console
70
71
  - bin/setup
72
+ - exe/github-connect.sh
71
73
  - exe/github_setup
72
74
  - github_setup.gemspec
73
75
  - lib/github_setup.rb