Class: Hackmac::KextUpgrader
- Inherits:
-
Object
- Object
- Hackmac::KextUpgrader
- Includes:
- FileUtils, AssetTools
- Defined in:
- lib/hackmac/kext_upgrader.rb
Overview
A class that handles the upgrade process for kernel extensions (kexts)
The KextUpgrader class manages the workflow for upgrading macOS kernel extensions by checking remote version availability, downloading new versions, and performing file system operations to replace existing kext files after user confirmation
Instance Method Summary collapse
-
#initialize(path:, config:, force: false) ⇒ KextUpgrader
constructor
The initialize method sets up a KextUpgrader instance by storing the provided path, configuration, and force flag.
-
#perform ⇒ void
The perform method executes the kext upgrade process by isolating the operation in a temporary directory.
Methods included from AssetTools
Constructor Details
#initialize(path:, config:, force: false) ⇒ KextUpgrader
The initialize method sets up a KextUpgrader instance by storing the provided path, configuration, and force flag.
This method takes the necessary parameters to configure the kext upgrader, including the filesystem path to the kext, the configuration object that defines source information, and a force flag that determines whether upgrades should be performed even when the remote version is not newer than the local version.
35 36 37 |
# File 'lib/hackmac/kext_upgrader.rb', line 35 def initialize(path:, config:, force: false) @path, @config, @force = path, config, force end |
Instance Method Details
#perform ⇒ void
This method returns an undefined value.
The perform method executes the kext upgrade process by isolating the operation in a temporary directory
This method handles the complete workflow for upgrading a kernel extension, including checking for remote version availability, downloading and decompressing the new version, identifying target installation paths, and performing the actual file replacement after user confirmation
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/hackmac/kext_upgrader.rb', line 54 def perform isolate do |dir| kext = Kext.new(path: @path, config: @config) case when kext.remote_version.nil? puts "No source defined for #{kext}" when (kext.remote_version > kext.version rescue false) || @force name, data = kext.remote_kext.download_asset if name File.secure_write(name, data) decompress(name) kext_pathes = [] Find.find(dir) do |path| if File.directory?(path) case File.basename(path) when /\A\./ Find.prune when "#{kext.name}.kext" kext_pathes.unshift path when *@config.kext.sources[kext.name]&.plugins?&.map { |p| p + '.kext' } then kext_pathes << path end end end kext_pathes.each do |kext_path| old_path = (Pathname.new(@path).dirname + File.basename(kext_path)).to_s if ask("Really upgrade #{old_path.inspect} to version #{kext.remote_version}? (y/n) ") rm_rf old_path cp_r kext_path, old_path end end else fail "#{kext.remote_kext.name} could not be downloaded" end else puts "#{kext} is already the latest version" end end end |