From 2f816693942e5ed3eae93156e7a502a6c210aaa9 Mon Sep 17 00:00:00 2001 From: Aaron Quint Date: Mon, 13 Apr 2015 13:45:17 -0400 Subject: [PATCH] Move shell_cmd to a method in SSH::Communicator This allows shell_cmd to be overridable by plugins/patches without having to override the entire (large) shell_execute method --- plugins/communicators/ssh/communicator.rb | 25 +++++++++++++++-------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/plugins/communicators/ssh/communicator.rb b/plugins/communicators/ssh/communicator.rb index 64455042b..4109a66ff 100644 --- a/plugins/communicators/ssh/communicator.rb +++ b/plugins/communicators/ssh/communicator.rb @@ -434,6 +434,21 @@ module VagrantPlugins return yield connection if block_given? end + # The shell wrapper command used in shell_execute defined by + # the sudo and shell options. + def shell_cmd(opts) + sudo = opts[:sudo] + shell = opts[:shell] + + # Determine the shell to execute. Prefer the explicitly passed in shell + # over the default configured shell. If we are using `sudo` then we + # need to wrap the shell in a `sudo` call. + cmd = @machine.config.ssh.shell + cmd = shell if shell + cmd = "sudo -E -H #{cmd}" if sudo + cmd + end + # Executes the command on an SSH connection within a login shell. def shell_execute(connection, command, **opts) opts = { @@ -442,18 +457,10 @@ module VagrantPlugins }.merge(opts) sudo = opts[:sudo] - shell = opts[:shell] @logger.info("Execute: #{command} (sudo=#{sudo.inspect})") exit_status = nil - # Determine the shell to execute. Prefer the explicitly passed in shell - # over the default configured shell. If we are using `sudo` then we - # need to wrap the shell in a `sudo` call. - shell_cmd = @machine.config.ssh.shell - shell_cmd = shell if shell - shell_cmd = "sudo -E -H #{shell_cmd}" if sudo - # These variables are used to scrub PTY output if we're in a PTY pty = false pty_stdout = "" @@ -472,7 +479,7 @@ module VagrantPlugins end end - ch.exec(shell_cmd) do |ch2, _| + ch.exec(shell_cmd(opts)) do |ch2, _| # Setup the channel callbacks so we can get data and exit status ch2.on_data do |ch3, data| # Filter out the clear screen command