Sha256: 419ee4af8b1a01a59a3674878bf149d713bb0dbe170f6c70bef804090643c3b7

Contents?: true

Size: 1.64 KB

Versions: 8

Compression:

Stored size: 1.64 KB

Contents

module Capsaicin

  module Invocation

    # Capistrano's system() override is only available from the base deployment strategy.
    # Also, we could do with a few more windows checks.
    def local_run(*args, &block)
      args.pop if Hash===args.last
      cmd = args.join(' ')
      if RUBY_PLATFORM =~ /win32|mingw|mswin/
        cmd.gsub!('/','\\') # Replace / with \\
        cmd.gsub!(/^cd /,'cd /D ') # Replace cd with cd /D
        cmd.gsub!(/&& cd /,'&& cd /D ') # Replace cd with cd /D
        logger.trace "executing locally: #{cmd}"
        Kernel.system cmd
      else
        logger.trace "executing locally: #{cmd}"
        Kernel.system cmd
      end
    end
    
    # Always uses :runner to sudo as someone. 
    # Equivalent to:  sudo "command", :as => fetch(:runner,nil)
    def sudo_as(*args, &block)
      options = Hash===args.last ? args.pop.dup :  {}
      options[:as] = fetch(:runner, nil)
      sudo *args.push(options), &block
    end
    
    # Extremely helpful if you only have permission to: sudo su SOMEUSER -c "command"
    def sudo_su(*args, &block)
      options = Hash===args.last ? args.pop.dup :  {}
      args[0] = "su #{fetch(:runner, nil)} -c '#{args[0]}'"
      sudo *args.push(options), &block
    end
    
    # Extremely helpful if you only have permission to: sudo su - SOMEUSER
    def sudo_su_to(*args, &block)
      options = Hash===args.last ? args.pop.dup :  {}
      options[:shell] = false
      cmd = args[0].gsub(/[$\\`"]/) { |m| "\\#{m}" }
      args[0] = "echo \"#{cmd}\" | #{sudo} su - #{fetch(:runner, nil)}"
      run *args.push(options), &block
    end
  end

  Capistrano::Configuration.send :include, Invocation
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
joekhoobyar-capsaicin-0.1.2 lib/capsaicin/invocation.rb
joekhoobyar-capsaicin-0.1.3 lib/capsaicin/invocation.rb
joekhoobyar-capsaicin-0.1.4 lib/capsaicin/invocation.rb
joekhoobyar-capsaicin-0.1.5 lib/capsaicin/invocation.rb
capsaicin-0.1.3 lib/capsaicin/invocation.rb
capsaicin-0.1.2 lib/capsaicin/invocation.rb
capsaicin-0.1.5 lib/capsaicin/invocation.rb
capsaicin-0.1.4 lib/capsaicin/invocation.rb