Created
April 17, 2012 18:12
-
-
Save mklnz/2407925 to your computer and use it in GitHub Desktop.
Sudo put and template methods for Capistrano
This file contains hidden or 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this. Saved the day!