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.
- data/.gitignore +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +22 -8
- data/README.rdoc +39 -9
- data/bin/runssh_comp.sh +1 -1
- data/features/add_bookmarks.feature +58 -0
- data/features/cli_help.feature +32 -0
- data/features/copy_id.feature +26 -0
- data/features/delete_bookmarks.feature +45 -0
- data/features/export_bookmarks.feature +19 -0
- data/features/import_bookmarks.feature +35 -0
- data/features/print_bookmarks.feature +42 -0
- data/features/run_shell.feature +83 -0
- data/features/step_definitions/argument_steps.rb +51 -0
- data/features/step_definitions/bookmarks_steps.rb +109 -0
- data/features/step_definitions/output_steps.rb +77 -0
- data/features/support/env.rb +36 -0
- data/features/update_bookmarks.feature +24 -0
- data/lib/runsshlib/cli.rb +248 -120
- data/lib/runsshlib/ssh_backend.rb +34 -4
- data/lib/runsshlib/ssh_host_def.rb +12 -2
- data/lib/runsshlib/version.rb +3 -3
- data/lib/runsshlib.rb +3 -0
- data/runssh.gemspec +0 -5
- data/spec/runsshlib/cli_spec.rb +181 -319
- data/spec/runsshlib/config_file_spec.rb +3 -5
- data/spec/runsshlib/ssh_backend_spec.rb +48 -3
- data/spec/runsshlib/ssh_host_def_spec.rb +5 -1
- data/spec/spec_helper.rb +4 -65
- data/spec/support/utils.rb +149 -0
- metadata +34 -86
@@ -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
|
-
#
|
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]}
|
53
|
+
command << " -L #{normalize_tunnel_definition definition[:local_tunnel]}" if
|
37
54
|
definition[:local_tunnel]
|
38
|
-
|
39
|
-
|
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 =
|
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
|
data/lib/runsshlib/version.rb
CHANGED
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']
|