Skip to content

Instantly share code, notes, and snippets.

@mklnz
Created April 17, 2012 18:12
Show Gist options
  • Select an option

  • Save mklnz/2407925 to your computer and use it in GitHub Desktop.

Select an option

Save mklnz/2407925 to your computer and use it in GitHub Desktop.

Revisions

  1. mklnz revised this gist Apr 17, 2012. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions capistrano_sudo_helpers.rb
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,14 @@
    #Helper method to upload to /tmp then use sudo to move to correct location.
    # 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)
    # 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
  2. mklnz created this gist Apr 17, 2012.
    13 changes: 13 additions & 0 deletions capistrano_sudo_helpers.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #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