aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelijah <elijah@riseup.net>2013-04-18 00:16:58 -0700
committerelijah <elijah@riseup.net>2013-04-18 00:16:58 -0700
commit558a44fb6391461f9e56060a5211435128e5fff3 (patch)
tree9a9399703a2c6a5b711ac6306804edb40682f4cc
parentf77ee68d61646d27ea2c4098d14808b31f6d9a86 (diff)
downloadleap_cli-558a44fb6391461f9e56060a5211435128e5fff3.tar.gz
leap_cli-558a44fb6391461f9e56060a5211435128e5fff3.tar.bz2
added `leap mosh NODE`
-rw-r--r--lib/leap_cli/commands/shell.rb51
1 files changed, 35 insertions, 16 deletions
diff --git a/lib/leap_cli/commands/shell.rb b/lib/leap_cli/commands/shell.rb
index cc17408..5c16f92 100644
--- a/lib/leap_cli/commands/shell.rb
+++ b/lib/leap_cli/commands/shell.rb
@@ -4,23 +4,42 @@ module LeapCli; module Commands
arg_name 'NAME' #, :optional => false, :multiple => false
command :ssh do |c|
c.action do |global_options,options,args|
- node = get_node_from_args(args)
- options = [
- "-o 'HostName=#{node.ip_address}'",
- "-o 'HostKeyAlias=#{node.name}'",
- "-o 'GlobalKnownHostsFile=#{path(:known_hosts)}'",
- "-o 'StrictHostKeyChecking=yes'"
- ]
- if node.vagrant?
- options << "-i #{vagrant_ssh_key_file}"
- end
- username = 'root'
- # the echo sets the terminal title. it would be better to do this on the server
- cmd = "ssh -l #{username} -p #{node.ssh.port} #{options.join(' ')} #{node.name}"
- log 2, cmd
- title = "echo -n \"\\033]0;#{username}@#{node.domain.full}\007\""
- exec "#{title} && #{cmd}"
+ exec_ssh(:ssh, args)
end
end
+ desc 'Log in to the specified node with an interactive shell using mosh.'
+ arg_name 'NAME'
+ command :mosh do |c|
+ c.action do |global_options,options,args|
+ exec_ssh(:mosh, args)
+ end
+ end
+
+ private
+
+ def exec_ssh(cmd, args)
+ node = get_node_from_args(args)
+ options = [
+ "-o 'HostName=#{node.ip_address}'",
+ "-o 'HostKeyAlias=#{node.name}'",
+ "-o 'GlobalKnownHostsFile=#{path(:known_hosts)}'",
+ "-o 'StrictHostKeyChecking=yes'"
+ ]
+ if node.vagrant?
+ options << "-i #{vagrant_ssh_key_file}"
+ end
+ username = 'root'
+ # the echo sets the terminal title. it would be better to do this on the server
+ ssh = "ssh -l #{username} -p #{node.ssh.port} #{options.join(' ')}"
+ if cmd == :ssh
+ command = "#{ssh} #{node.name}"
+ elsif cmd == :mosh
+ command = "mosh --ssh \"#{ssh}\" #{node.name}"
+ end
+ log 2, command
+ title = "echo -n \"\\033]0;#{username}@#{node.domain.full}\007\""
+ exec "#{title} && #{command}"
+ end
+
end; end \ No newline at end of file