environment/lib/system/macos.rb
2025-08-26 17:50:38 +02:00

76 lines
1.5 KiB
Ruby

require 'open3'
require_relative "utils"
module MacOSSystem
def os_name
"macOS"
end
def arch
sh("sysctl -n hw.machine")
end
def cpus
stdout, stderr, status = Open3.capture3("sysctl -n hw.ncpu")
stdout.strip.to_i
end
def install(packages)
missing_packages = packages.reject { |pkg| package_installed?(pkg) }
if missing_packages.empty?
puts "All packages are already installed."
return
end
pkg_list = missing_packages.join(' ')
puts "Installing missing packages: #{pkg_list}"
success = system("brew install #{pkg_list}")
unless success
puts "Failed to install some packages."
end
end
def package_installed?(package)
system("brew list --formula | grep -qx #{package}")
end
def uninstall(packages)
installed_packages = packages.select { |pkg| package_installed?(pkg) }
if installed_packages.empty?
puts "None of the specified packages are installed."
return
end
pkg_list = installed_packages.join(' ')
puts "Uninstalling packages: #{pkg_list}"
success = system("brew uninstall #{pkg_list}")
unless success
puts "Failed to uninstall some packages."
end
end
def qemu_code_fd_path()
case arch_to_symbol(arch)
when :arm64
"/opt/homebrew/share/qemu/edk2-aarch64-code.fd"
else
raise "not supported yet"
end
end
def qemu_vars_fd_path()
case arch_to_symbol(arch)
when :arm64
"/opt/homebrew/share/qemu/edk2-arm-vars.fd"
else
raise "not supported yet"
end
end
end