Skip to content
Draft
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
6 changes: 6 additions & 0 deletions Scripting/UTM.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,12 @@
<property name="notes" code="NoTe" type="text"
description="User-specified notes."/>

<property name="operating system" code="OpSy" type="text" access="r"
description="Operating system (cannot be changed after creation)."/>

<property name="ipsw" code="IpSw" type="file"
description="Macos recovery IPSW (cannot be changed after creation)."/>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“macOS recovery IPSW”?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to change it to whatever is correct


<property name="memory" code="MeMy" type="integer"
description="RAM size (in mebibytes)."/>

Expand Down
32 changes: 31 additions & 1 deletion Scripting/UTMScriptingCreateCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//

import Foundation
import Virtualization

@MainActor
@objc(UTMScriptingCreateCommand)
Expand Down Expand Up @@ -102,8 +103,29 @@ class UTMScriptingCreateCommand: NSCreateCommand, UTMScriptable {
guard record["name"] as? String != nil else {
throw ScriptingError.nameNotSpecified
}
guard let osString = record["operatingSystem"] as? String else {
throw ScriptingError.osNotSpecified
}
let config = UTMAppleConfiguration()
config.system.boot = try UTMAppleConfigurationBoot(for: .linux)
// validate os
switch osString {
case "macos":
// need ipsw for macos
guard let ipswURL = record["ipsw"] as? URL else {
throw ScriptingError.ipswNotSpecified
}
let image = try await VZMacOSRestoreImage.image(from: ipswURL)
guard let model = image.mostFeaturefulSupportedConfiguration?.hardwareModel else {
throw ScriptingError.ipswNotSupported
}
config.system.macPlatform = UTMAppleConfigurationMacPlatform(newHardware: model)
config.system.boot = try UTMAppleConfigurationBoot(for: .macOS)
config.system.boot.macRecoveryIpswURL = ipswURL
case "linux":
config.system.boot = try UTMAppleConfigurationBoot(for: .linux)
default:
throw ScriptingError.osNotSupported
}
config.virtualization.hasBalloon = true
config.virtualization.hasEntropy = true
config.networks = [UTMAppleConfigurationNetwork()]
Expand Down Expand Up @@ -131,6 +153,10 @@ class UTMScriptingCreateCommand: NSCreateCommand, UTMScriptable {
case configurationNotFound
case nameNotSpecified
case architectureNotSpecified
case osNotSpecified
case osNotSupported
case ipswNotSpecified
case ipswNotSupported

var errorDescription: String? {
switch self {
Expand All @@ -140,6 +166,10 @@ class UTMScriptingCreateCommand: NSCreateCommand, UTMScriptable {
case .configurationNotFound: return NSLocalizedString("A valid configuration must be specified.", comment: "UTMScriptingAppDelegate")
case .nameNotSpecified: return NSLocalizedString("No name specified in the configuration.", comment: "UTMScriptingAppDelegate")
case .architectureNotSpecified: return NSLocalizedString("No architecture specified in the configuration.", comment: "UTMScriptingAppDelegate")
case .osNotSpecified: return NSLocalizedString("No operating system specified in the configuration.", comment: "UTMScriptingAppDelegate")
case .osNotSupported: return NSLocalizedString("This operating system is not supported on your machine", comment: "UTMScriptingAppDelegate")
case .ipswNotSpecified: return NSLocalizedString("No ipsw file specified in the configuration for macos vm", comment: "UTMScriptingAppDelegate")
case .ipswNotSupported: return NSLocalizedString("Your machine does not support running this IPSW.", comment: "UTMScriptingAppDelegate")
}
}
}
Expand Down
Loading