Created
August 18, 2012 05:52
-
-
Save agush22/3384721 to your computer and use it in GitHub Desktop.
Simple SSH key switcher for multiple Heroku accounts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
class Switcher | |
include FileUtils | |
home = File.expand_path('~/')+"/" | |
@@dir = home+".ssh/" | |
@@current = home + ".switcher" | |
def switch_accounts(account) | |
#missing all types of checks | |
#check for current account | |
#check if account keys exist | |
#check everything | |
file = File.open(@@current).first | |
if account == file | |
puts "Same account" | |
else | |
cp(@@dir+account+"/id_rsa", @@dir+"id_rsa", :verbose => true) | |
cp(@@dir+account+"/id_rsa.pub", @@dir+"id_rsa.pub", :verbose => true) | |
File.open(@@current, 'w') {|f| f.write(account) } | |
puts "Changed account to " + account | |
end | |
end | |
def get_current | |
puts File.open(@@current).first | |
end | |
end | |
sw = Switcher.new | |
if ARGV.first.nil? | |
puts "Missing arguments" | |
elsif ARGV.first == "current" | |
sw.get_current | |
else | |
sw.switch_accounts(ARGV.first) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment