Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 42 additions & 16 deletions Mist/Helpers/InstallerCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum InstallerCreator {
///
/// - Throws: A `MistError` if the downloaded macOS Installer fails to generate.
static func create(_ installer: Installer, mountPoint: URL, cacheDirectory: String) async throws {
let installerCacheDirectoryURL = URL(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id)
let packageURL: URL

if installer.sierraOrOlder {
Expand All @@ -29,36 +30,61 @@ enum InstallerCreator {
packageURL = URL(fileURLWithPath: "/Volumes/Install \(installer.name)").appendingPathComponent(package.filename.replacingOccurrences(of: ".dmg", with: ".pkg"))
} else {
if installer.containsInstallAssistantPackage {
packageURL = URL(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id).appendingPathComponent("InstallAssistant.pkg")
packageURL = installerCacheDirectoryURL.appendingPathComponent("InstallAssistant.pkg")
} else if installer.containsInstallAssistantAutoPackage {
packageURL = installerCacheDirectoryURL.appendingPathComponent("InstallAssistantAuto.pkg")
} else {
guard let url: URL = URL(string: installer.distributionURL) else {
throw MistError.invalidURL(installer.distributionURL)
}

packageURL = URL(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id).appendingPathComponent(url.lastPathComponent)
packageURL = installerCacheDirectoryURL.appendingPathComponent(url.lastPathComponent)
}
}

try await DirectoryRemover.remove(installer.temporaryInstallerURL)

var argumentsArrays: [[String]] = [
["installer", "-pkg", packageURL.path, "-target", mountPoint.path]
]

// workaround for macOS High Sierra 10.13, macOS Mojave 10.14 and macOS Catalina 10.15
if installer.highSierraOrNewer, !installer.bigSurOrNewer {
var argumentsArrays: [[String]] = []

let osVersion = ProcessInfo.processInfo.operatingSystemVersion
if
installer.highSierraOrNewer, !installer.bigSurOrNewer,
(osVersion.majorVersion > 15 || (osVersion.majorVersion == 15 && osVersion.minorVersion >= 6)) {
// Use special method for macOS >= 15.6
let installAssistantExpansionDirectory = installerCacheDirectoryURL.appendingPathComponent("InstallAssistantAuto")
let payloadInstallerApp = installAssistantExpansionDirectory.appendingPathComponent("Payload/Install \(installer.name).app")
let sharedSupportDirectory = payloadInstallerApp.appendingPathComponent("Contents/SharedSupport")
argumentsArrays += [
["ditto", "/Applications/Install \(installer.name).app", "\(mountPoint.path)/Applications/Install \(installer.name).app"],
["rm", "-r", "/Applications/Install \(installer.name).app"]
["pkgutil", "--expand-full", packageURL.path, installAssistantExpansionDirectory.path],
["cp", installerCacheDirectoryURL.appendingPathComponent("AppleDiagnostics.chunklist").path, sharedSupportDirectory.path],
["cp", installerCacheDirectoryURL.appendingPathComponent("AppleDiagnostics.dmg").path, sharedSupportDirectory.path],
["cp", installerCacheDirectoryURL.appendingPathComponent("BaseSystem.chunklist").path, sharedSupportDirectory.path],
["cp", installerCacheDirectoryURL.appendingPathComponent("BaseSystem.dmg").path, sharedSupportDirectory.path],
["cp", installerCacheDirectoryURL.appendingPathComponent("InstallESDDmg.pkg").path, sharedSupportDirectory.appendingPathComponent("InstallESD.dmg").path],
["ditto", payloadInstallerApp.path, mountPoint.appendingPathComponent("Applications").appendingPathComponent("Install \(installer.name).app").path],
["rm", "-r", installAssistantExpansionDirectory.path]
]
}

// workaround for macOS Catalina 10.15 and newer
if installer.catalinaOrNewer {
} else {
// Use /usr/sbin/installer for macOS < 15.6
argumentsArrays += [
["ditto", "\(mountPoint.path)Applications", "\(mountPoint.path)/Applications"],
["rm", "-r", "\(mountPoint.path)Applications"]
["installer", "-pkg", packageURL.path, "-target", mountPoint.path]
]

// workaround for macOS High Sierra 10.13, macOS Mojave 10.14 and macOS Catalina 10.15
if installer.highSierraOrNewer, !installer.bigSurOrNewer {
argumentsArrays += [
["ditto", "/Applications/Install \(installer.name).app", "\(mountPoint.path)/Applications/Install \(installer.name).app"],
["rm", "-r", "/Applications/Install \(installer.name).app"]
]
}

// workaround for macOS Catalina 10.15 and newer
if installer.catalinaOrNewer {
argumentsArrays += [
["ditto", "\(mountPoint.path)Applications", "\(mountPoint.path)/Applications"],
["rm", "-r", "\(mountPoint.path)Applications"]
]
}
}

let variables: [String: String] = ["CM_BUILD": "CM_BUILD"]
Expand Down
4 changes: 4 additions & 0 deletions Mist/Model/Installer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,10 @@ struct Installer: Decodable, Hashable, Identifiable {
var containsInstallAssistantPackage: Bool {
packages.contains { $0.filename == "InstallAssistant.pkg" }
}

var containsInstallAssistantAutoPackage: Bool {
packages.contains { $0.filename == "InstallAssistantAuto.pkg" }
}

var temporaryDiskImageMountPointURL: URL {
URL(fileURLWithPath: "/Volumes/\(id)")
Expand Down