64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/packaging/util/net.rb', line 64
def remote_execute(target_host, command, user_options = {})
option_defaults = {
capture_output: false,
extra_options: '',
fail_fast: true,
trace: false
}
options = option_defaults.merge(user_options)
ssh = Pkg::Util::Tool.check_tool('ssh')
shell_flags = ''
shell_flags += 'set -e;' if options[:fail_fast]
shell_flags += 'set -x;' if options[:trace]
shell_commands = "#{shell_flags}#{command}"
remote_command = "#{ssh} #{options[:extra_options]} -t #{target_host} " +
"'#{shell_commands.gsub("'", "'\\\\''")}'"
if ENV['DRYRUN']
puts "[DRY-RUN] Executing '#{command}' on #{target}"
puts "[DRY-RUN] #{cmd}"
return ''
end
if options[:capture_output]
stdout, stderr, exitstatus = Pkg::Util::Execution.capture3(remote_command)
Pkg::Util::Execution.success?(exitstatus) or
raise "Remote ssh command (\"#{remote_command}\") failed."
return stdout, stderr
end
puts "Remote Execute: '#{remote_command}'"
Kernel.system(remote_command)
Pkg::Util::Execution.success? or
raise "Remote ssh command (\"#{remote_command}\") failed."
end
|