Class: Hackmac::OCValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/hackmac/oc_validator.rb

Overview

A class that handles validation of OpenCore bootloader configurations

The OCValidator class provides functionality for verifying the correctness and compatibility of OpenCore EFI configuration files. It retrieves the latest OpenCore release, downloads the necessary validation utilities, and executes validation checks against a specified configuration plist file to ensure it meets the required standards for OpenCore bootloaders.

Examples:

validator = Hackmac::OCValidator.new(mdev: '/dev/disk1', config: config_obj)
# Configures validation for an OpenCore installation on a specific disk

Instance Method Summary collapse

Constructor Details

#initialize(mdev:, config:) ⇒ OCValidator

The initialize method sets up an OCValidator instance by configuring the path to the OpenCore configuration plist file

This method takes a mount device identifier and configuration object, then constructs the full path to the OpenCore configuration plist file by joining the mount path with the EFI path and OC subdirectory specified in the configuration

Parameters:

  • mdev (String)

    the mount device identifier for the EFI partition

  • config (Object)

    the configuration object containing OpenCore settings including the EFI path



25
26
27
28
29
30
# File 'lib/hackmac/oc_validator.rb', line 25

def initialize(mdev:, config:)
  @config = config
  mount_path   = Pathname.new('/Volumes').join(mdev)
  @config_plist =
    Pathname.new(mount_path).join(@config.oc.efi_path).join('OC/config.plist')
end

Instance Method Details

#performBoolean

The perform method executes the OpenCore configuration validation process

This method handles the complete workflow for validating an OpenCore configuration file by retrieving the latest OpenCore release, downloading the validation utilities, and running the ocvalidate tool against the specified configuration plist file

Returns:

  • (Boolean)

    returns true if validation succeeds, false if validation fails

Raises:

  • (RuntimeError)

    raised when the OpenCore download fails or when no remote source is defined for the OpenCore upgrade



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/hackmac/oc_validator.rb', line 42

def perform
  isolate do |dir|
    oc = OC.new(config: @config)
    name, data = oc.remote.download_asset
    if name
      File.secure_write(name, data)
      decompress(name)
      result = %x(Utilities/ocvalidate/ocvalidate #{@config_plist.to_s.inspect} 2>&1)
      if $?.success?
        STDERR.puts result
        true
      else
        STDERR.puts "Validation has failed!", "", result
        false
      end
      true
    else
      fail "#{oc} could not be downloaded"
    end
  end
end