Class: Simp::Packer::IsoVarsJson

Inherits:
Object
  • Object
show all
Defined in:
lib/simp/packer/iso_vars_json.rb

Overview

Write a ‘vars.json` file to accompany a SIMP ISO

Constant Summary collapse

VARS_FORMAT_VERSION =

SemVer data version of file

(Starting at 1.0.0, because earlier formats didn't include versions)
'1.0.0'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(iso, target_release, target_data, opts = {}) ⇒ IsoVarsJson

Returns a new instance of IsoVarsJson.

Parameters:

  • file (String)

    path to iso file

  • target_release (String)

    SIMP release to build (e.g., ‘6.X’) This is a key from the build’s ‘release_mappings.yaml` in simp-core

  • target_data (Hash)

    Unpacked hash of isos and metadata The metadata is in the format returned by Simp::Build::ReleaseMapper#autoscan_unpack_list

  • opts (Hash) (defaults to: {})

    extra options



21
22
23
24
25
26
27
# File 'lib/simp/packer/iso_vars_json.rb', line 21

def initialize(iso, target_release, target_data, opts = {})
  @iso            = iso
  @target_release = target_release
  @target_data    = target_data
  @opts           = opts
  @opts[:silent] ||= false
end

Instance Method Details

#dataHash

Returns a versioned vars.json data structure

Returns:

  • (Hash)

    vars data structure



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/simp/packer/iso_vars_json.rb', line 46

def data
  sum = sha256sum(@iso)
  box_distro_release = "SIMP-#{@target_release}-#{@target_data['flavor']}-#{@target_data['os_version']}"
  {
    'simp_vars_version'   => VARS_FORMAT_VERSION,
    'box_simp_release'    => @target_release,
    'box_distro_release'  => box_distro_release,
    'iso_url'             => @iso,
    'iso_checksum'        => sum,
    'iso_checksum_type'   => 'sha256',
    'new_password'        => 'suP3rP@ssw0r!suP3rP@ssw0r!suP3rP@ssw0r!',
    'output_directory'    => './OUTPUT',
    'dist_os_flavor'      => @target_data['flavor'],
    'dist_os_version'     => @target_data['os_version'],
    'dist_os_maj_version' => @target_data['os_version'].split('.').first,
    'dist_source_isos'    => @target_data['isos'].map { |x| File.basename(x) }.join(':'),
    'git_commit'          => %x(git rev-parse --verify HEAD).strip,
    'packer_src_type'     => 'simp-iso',
    'iso_builder'         => 'rubygem-simp-rake-helpers',
    'iso_builder_version' => Simp::Rake::Helpers::VERSION
  }
end

#sha256sum(file) ⇒ String

Returns a SHA256 checksum of iso file

Parameters:

  • file (String)

    path to file

Returns:

  • (String)

    SHA256 sum of ISO



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/simp/packer/iso_vars_json.rb', line 32

def sha256sum(file)
  unless @opts[:silent]
    puts
    puts '=' * 80
    puts "#### Checksumming (SHA256) #{file}..."
    puts '=' * 80
    puts
  end

  Digest::SHA256.file(file).hexdigest
end

#write(vars_file = @iso.sub(%r{.iso$}, '.json')) ⇒ Object

Write data to a vars.json file for simp-packer to use

Parameters:

  • file (String)

    path to vars.json file to write (Defaults to the same path as the .iso, with a ‘.json` extension)



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/simp/packer/iso_vars_json.rb', line 73

def write(vars_file = @iso.sub(%r{.iso$}, '.json'))
  unless @opts[:silent]
    puts
    puts '=' * 80
    puts '#### Writing packer vars data to:'
    puts "       '#{vars_file}'"
    puts '=' * 80
    puts
  end

  File.open(vars_file, 'w') { |f| f.puts data.to_json }
end