Module: Capsaicin::Invocation

Defined in:
lib/capsaicin/invocation.rb

Instance Method Summary collapse

Instance Method Details

#local_run(*args, &block) ⇒ Object

Capistrano’s system() override is only available from the base deployment strategy. Also, we could do with a few more windows checks.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/capsaicin/invocation.rb', line 7

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

#sudo_as(*args, &block) ⇒ Object

Always uses :runner to sudo as someone. Equivalent to: sudo “command”, :as => fetch(:runner,nil)



24
25
26
27
28
# File 'lib/capsaicin/invocation.rb', line 24

def sudo_as(*args, &block)
  options = Hash===args.last ? args.pop.dup :  {}
  options[:as] = fetch(:runner, nil)
  sudo *args.push(options), &block
end

#sudo_su(*args, &block) ⇒ Object

Extremely helpful if you only have permission to: sudo su SOMEUSER -c “command”



31
32
33
34
35
# File 'lib/capsaicin/invocation.rb', line 31

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

#sudo_su_to(*args, &block) ⇒ Object

Extremely helpful if you only have permission to: sudo su - SOMEUSER



38
39
40
41
42
43
44
# File 'lib/capsaicin/invocation.rb', line 38

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