Skip to content

Commit

Permalink
Add support for legacy ISOs on Apple Silicon
Browse files Browse the repository at this point in the history
  • Loading branch information
ninxsoft committed Oct 29, 2023
1 parent e02f03a commit a5fcffd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
15 changes: 15 additions & 0 deletions Mist/Helpers/Codesigner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,19 @@ struct Codesigner {
throw MistError.invalidTerminationStatus(status: response.terminationStatus, output: response.standardOutput, error: response.standardError)
}
}

/// Ad-hoc sign all files within a directory (or app bundle).
///
/// - Parameters:
/// - url: The URL of the directory to ad-hoc sign.
///
/// - Throws: A `MistError` if the command failed to execute.
static func adhocSign(_ url: URL) async throws {
let arguments: [String] = ["find", url.path, "-type", "f", "-exec", "codesign", "--sign", "-", "--force", "{}", ";"]
let response: HelperToolCommandResponse = try ShellExecutor.shared.execute(arguments)

guard response.terminationStatus == 0 else {
throw MistError.invalidTerminationStatus(status: response.terminationStatus, output: response.standardOutput, error: response.standardError)
}
}
}
13 changes: 13 additions & 0 deletions Mist/Helpers/TaskManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ class TaskManager: ObservableObject {
return tasks
}

// swiftlint:disable:next function_body_length
private static func isoTasks(for installer: Installer, filename: String, destination destinationURL: URL, temporaryDirectory temporaryDirectoryURL: URL) -> [MistTask] {

let temporaryImageURL: URL = temporaryDirectoryURL.appendingPathComponent("\(installer.id).dmg")
Expand All @@ -443,6 +444,12 @@ class TaskManager: ObservableObject {
},
MistTask(type: .create, description: "macOS Installer in temporary Disk Image") {

// Workaround to make OS X Yosemite 10.10 to macOS Catalina 10.15 createinstallmedia work on Apple Silicon
if let architecture: Architecture = Hardware.architecture,
architecture == .appleSilicon && !installer.bigSurOrNewer {
try await Codesigner.adhocSign(installer.temporaryInstallerURL)
}

// Workaround to make macOS Sierra 10.12 createinstallmedia work
if installer.version.hasPrefix("10.12") {
let infoPlistURL: URL = installer.temporaryInstallerURL.appendingPathComponent("Contents/Info.plist")
Expand Down Expand Up @@ -533,6 +540,12 @@ class TaskManager: ObservableObject {
let tasks: [MistTask] = [
MistTask(type: .create, description: "Bootable Installer") {

// Workaround to make OS X Yosemite 10.10 to macOS Catalina 10.15 createinstallmedia work on Apple Silicon
if let architecture: Architecture = Hardware.architecture,
architecture == .appleSilicon && !installer.bigSurOrNewer {
try await Codesigner.adhocSign(installer.temporaryInstallerURL)
}

// Workaround to make macOS Sierra 10.12 createinstallmedia work
if installer.version.hasPrefix("10.12") {
let infoPlistURL: URL = installer.temporaryInstallerURL.appendingPathComponent("Contents/Info.plist")
Expand Down
21 changes: 1 addition & 20 deletions Mist/Views/List/InstallerExportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,6 @@ struct InstallerExportView: View {
private var exportPackage: Bool = false
var installer: Installer
@Binding var exports: [InstallerExportType]
private var isoCompatible: Bool {
guard let architecture: Architecture = Hardware.architecture else {
return false
}

return architecture == .intel || (architecture == .appleSilicon && installer.bigSurOrNewer)
}
private var compatibilityMessage: String {
"**Note:** ISOs are unavailable for building **macOS Catalina 10.15 and older** on [Apple Silicon Macs](https://support.apple.com/en-us/HT211814)."
}

var body: some View {
VStack {
Expand All @@ -40,16 +30,11 @@ struct InstallerExportView: View {
InstallerExportViewItem(exportType: .diskImage, selected: $exportDiskImage)
.disabled(exports.count == 1 && exportDiskImage)
InstallerExportViewItem(exportType: .iso, selected: $exportISO)
.disabled(isoCompatible ? exports.count == 1 && exportISO : true)
.opacity(isoCompatible ? 1 : 0.5)
.disabled(exports.count == 1 && exportISO)
InstallerExportViewItem(exportType: .package, selected: $exportPackage)
.disabled(exports.count == 1 && exportPackage)
Spacer()
}
if !isoCompatible {
Text(.init(compatibilityMessage))
.padding(.top)
}
}
.padding()
.onChange(of: exportApplication) { _ in
Expand All @@ -73,10 +58,6 @@ struct InstallerExportView: View {

var exports: [InstallerExportType] = []

if !isoCompatible && exportISO {
exportISO = false
}

if !exportApplication && !exportDiskImage && !exportISO && !exportPackage {
exportApplication = true
}
Expand Down
3 changes: 1 addition & 2 deletions Mist/Views/List/ListRowInstaller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ struct ListRowInstaller: View {
}
.help("Download and export macOS Installer")
.buttonStyle(.mistAction)
if let architecture: Architecture = Hardware.architecture,
(architecture == .appleSilicon && installer.bigSurOrNewer) || (architecture == .intel && installer.mavericksOrNewer) {
if installer.mavericksOrNewer {
Button {
pressButton(.volumeSelection)
} label: {
Expand Down
2 changes: 1 addition & 1 deletion Mist/Views/Settings/SettingsISOsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ struct SettingsISOsView: View {
private let imageName: String = "ISO"
private let title: String = "ISOs"
// swiftlint:disable:next line_length
private let description: String = "ISOs are Bootable macOS Installer Disk Images that can be restored on external USB drives, or used with virtualization software (ie. [Parallels Desktop](https://www.parallels.com/au/products/desktop/), [UTM](https://mac.getutm.app), [VMware Fusion](https://www.vmware.com/au/products/fusion.html), [VirtualBox](https://www.virtualbox.org)).\n\n**Note:** ISOs are unavailable for building **macOS Catalina 10.15 and older** on [Apple Silicon Macs](https://support.apple.com/en-us/HT211814)."
private let description: String = "ISOs are Bootable macOS Installer Disk Images that can be restored on external USB drives, or used with virtualization software (ie. [Parallels Desktop](https://www.parallels.com/au/products/desktop/), [UTM](https://mac.getutm.app), [VMware Fusion](https://www.vmware.com/au/products/fusion.html), [VirtualBox](https://www.virtualbox.org))."

var body: some View {
VStack(alignment: .leading) {
Expand Down

0 comments on commit a5fcffd

Please sign in to comment.