runssh 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,23 +20,53 @@ module RunSSHLib
20
20
 
21
21
  # A collection of ssh procedures.
22
22
  module SshBackend
23
+
24
+ class KnownHostsUtils
25
+ attr_reader :known_hosts_file
26
+
27
+ def initialize(known_hosts_file=File.expand_path('~/.ssh/known_hosts'))
28
+ @known_hosts_file = known_hosts_file
29
+ end
30
+
31
+ def delete_line_from_known_hosts_file(line_number)
32
+ `sed -i -e "#{line_number}d" #{@known_hosts_file}`
33
+ raise 'Error deleting line from known_hosts file! See output for details' unless
34
+ $? == 0
35
+ end
36
+ end
37
+
23
38
  module_function
24
39
 
25
40
  # run shell on remote host.
26
41
  # definition:: A Hash containing required data for
27
- # making shell connection (e.g., :host_name, :login).
42
+ # making shell connection (e.g., :host_name, :login).
28
43
  #
29
44
  # For running remote commands add to the _definition_ hash
30
45
  # the entire remote command as a string with a +:remote_cmd+ key.
31
46
  def shell(definition)
32
47
  raise "no hostname" unless definition[:host_name] # should never happen
48
+ rmtcmd_flag = (definition[:remote_cmd] && (!definition[:remote_cmd].empty?))
33
49
  command = "ssh "
50
+ command << "-t " if (rmtcmd_flag && (!definition[:no_pseudo_terminal]))
34
51
  command << "-l #{definition[:login]} " if definition[:login]
35
52
  command << "#{definition[:host_name]}"
36
- command << " -L #{normalize_tunnel_definition definition[:local_tunnel]} " if
53
+ command << " -L #{normalize_tunnel_definition definition[:local_tunnel]}" if
37
54
  definition[:local_tunnel]
38
- command << %( -- "#{definition[:remote_cmd]}") if
39
- (definition[:remote_cmd] && (!definition[:remote_cmd].empty?))
55
+ definition[:option].each do |option|
56
+ command << " -o #{option}"
57
+ end if definition[:option]
58
+ command << %( -- "#{definition[:remote_cmd]}") if rmtcmd_flag
59
+ exec command
60
+ end
61
+
62
+ # Copy ssh identity file to remote host according to options
63
+ # options:: A hash containing host definition (:host_name, etc) and
64
+ # optionally identity_file path.
65
+ def copy_id(options)
66
+ command = "ssh-copy-id "
67
+ command << "-i #{options[:identity_file]} " if options[:identity_file]
68
+ command << "#{options[:login]}@" if options[:login]
69
+ command << "#{options[:host_name]}"
40
70
  exec command
41
71
  end
42
72
 
@@ -41,9 +41,19 @@ module RunSSHLib
41
41
  alias_method :eql?, :==
42
42
 
43
43
  def to_print
44
- out = " * host: #{definition[:host_name]}"
44
+ out = " * host: #{definition[:host_name]}"
45
45
  out << "\n * login: #{definition[:login] || 'current user'}"
46
+ if definition[:local_tunnel]
47
+ tunnel = RunSSHLib::SshBackend.normalize_tunnel_definition(definition[:local_tunnel])
48
+ out << "\n * local tunnel: #{tunnel}"
49
+ end
50
+ if definition[:option] && definition[:option].any?
51
+ out << "\n * ssh options:"
52
+ definition[:option].each do |option|
53
+ out << "\n - #{option}"
54
+ end
55
+ end
46
56
  out
47
57
  end
48
58
  end
49
- end
59
+ end
@@ -19,9 +19,9 @@
19
19
  module RunSSHLib
20
20
  module Version
21
21
  MAJOR = 0
22
- MINOR = 2
23
- BUILD = 2
22
+ MINOR = 4
23
+ BUILD = 0
24
24
 
25
25
  STRING = [MAJOR, MINOR, BUILD].compact.join('.')
26
26
  end
27
- end
27
+ end
data/lib/runsshlib.rb CHANGED
@@ -38,6 +38,9 @@ module RunSSHLib
38
38
  # message should contain only the older config version!
39
39
  class OlderConfigVersionError < StandardError; end
40
40
 
41
+ # Just a general abort with error
42
+ class AbortError < StandardError; end
43
+
41
44
  # A placeholder for host definitions
42
45
  HostDef = Struct.new(:name, :login)
43
46
  end
data/runssh.gemspec CHANGED
@@ -19,11 +19,6 @@ EOF
19
19
  s.required_ruby_version = '>= 1.8.7'
20
20
  s.add_dependency('trollop', '~> 1.16.2')
21
21
  s.add_dependency('highline', '~> 1.6.1')
22
- s.add_development_dependency('rspec', "~> 2.1.0")
23
- s.add_development_dependency('rcov', '~> 0.9.9')
24
- s.add_development_dependency('autotest', '~> 4.4.4')
25
- s.add_development_dependency('autotest-fsevent', '~> 0.2.3')
26
- s.add_development_dependency('autotest-growl', '~> 0.2.6')
27
22
 
28
23
  s.has_rdoc = true
29
24
  s.extra_rdoc_files = ['README.rdoc']