Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/env ruby
require 'rubygems'
require 'choice'
Choice.options do
header ''
header 'options:'
option :phrase do
short '-p'
long '--passphrase=PHRASE'
desc 'Passphrase to be used to create you SSH key'
end
option :user do
short '-u'
long '--user=USER'
desc 'Your GitHub user name'
end
option :token do
short '-t'
long '--token=TOKEN'
desc 'Your GitHub token'
end
option :email do
short '-e'
long '--email=EMAIL'
desc 'The email to be used with git'
end
option :name do
short '-n'
long '--name=NAME'
desc 'Name to be used with git'
end
end
key = "#{ENV['HOME']}/.ssh/id_rsa"
pubkey = "#{key}.pub"
if !File.exist?(pubkey)
`ssh-keygen -t rsa -N "#{Choice.choices[:phrase]}" -f #{key}`
end
gitconfig = "#{ENV['HOME']}/.gitconfig"
if !File.exist?(gitconfig)
if not Choice.choices[:user] or not Choice.choices[:token]
raise "Missing #{gitconfig}. Use ghkey --help to see options on how to create one."
end
`git config --global github.user #{Choice.choices[:user]}`
`git config --global github.token #{Choice.choices[:token]}`
`git config --global user.name #{Choice.choices[:name]}` if Choice.choices[:name]
`git config --global user.email #{Choice.choices[:email]}` if Choice.choices[:email]
end
sshkey = File.open(pubkey, 'r') { |f| f.read }
hostname = `hostname`
`curl -is --basic -u "#{Choice.choices[:user]}/token:#{Choice.choices[:token]}" http://github.com/api/v2/json/user/key/add -F "title=#{hostname}" -F "key=#{sshkey}"`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.