Class: Hackmac::OCUpgrader

Inherits:
Object
  • Object
show all
Includes:
FileUtils::Verbose, AssetTools
Defined in:
lib/hackmac/oc_upgrader.rb

Overview

A class that handles the upgrade process for OpenCore bootloader files

The OCUpgrader class manages the workflow for upgrading OpenCore bootloader installations by retrieving remote release information, downloading and decompressing new versions, and performing file system operations to replace existing EFI files after ensuring the installation directory is properly configured

Examples:

upgrader = Hackmac::OCUpgrader.new(mdev: '/dev/disk1', config: config_obj)
upgrader.perform
# Executes the OpenCore upgrade process in a temporary directory context

Instance Method Summary collapse

Methods included from AssetTools

#decompress, #isolate

Constructor Details

#initialize(mdev:, config:) ⇒ void

The initialize method sets up an OCUpgrader instance by configuring the installation directory based on the provided mount point and configuration.

This method takes a mount device identifier and configuration object, then constructs the full path to the EFI installation directory by joining the mount path with the OpenCore EFI path 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



33
34
35
36
37
# File 'lib/hackmac/oc_upgrader.rb', line 33

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

Instance Method Details

#performvoid

This method returns an undefined value.

The perform method executes the OpenCore upgrade process by isolating the operation in a temporary directory

This method handles the complete workflow for upgrading OpenCore bootloader files, including retrieving remote release information, downloading and decompressing the new version, and performing file system operations to replace existing EFI files after ensuring the installation directory is properly configured

Raises:

  • (RuntimeError)

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



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/hackmac/oc_upgrader.rb', line 52

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)
      for f in @config.oc.files.map { |x| Pathname.new(x) }
        sf = Pathname.new(dir).join(@config.oc.install_path).join(f)
        cp sf, @install_dir.join(f.dirname)
      end
    else
      fail "#{oc} could not be downloaded"
    end
  end
end

#to_sString

The to_s method returns a string representation of the object by formatting the installation directory path into a descriptive string that indicates where the OpenCore files will be installed

Returns:

  • (String)

    a formatted string containing the installation path in the format “Installation into /path/to/installation/directory”



75
76
77
# File 'lib/hackmac/oc_upgrader.rb', line 75

def to_s
  'Installation into %s' % @install_dir
end