Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(lume): make fresh unattended VMs Recovery-ready (#2167)

Francesco Bonaccibffb1e21ce07
diff --git a/docs/content/docs/reference/lume/cli-reference.mdx b/docs/content/docs/reference/lume/cli-reference.mdx
index f29ec49041..768b3cb96c 100644
--- a/docs/content/docs/reference/lume/cli-reference.mdx
+++ b/docs/content/docs/reference/lume/cli-reference.mdx
@@ -7,12 +7,12 @@ description: Command Line Interface reference for Lume
AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
Generated by: npx tsx scripts/docs-generators/lume.ts
Source: lume dump-docs --type cli
- Version: 0.3.12
+ Version: 0.3.13
*/}
A lightweight CLI and local API server to build, run and manage macOS VMs.
-Documented against Lume **0.3.12**. Run `lume --version` for your installed version.
+Documented against Lume **0.3.13**. Run `lume --version` for your installed version.
For installation steps, see [Install Lume](/how-to-guides/lume/install-lume).
diff --git a/docs/content/docs/reference/lume/http-api.mdx b/docs/content/docs/reference/lume/http-api.mdx
index dd0cf76151..268fd8d288 100644
--- a/docs/content/docs/reference/lume/http-api.mdx
+++ b/docs/content/docs/reference/lume/http-api.mdx
@@ -7,14 +7,14 @@ description: HTTP API reference for Lume server
AUTO-GENERATED FILE - DO NOT EDIT DIRECTLY
Generated by: npx tsx scripts/docs-generators/lume.ts
Source: lume dump-docs --type api
- Version: 0.3.12
+ Version: 0.3.13
*/}
import { Tabs, Tab } from 'fumadocs-ui/components/tabs';
HTTP API for managing macOS and Linux virtual machines
-Documented against Lume **0.3.12**. Run `lume --version` for your installed version.
+Documented against Lume **0.3.13**. Run `lume --version` for your installed version.
## Default URL
diff --git a/libs/lume/scripts/install.sh b/libs/lume/scripts/install.sh
index 070bbd6dc5..6fbcd69de6 100755
--- a/libs/lume/scripts/install.sh
+++ b/libs/lume/scripts/install.sh
@@ -5,12 +5,12 @@ set -e
# This script installs Lume to your system
# Define colors for output
-BOLD=$(tput bold)
-NORMAL=$(tput sgr0)
-RED=$(tput setaf 1)
-GREEN=$(tput setaf 2)
-BLUE=$(tput setaf 4)
-YELLOW=$(tput setaf 3)
+BOLD=$(tput bold 2>/dev/null || echo "")
+NORMAL=$(tput sgr0 2>/dev/null || echo "")
+RED=$(tput setaf 1 2>/dev/null || echo "")
+GREEN=$(tput setaf 2 2>/dev/null || echo "")
+BLUE=$(tput setaf 4 2>/dev/null || echo "")
+YELLOW=$(tput setaf 3 2>/dev/null || echo "")
# Check if running as root or with sudo
if [ "$(id -u)" -eq 0 ] || [ -n "$SUDO_USER" ]; then
diff --git a/libs/lume/src/Unattended/UnattendedInstaller.swift b/libs/lume/src/Unattended/UnattendedInstaller.swift
index ac52507950..e7ec015496 100644
--- a/libs/lume/src/Unattended/UnattendedInstaller.swift
+++ b/libs/lume/src/Unattended/UnattendedInstaller.swift
@@ -3,6 +3,29 @@ import Foundation
/// Orchestrates unattended macOS installation
@MainActor
final class UnattendedInstaller {
+ // Publish the offline-created administrator to the VM's paired Recovery environment.
+ static let recoveryUserMetadataRefreshCommand = "/usr/sbin/diskutil apfs updatePreboot / >/dev/null"
+
+ static var guestFinalizationScript: String {
+ """
+ set -e
+ /usr/bin/touch /var/db/.AppleSetupDone
+ /usr/sbin/chown root:wheel /var/db/.AppleSetupDone
+ /bin/chmod 644 /var/db/.AppleSetupDone
+ /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser -string lume
+ /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow GuestEnabled -bool false
+ /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow lastUser -string loggedIn
+ /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow lastUserName -string lume
+ /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeCloudSetup -bool true
+ /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeePrivacy -bool true
+ /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeSiriSetup -bool true
+ /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeTouchIDSetup -bool true
+ /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeTrueToneSetup -bool true
+ \(recoveryUserMetadataRefreshCommand)
+ /bin/launchctl enable system/com.openssh.sshd
+ /usr/bin/stat -f 'MARKER_OWNER=%u:%g' /var/db/.AppleSetupDone
+ """
+ }
/// Run unattended setup on a VM by patching the installed macOS disk offline.
func install(
@@ -191,23 +214,7 @@ final class UnattendedInstaller {
let sshClient = SSHClient(host: vmIP, port: 22, user: user, password: password)
let escapedPassword = password.replacingOccurrences(of: "'", with: "'\\''")
- let script = """
- set -e
- /usr/bin/touch /var/db/.AppleSetupDone
- /usr/sbin/chown root:wheel /var/db/.AppleSetupDone
- /bin/chmod 644 /var/db/.AppleSetupDone
- /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser -string lume
- /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow GuestEnabled -bool false
- /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow lastUser -string loggedIn
- /usr/bin/defaults write /Library/Preferences/com.apple.loginwindow lastUserName -string lume
- /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeCloudSetup -bool true
- /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeePrivacy -bool true
- /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeSiriSetup -bool true
- /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeTouchIDSetup -bool true
- /usr/bin/defaults write /Library/Preferences/com.apple.SetupAssistant DidSeeTrueToneSetup -bool true
- /bin/launchctl enable system/com.openssh.sshd
- /usr/bin/stat -f 'MARKER_OWNER=%u:%g' /var/db/.AppleSetupDone
- """
+ let script = Self.guestFinalizationScript
let encodedScript = Data(script.utf8).base64EncodedString()
let command = "printf '%s\\n' '\(escapedPassword)' | /usr/bin/sudo -S /bin/sh -c '/bin/echo \(encodedScript) | /usr/bin/base64 -D | /bin/sh'"
let result = try await sshClient.execute(command: command, timeout: 60)
diff --git a/libs/lume/tests/UnattendedInstallerTests.swift b/libs/lume/tests/UnattendedInstallerTests.swift
new file mode 100644
index 0000000000..1fc377682b
--- /dev/null
+++ b/libs/lume/tests/UnattendedInstallerTests.swift
@@ -0,0 +1,13 @@
+import Testing
+
+@testable import lume
+
+@MainActor
+@Test("guest finalization refreshes Recovery user metadata")
+func guestFinalizationRefreshesPreboot() {
+ let script = UnattendedInstaller.guestFinalizationScript
+
+ #expect(script.contains("/usr/sbin/diskutil apfs updatePreboot / >/dev/null"))
+ #expect(script.contains("/bin/launchctl enable system/com.openssh.sshd"))
+ #expect(script.contains("MARKER_OWNER=%u:%g"))
+}