Skip to content

Instantly share code, notes, and snippets.

@ryotarai
Created September 20, 2013 04:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryotarai/6633202 to your computer and use it in GitHub Desktop.
Save ryotarai/6633202 to your computer and use it in GitHub Desktop.
mina 'execute_as' patch
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