class AWS_SSH::Teardown
Attributes
profile[RW]
Public Class Methods
shells(home, shell)
click to toggle source
# File lib/aws_ssh/teardown.rb, line 13 def self.shells(home, shell) ["#{home}/.#{shell}rc", "#{home}/.#{shell}_profile", "#{home}/.profile"] end
Public Instance Methods
alias()
click to toggle source
create the alias file
# File lib/aws_ssh/teardown.rb, line 30 def alias filename=ENV['HOME']+"/"+AWS_SSH::ALIAS_FILE if File.exists?(filename) FileUtils.rm(filename) end return !File.exists?(filename) end
remove_from_profile()
click to toggle source
# File lib/aws_ssh/teardown.rb, line 50 def remove_from_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" File.open(@profile, 'w') { |file| file.write(contents) } end end
run()
click to toggle source
# File lib/aws_ssh/teardown.rb, line 59 def run 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 removed ", "\u2713") else printf(AWS_SSH::FORMAT_FATAL, "Alias removal failed", "\u2620") return nil end self.swap_base printf(AWS_SSH::FORMAT_OK, "Base SSH file reverted ", "\u2713") self.remove_from_profile printf(AWS_SSH::FORMAT_OK, "Alias removed from shell ", "\u2713") return true end
swap_base()
click to toggle source
# File lib/aws_ssh/teardown.rb, line 38 def swap_base origin = "#{ENV['HOME']}/.ssh/config" dest = "#{ENV['HOME']}/.ssh/#{AWS_SSH::BASE_HOSTS_FILE}" if File.exists?(dest) FileUtils.mv(dest, origin) end extra = "#{ENV['HOME']}/.ssh/#{AWS_SSH::HOSTS_FILE}" if File.exists?(extra) FileUtils.rm(extra) end end