Created
September 20, 2013 04:13
-
-
Save ryotarai/6633202 to your computer and use it in GitHub Desktop.
mina 'execute_as' patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mina | |
module SshHelpers | |
def ssh(cmd, options={}) | |
require 'shellwords' | |
cmd = cmd.join("\n") if cmd.is_a?(Array) | |
# monkey patch | |
cmd = "sudo -u #{Shellwords.escape(execute_as)} bash -c #{Shellwords.escape(cmd)}" if execute_as? | |
# end | |
script = Shellwords.escape(cmd) | |
if options[:return] == true | |
`#{ssh_command} -- #{script}` | |
elsif simulate_mode? | |
Ssh.simulate(cmd, ssh_command) | |
else | |
result = Ssh.invoke(script, self) | |
Ssh.ensure_successful result, self | |
end | |
end | |
end | |
end | |
# Usage | |
set :execute_as, 'user' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment