module Bootscript

provides the software’s only public method, generate()

Constants

BUILTIN_TEMPLATE_DIR
DEFAULT_VARS

These values are interpolated into all templates, and can be overridden in calls to {Bootscript#generate}

UNIX_TEMPLATE
VERSION
WINDOWS_TEMPLATE

Public Class Methods

default_logger(output = nil, level = Logger::FATAL) click to toggle source

Returns a slightly-modified version of the default Ruby Logger @param output [STDOUT, File, etc.] where to write the logs @param level [DEBUG|INFO|etc.] desired minimum severity @return [Logger] a standard Ruby Logger with a nicer output format

# File lib/bootscript.rb, line 46
def self.default_logger(output = nil, level = Logger::FATAL)
  logger = ::Logger.new(output || STDOUT)
  logger.sev_threshold = level
  logger.formatter = proc {|lvl, time, prog, msg|
    "#{lvl} #{time.strftime '%Y-%m-%d %H:%M:%S %Z'}: #{msg}\n"
  }
  logger
end
generate(template_vars = {}, data_map = {}, destination = nil) click to toggle source

Generates the full text of a boot script based on the supplied template_vars and data_map. If no optional destination is supplied, the full text is returned as a String. Otherwise, the text is written to the destination using write(), and the number of bytes written is returned.

# File lib/bootscript.rb, line 30
def self.generate(template_vars = {}, data_map = {}, destination = nil)
  script = Bootscript::Script.new(template_vars[:logger])
  script.data_map = data_map
  script.generate(template_vars, destination)
end
merge_platform_defaults(vars) click to toggle source

Returns the passed Hash of template vars, merged over a set of computed, platform-specific default variables

# File lib/bootscript.rb, line 57
def self.merge_platform_defaults(vars)
  defaults = DEFAULT_VARS.merge(vars)
  if defaults[:platform].to_s == 'windows'
    defaults[:ramdisk_mount]      = 'R:'
    defaults[:script_name]        = 'bootscript.ps1'
    if Chef::included?(defaults)
      defaults[:startup_command]  = 'PowerShell -Command "& '+
        '{C:/chef/chef-install.ps1}" > c:/chef/bootscript_setup.log 2>&1'
    end
  else
    defaults[:ramdisk_mount]      = '/etc/secrets'
    defaults[:script_name]        = 'bootscript.sh'
    if Chef::included?(defaults)
      defaults[:startup_command]  = 'chef-install.sh'
    end
  end
  defaults.merge(vars)  # return user vars merged over platform defaults
end
windows?(erb_vars) click to toggle source

Returns true if the passed Hash of erb_vars indicate a Windows boot target

# File lib/bootscript.rb, line 38
def self.windows?(erb_vars)
  (erb_vars[:platform] || '').to_s.downcase == 'windows'
end