Merge pull request #5591 from paperlesspost/extract_shell_cmd
Move shell_cmd to a method in SSH::Communicator
This commit is contained in:
commit
2daa9ed175
|
@ -434,6 +434,21 @@ module VagrantPlugins
|
||||||
return yield connection if block_given?
|
return yield connection if block_given?
|
||||||
end
|
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.
|
# Executes the command on an SSH connection within a login shell.
|
||||||
def shell_execute(connection, command, **opts)
|
def shell_execute(connection, command, **opts)
|
||||||
opts = {
|
opts = {
|
||||||
|
@ -442,18 +457,10 @@ module VagrantPlugins
|
||||||
}.merge(opts)
|
}.merge(opts)
|
||||||
|
|
||||||
sudo = opts[:sudo]
|
sudo = opts[:sudo]
|
||||||
shell = opts[:shell]
|
|
||||||
|
|
||||||
@logger.info("Execute: #{command} (sudo=#{sudo.inspect})")
|
@logger.info("Execute: #{command} (sudo=#{sudo.inspect})")
|
||||||
exit_status = nil
|
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
|
# These variables are used to scrub PTY output if we're in a PTY
|
||||||
pty = false
|
pty = false
|
||||||
pty_stdout = ""
|
pty_stdout = ""
|
||||||
|
@ -472,7 +479,7 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
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
|
# Setup the channel callbacks so we can get data and exit status
|
||||||
ch2.on_data do |ch3, data|
|
ch2.on_data do |ch3, data|
|
||||||
# Filter out the clear screen command
|
# Filter out the clear screen command
|
||||||
|
|
Loading…
Reference in New Issue