Class: Script::Bash

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/bash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(toplevel, injection = nil, &block) ⇒ Bash

Returns a new instance of Bash.



9
10
11
12
13
# File 'lib/plugins/bash.rb', line 9

def initialize(toplevel, injection = nil, &block)
  @toplevel = toplevel
  @injection = injection
  instance_eval(&block)
end

Instance Attribute Details

#injectionObject (readonly)

Returns the value of attribute injection.



15
16
17
# File 'lib/plugins/bash.rb', line 15

def injection
  @injection
end

Instance Method Details

#code(s) ⇒ Object



43
# File 'lib/plugins/bash.rb', line 43

def code(s); @code = s end

#cwd(s) ⇒ Object



46
# File 'lib/plugins/bash.rb', line 46

def cwd(s); @cwd = s end

#doitObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/plugins/bash.rb', line 17

def doit
  if @code
    command = nil
    if @user
      if @user == 'root'
        command = "sudo /bin/bash"
      else
        group = @group || @user
        command = "sudo -u #{@user} -g #{group} /bin/bash"
      end
    else
      command = "/bin/bash"
    end

    if exec_code(command) == 0
      @success && @success.doit
    else
      @failure && @failure.doit
    end
  end
end

#echo(s) ⇒ Object



45
# File 'lib/plugins/bash.rb', line 45

def echo(s); @echo = s end

#failure(inj = nil, &block) ⇒ Object



51
52
53
# File 'lib/plugins/bash.rb', line 51

def failure(inj = nil, &block)
  @failure = Prog.new(@toplevel, inj, &block)
end

#group(s) ⇒ Object



42
# File 'lib/plugins/bash.rb', line 42

def group(s); @group = s end

#log(s) ⇒ Object



44
# File 'lib/plugins/bash.rb', line 44

def log(s); @log = s end

#success(inj = nil, &block) ⇒ Object



48
49
50
# File 'lib/plugins/bash.rb', line 48

def success(inj = nil, &block)
  @success = Prog.new(@toplevel, inj, &block)
end

#user(s) ⇒ Object


DSL



41
# File 'lib/plugins/bash.rb', line 41

def user(s); @user = s end