Skip to content

Instantly share code, notes, and snippets.

@mklnz
Created April 17, 2012 18:12
Show Gist options
  • Save mklnz/2407925 to your computer and use it in GitHub Desktop.
Save mklnz/2407925 to your computer and use it in GitHub Desktop.
Sudo put and template methods for Capistrano
# I got tired of uploading to /tmp then moving to the correct location, so these two convenience methods will save you a lot of time in the long run.
# Helper method to upload to /tmp then use sudo to move to correct location.
def put_sudo(data, to)
filename = File.basename(to)
to_directory = File.dirname(to)
put data, "/tmp/#{filename}"
run "#{sudo} mv /tmp/#{filename} #{to_directory}"
end
# Helper method to create ERB template then upload using sudo privileges (modified from rbates)
def template_sudo(from, to)
erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
put_sudo ERB.new(erb).result(binding), to
end
@ometa
Copy link

ometa commented Apr 17, 2013

Thank you for this. Saved the day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment