class AWS_SSH::Setup
Attributes
profile[RW]
Public Class Methods
shells(home, shell)
click to toggle source
# File lib/aws_ssh/setup.rb, line 24 def self.shells(home, shell) ["#{home}/.#{shell}rc", "#{home}/.#{shell}_profile", "#{home}/.profile"] end
Public Instance Methods
add_to_profile()
click to toggle source
# File lib/aws_ssh/setup.rb, line 57 def add_to_profile if ! @profile.nil? contents = File.open(@profile, 'rb') {|file| file.read} # remove any current references and add new one in contents = contents.gsub(". ~/#{AWS_SSH::ALIAS_FILE}", "").chomp + "\n" + ". ~/#{AWS_SSH::ALIAS_FILE}" File.open(@profile, 'w') { |file| file.write(contents) } end end
alias()
click to toggle source
create the alias file
# File lib/aws_ssh/setup.rb, line 41 def alias msg = "# This is an automatically generated file; do not edit.\n# Created at #{Time.now}\n# Created by aws_ssh #{AWS_SSH::VERSION}\n" cmd = 'alias ssh="' + AWS_SSH::GENERATE_CMD + ' ; '+AWS_SSH::MERGE_CMD+ '; ssh"' filename=ENV['HOME']+"/"+AWS_SSH::ALIAS_FILE File.open(filename, 'w') { |file| file.write(msg+cmd) } return File.exists?(filename) end
backup()
click to toggle source
# File lib/aws_ssh/setup.rb, line 66 def backup filename = "#{ENV['HOME']}/.ssh/config" if File.exists?(filename) FileUtils.copy_file(filename, "#{filename}.bk.#{Time.now.to_i}", true) end end
create_base()
click to toggle source
move any current ssh config file to a base file
# File lib/aws_ssh/setup.rb, line 49 def create_base origin = "#{ENV['HOME']}/.ssh/config" dest = "#{ENV['HOME']}/.ssh/#{AWS_SSH::BASE_HOSTS_FILE}" if File.exists?(origin) FileUtils.mv(origin, dest) end end
env()
click to toggle source
all vars are required
# File lib/aws_ssh/setup.rb, line 13 def env return ( ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY'] && ENV['AWS_REGION'] && ENV['SHELL'] && ENV['HOME']) end
run()
click to toggle source
# File lib/aws_ssh/setup.rb, line 73 def run self.backup if !self.env printf(AWS_SSH::FORMAT_FATAL, "Environment failed", "\u2620") return nil else printf(AWS_SSH::FORMAT_OK, "Environment vars", "\u2713") end self.profile if @profile.nil? printf(AWS_SSH::FORMAT_FATAL, "Shell profile failed", "\u2620") return nil else printf(AWS_SSH::FORMAT_OK, "Shell profile found", "\u2713") end if self.alias printf(AWS_SSH::FORMAT_OK, "Alias file created ", "\u2713") else printf(AWS_SSH::FORMAT_FATAL, "Alias file creation failed", "\u2620") return nil end self.create_base printf(AWS_SSH::FORMAT_OK, "Base SSH file created ", "\u2713") self.add_to_profile printf(AWS_SSH::FORMAT_OK, "Alias added to shell ", "\u2713") run = AWS_SSH::Run.new run.force run.merge printf(AWS_SSH::FORMAT_OK, "Completed first run", "\u2713") return true end
shell()
click to toggle source
# File lib/aws_ssh/setup.rb, line 17 def shell shell = ENV['SHELL'] last = shell.rindex("/")+1 len = shell.length-1 return shell[last..len] end