Module: Bootscript

Defined in:
lib/bootscript.rb,
lib/bootscript/chef.rb,
lib/bootscript/script.rb,
lib/bootscript/version.rb,
lib/bootscript/uu_writer.rb

Overview

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

Defined Under Namespace

Modules: Chef Classes: Script, UUWriter

Constant Summary collapse

DEFAULT_VARS =

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

{
  platform:       :unix,          # or :windows
  create_ramdisk: false,
  startup_command: '',  # customized by platform if chef used
  ramdisk_mount:  '',   # customized by platform, see platform_defaults
  ramdisk_size:   20,   # Megabytes
  add_script_tags: false,
  script_name:    'bootscript', # base name of the boot script
  strip_comments: true,
  imdisk_url:     'http://www.ltr-data.se/files/imdiskinst.exe',
  update_os:      false
}
BUILTIN_TEMPLATE_DIR =
File.dirname(__FILE__)+"/templates"
UNIX_TEMPLATE =
"#{BUILTIN_TEMPLATE_DIR}/bootscript.sh.erb"
WINDOWS_TEMPLATE =
"#{BUILTIN_TEMPLATE_DIR}/bootscript.ps1.erb"
VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.default_logger(output = nil, level = Logger::FATAL) ⇒ Logger

Returns a slightly-modified version of the default Ruby Logger

Parameters:

  • output (STDOUT, File, etc.) (defaults to: nil)

    where to write the logs

  • level (DEBUG|INFO|etc.) (defaults to: Logger::FATAL)

    desired minimum severity

Returns:

  • (Logger)

    a standard Ruby Logger with a nicer output format



46
47
48
49
50
51
52
53
# 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) ⇒ Object

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.



30
31
32
33
34
# 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) ⇒ Object

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



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# 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) ⇒ Boolean

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

Returns:

  • (Boolean)


38
39
40
# File 'lib/bootscript.rb', line 38

def self.windows?(erb_vars)
  (erb_vars[:platform] || '').to_s.downcase == 'windows'
end