Class: AWS_SSH::Teardown
- Inherits:
-
Setup
- Object
- Setup
- AWS_SSH::Teardown
show all
- Defined in:
- lib/aws_ssh/teardown.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Setup
#add_to_profile, #backup, #create_base, #env, #shell
Instance Attribute Details
#profile ⇒ Object
Returns the value of attribute profile.
10
11
12
|
# File 'lib/aws_ssh/teardown.rb', line 10
def profile
@profile
end
|
Class Method Details
.shells(home, shell) ⇒ Object
13
14
15
|
# File 'lib/aws_ssh/teardown.rb', line 13
def self.shells(home, shell)
["#{home}/.#{shell}rc", "#{home}/.#{shell}_profile", "#{home}/.profile"]
end
|
Instance Method Details
#alias ⇒ Object
30
31
32
33
34
35
36
|
# 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 ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/aws_ssh/teardown.rb', line 50
def remove_from_profile
if ! @profile.nil?
contents = File.open(@profile, 'rb') {|file| file.read}
contents = contents.gsub(". ~/#{AWS_SSH::ALIAS_FILE}", "").chomp + "\n"
File.open(@profile, 'w') { |file| file.write(contents) }
end
end
|
#run ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# 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 ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
|
# 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
= "#{ENV['HOME']}/.ssh/#{AWS_SSH::HOSTS_FILE}"
if File.exists?()
FileUtils.rm()
end
end
|