Method: #hook_handler

Defined in:
lib/vagrant-subutai/packer/subutai_hooks.rb

#hook_handler(hook) ⇒ Object

Handle hook scripts or normal files: returns path to file to provision




15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-subutai/packer/subutai_hooks.rb', line 15

def hook_handler(hook)
  # hook might be the upload file or an executable to give the path to the
  # file to be provisioned. Builders can use this to hook into the
  # provisioning process for new management templates.
  unless File.executable?(hook)
    puts '[WARNING] hook script ' + hook + ' not executable. Abandoning launch.'
    return nil
  end

  fext = File.extname(hook)
  if fext == '.sh' && shebang?(hook)
    `#{hook}`.strip # executes and returns output (should be file)
  # elsif fext == '.bat'
  #   return `#{hook}`.strip # executes and returns output (should be file)
  else
    # raise '[WARNING] hook script not valid bash .sh or .bat. Abandoning launch.'
    raise '[WARNING] hook script not valid bash file with .sh extension. Abandoning launch.'
  end
end