Skip to content

An open-source remote desktop application designed for self-hosting, as an alternative to TeamViewer.

Fix/macos update dmg eject (#16921)

fufesou817ba32b25c4
diff --git a/src/platform/macos.rs b/src/platform/macos.rs
index d321d12f5..4d7705d38 100644
--- a/src/platform/macos.rs
+++ b/src/platform/macos.rs
@@ -54,6 +54,7 @@ static PRIVILEGES_SCRIPTS_DIR: Dir =
include_dir!("$CARGO_MANIFEST_DIR/src/platform/privileges_scripts");
static mut LATEST_SEED: i32 = 0;
const UPDATE_CLEANUP_FAILED_AFTER_COMMIT: &str = "UPDATE_CLEANUP_FAILED_AFTER_COMMIT";
+const UPDATE_DMG_FALLBACK: &str = "UPDATE_DMG_FALLBACK";
// `kill -9` may not work without administrator privileges.
// App-only update transaction used when launchd jobs are absent or intentionally stopped.
// Keep its verification, staging, bundle rollback, and cleanup aligned with update.scpt.
@@ -67,10 +68,24 @@ const PRIVILEGED_UPDATE_BODY: &str = r#"
set expected_sha256_q to quoted form of expected_sha256
set expected_bundle_id_q to quoted form of expected_bundle_id
+ set detach_dmg to "/usr/bin/hdiutil detach \"$dmg_mount\" -force >/dev/null"
+ set attach_dmg to "/usr/bin/hdiutil attach -readonly -nobrowse -mountpoint \"$dmg_mount\" \"$verified_dmg\" >/dev/null"
+ if expected_sha256 is not "" then
+ -- macOS 27.0 deprecates hdiutil; this is not diskutil's minimum supported version.
+ -- Source: hdiutil(1), WHAT'S NEW: https://keith.github.io/xcode-man-pages/hdiutil.1.html
+ set hdiutil_deprecated_macos_version to 27
+ set macos_major to do shell script "set -e; macos_version=$(/usr/bin/sw_vers -productVersion); printf '%s' \"${macos_version%%.*}\""
+ if (macos_major as integer) >= hdiutil_deprecated_macos_version then
+ -- Preserve command-not-found status despite the parent shell's set -e.
+ set detach_dmg to "( set +e; if /usr/sbin/diskutil eject force \"$dmg_mount\" >/dev/null; then exit 0; else detach_status=$?; fi; command_not_found=127; if [ \"$detach_status\" -eq \"$command_not_found\" ] && [ ! -e /usr/sbin/diskutil ]; then echo 'UPDATE_DMG_FALLBACK'; " & detach_dmg & "; else exit \"$detach_status\"; fi )"
+ set attach_dmg to "( set +e; if /usr/sbin/diskutil image attach --readOnly --nobrowse --mountPoint \"$dmg_mount\" \"$verified_dmg\" >/dev/null; then exit 0; else attach_status=$?; fi; command_not_found=127; if [ \"$attach_status\" -eq \"$command_not_found\" ] && [ ! -e /usr/sbin/diskutil ]; then echo 'UPDATE_DMG_FALLBACK'; " & attach_dmg & "; else exit \"$attach_status\"; fi )"
+ end if
+ end if
+
set check_source to "if [ -n " & expected_sha256_q & " ]; then test -f " & source_path_q & "; else test -d " & source_path_q & "; fi;"
set kill_others to "pids=$(pgrep -x '" & app_name & "' | grep -vx " & cur_pid & " || true); if [ -n \"$pids\" ]; then echo \"$pids\" | xargs kill -9 || true; fi;"
-- Rehash the root-owned copy in a clean environment before staging bytes.
- set prepare_verified to "verified_dir=$(/usr/bin/mktemp -d /tmp/.rustdeskupdate-verified.XXXXXX); /bin/chmod 0700 \"$verified_dir\"; verified_app=\"$verified_dir/" & app_name & ".app\"; dmg_attached=0; if [ -n " & expected_sha256_q & " ]; then verified_dmg=\"$verified_dir/update.dmg\"; /bin/cp " & source_path_q & " \"$verified_dmg\"; /usr/sbin/chown root:wheel \"$verified_dmg\"; /bin/chmod 0400 \"$verified_dmg\"; actual_sha256=$(/usr/bin/env -i /usr/bin/shasum -a 256 \"$verified_dmg\"); actual_sha256=${actual_sha256%% *}; if [ \"$actual_sha256\" != " & expected_sha256_q & " ]; then echo 'Update DMG SHA256 mismatch' >&2; exit 1; fi; dmg_mount=\"$verified_dir/mount\"; /bin/mkdir \"$dmg_mount\"; dmg_attached=1; /usr/bin/hdiutil attach -readonly -nobrowse -mountpoint \"$dmg_mount\" \"$verified_dmg\" >/dev/null; /usr/bin/ditto \"$dmg_mount/" & app_name & ".app\" \"$verified_app\"; /usr/bin/hdiutil detach \"$dmg_mount\" -force >/dev/null; dmg_attached=0; /bin/rm -f \"$verified_dmg\"; else /usr/bin/ditto " & source_path_q & " \"$verified_app\"; fi; /usr/sbin/chown -R root:wheel \"$verified_app\"; /bin/chmod -R go-w \"$verified_app\";"
+ set prepare_verified to "verified_dir=$(/usr/bin/mktemp -d /tmp/.rustdeskupdate-verified.XXXXXX); /bin/chmod 0700 \"$verified_dir\"; verified_app=\"$verified_dir/" & app_name & ".app\"; dmg_attached=0; if [ -n " & expected_sha256_q & " ]; then verified_dmg=\"$verified_dir/update.dmg\"; /bin/cp " & source_path_q & " \"$verified_dmg\"; /usr/sbin/chown root:wheel \"$verified_dmg\"; /bin/chmod 0400 \"$verified_dmg\"; actual_sha256=$(/usr/bin/env -i /usr/bin/shasum -a 256 \"$verified_dmg\"); actual_sha256=${actual_sha256%% *}; if [ \"$actual_sha256\" != " & expected_sha256_q & " ]; then echo 'Update DMG SHA256 mismatch' >&2; exit 1; fi; dmg_mount=\"$verified_dir/mount\"; /bin/mkdir \"$dmg_mount\"; dmg_attached=1; " & attach_dmg & "; /usr/bin/ditto \"$dmg_mount/" & app_name & ".app\" \"$verified_app\"; " & detach_dmg & "; dmg_attached=0; /bin/rm -f \"$verified_dmg\"; else /usr/bin/ditto " & source_path_q & " \"$verified_app\"; fi; /usr/sbin/chown -R root:wheel \"$verified_app\"; /bin/chmod -R go-w \"$verified_app\";"
set validate_verified_app to "candidate_bundle_id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' \"$verified_app/Contents/Info.plist\"); if [ -z " & expected_bundle_id_q & " ] || [ \"$candidate_bundle_id\" != " & expected_bundle_id_q & " ]; then echo 'Update app bundle identifier mismatch' >&2; exit 1; fi; if [ -e " & app_bundle_q & " ]; then installed_bundle_id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' " & installed_info_q & "); if [ \"$installed_bundle_id\" != " & expected_bundle_id_q & " ]; then echo 'Installed app bundle identifier mismatch' >&2; exit 1; fi; fi;"
set prepare_swap_paths to "temp_bundle=" & app_bundle_q & ".new.$$; old_bundle=" & app_bundle_q & ".old.$$;"
set cleanup_swap_paths to "rm -rf \"$temp_bundle\" \"$old_bundle\";"
@@ -80,7 +95,7 @@ const PRIVILEGED_UPDATE_BODY: &str = r#"
set install_staged_bundle to "mv \"$temp_bundle\" " & app_bundle_q & "; bundle_swapped=1;"
set restore_installed_owner to "if [ " & quoted form of restore_owner & " = '1' ]; then chown -R " & user_name_q & ":staff " & app_bundle_q & "; fi;"
set rollback_bundle to "if [ \"${bundle_backed_up:-0}\" -eq 1 ]; then if [ ! -e \"$old_bundle\" ]; then rollback_status=1; elif ! rm -rf " & app_bundle_q & "; then rollback_status=1; elif ! mv \"$old_bundle\" " & app_bundle_q & "; then rollback_status=1; fi; elif [ \"${bundle_swapped:-0}\" -eq 1 ]; then rm -rf " & app_bundle_q & " || rollback_status=1; fi;"
- set cleanup_verified to "if [ \"${dmg_attached:-0}\" -eq 1 ]; then /usr/bin/hdiutil detach \"$dmg_mount\" -force >/dev/null 2>&1 || cleanup_status=1; fi; if [ -n \"${temp_bundle:-}\" ]; then rm -rf \"$temp_bundle\" || cleanup_status=1; fi; if [ -n \"${verified_dir:-}\" ]; then rm -rf \"$verified_dir\" || cleanup_status=1; fi;"
+ set cleanup_verified to "if [ \"${dmg_attached:-0}\" -eq 1 ]; then " & detach_dmg & " || cleanup_status=1; fi; if [ -n \"${temp_bundle:-}\" ]; then rm -rf \"$temp_bundle\" || cleanup_status=1; fi; if [ -n \"${verified_dir:-}\" ]; then rm -rf \"$verified_dir\" || cleanup_status=1; fi;"
set rollback_update to "status=$?; trap - EXIT; set +e; cleanup_status=0; if [ \"${transaction_started:-0}\" -eq 1 ] && [ \"${transaction_committed:-0}\" -ne 1 ]; then rollback_status=0;" & rollback_bundle & "if [ \"$rollback_status\" -ne 0 ]; then status=1; fi; fi; if [ \"${rollback_status:-0}\" -eq 0 ]; then " & cleanup_verified & "fi; if [ \"$cleanup_status\" -ne 0 ] && [ \"${transaction_committed:-0}\" -ne 1 ]; then status=1; elif [ \"$cleanup_status\" -ne 0 ]; then echo 'UPDATE_CLEANUP_FAILED_AFTER_COMMIT'; fi; exit \"$status\";"
set commit_update to "transaction_committed=1; if ! rm -rf \"$old_bundle\"; then echo 'UPDATE_CLEANUP_FAILED_AFTER_COMMIT'; fi;"
set copy_files to prepare_swap_paths & cleanup_swap_paths & stage_bundle & protect_staged_bundle & "transaction_started=1;" & move_current_bundle & install_staged_bundle & restore_installed_owner & commit_update
@@ -299,6 +314,9 @@ fn log_update_cleanup_warning(output: &std::process::Output) {
if String::from_utf8_lossy(&output.stdout).contains(UPDATE_CLEANUP_FAILED_AFTER_COMMIT) {
log::warn!("Update committed, but temporary update cleanup failed");
}
+ if String::from_utf8_lossy(&output.stdout).contains(UPDATE_DMG_FALLBACK) {
+ log::warn!("/usr/sbin/diskutil not found; fell back to hdiutil for DMG operations");
+ }
}
impl UpdateSource {
diff --git a/src/platform/macos/verified_dmg.rs b/src/platform/macos/verified_dmg.rs
index 8fbd802d9..3c89a3a87 100644
--- a/src/platform/macos/verified_dmg.rs
+++ b/src/platform/macos/verified_dmg.rs
@@ -4,10 +4,13 @@ use std::{
io::{self, Write},
os::unix::fs::OpenOptionsExt,
path::{Path, PathBuf},
- process::Command,
+ process::{Command, ExitStatus, Output},
};
const UPDATE_DMG_MOUNT_TEMPLATE: &str = "/tmp/.rustdeskmount-XXXXXX";
+// macOS 27.0 deprecates hdiutil; this is not diskutil's minimum supported version.
+// Source: hdiutil(1), WHAT'S NEW: https://keith.github.io/xcode-man-pages/hdiutil.1.html
+pub(super) const HDIUTIL_DEPRECATED_MACOS_VERSION: u32 = 27;
#[derive(Debug)]
pub(super) struct VerifiedDmg {
@@ -105,10 +108,7 @@ impl DmgGuard {
impl Drop for DmgGuard {
fn drop(&mut self) {
- match Command::new("/usr/bin/hdiutil")
- .args(["detach", self.0.as_str(), "-force"])
- .status()
- {
+ match detach_dmg(&self.0) {
Ok(status) if !status.success() => {
log::warn!("Failed to detach DMG mount {}: {}", self.0, status);
}
@@ -119,20 +119,30 @@ impl Drop for DmgGuard {
}
}
+fn detach_dmg(mount_point: &str) -> io::Result<ExitStatus> {
+ if super::major_version() >= HDIUTIL_DEPRECATED_MACOS_VERSION {
+ match Command::new("/usr/sbin/diskutil")
+ .args(["eject", "force", mount_point])
+ .status()
+ {
+ Err(err) if err.kind() == io::ErrorKind::NotFound => {
+ log::warn!(
+ "/usr/sbin/diskutil not found; falling back to hdiutil: {}",
+ err
+ );
+ }
+ result => return result,
+ }
+ }
+ Command::new("/usr/bin/hdiutil")
+ .args(["detach", mount_point, "-force"])
+ .status()
+}
+
pub(super) fn attach_dmg(dmg_path: &str) -> ResultType<DmgGuard> {
let mount_point = create_dmg_mount_point()?;
// Update images are input only, so never mount them writable.
- let output = match Command::new("/usr/bin/hdiutil")
- .args([
- "attach",
- "-readonly",
- "-nobrowse",
- "-mountpoint",
- mount_point.as_str(),
- dmg_path,
- ])
- .output()
- {
+ let output = match attach_dmg_readonly(dmg_path, &mount_point) {
Ok(output) => output,
Err(err) => {
remove_dmg_mount_point(&mount_point);
@@ -150,6 +160,41 @@ pub(super) fn attach_dmg(dmg_path: &str) -> ResultType<DmgGuard> {
Ok(DmgGuard(mount_point))
}
+fn attach_dmg_readonly(dmg_path: &str, mount_point: &str) -> io::Result<Output> {
+ if super::major_version() >= HDIUTIL_DEPRECATED_MACOS_VERSION {
+ match Command::new("/usr/sbin/diskutil")
+ .args([
+ "image",
+ "attach",
+ "--readOnly",
+ "--nobrowse",
+ "--mountPoint",
+ mount_point,
+ dmg_path,
+ ])
+ .output()
+ {
+ Err(err) if err.kind() == io::ErrorKind::NotFound => {
+ log::warn!(
+ "/usr/sbin/diskutil not found; falling back to hdiutil: {}",
+ err
+ );
+ }
+ result => return result,
+ }
+ }
+ Command::new("/usr/bin/hdiutil")
+ .args([
+ "attach",
+ "-readonly",
+ "-nobrowse",
+ "-mountpoint",
+ mount_point,
+ dmg_path,
+ ])
+ .output()
+}
+
pub(super) fn create_dmg_mount_point() -> ResultType<String> {
let output = Command::new("/usr/bin/mktemp")
.args(["-d", UPDATE_DMG_MOUNT_TEMPLATE])
diff --git a/src/platform/macos/verified_dmg_tests.rs b/src/platform/macos/verified_dmg_tests.rs
index eb1b21435..bbb74fe0c 100644
--- a/src/platform/macos/verified_dmg_tests.rs
+++ b/src/platform/macos/verified_dmg_tests.rs
@@ -1,11 +1,12 @@
use super::{
verified_dmg::{
- copy_and_verify_dmg_file, extract_dmg_inner, verified_dmg_path, verify_stored_dmg,
- VerifiedDmg,
+ attach_dmg, copy_and_verify_dmg_file, extract_dmg_inner, verified_dmg_path,
+ verify_stored_dmg, VerifiedDmg, HDIUTIL_DEPRECATED_MACOS_VERSION,
},
verified_dmg_update_source, ResultType,
};
use std::{
+ os::unix::fs::MetadataExt,
path::{Path, PathBuf},
process::Command,
};
@@ -20,8 +21,20 @@ fn create_test_dmg(test_dir: &Path) -> PathBuf {
std::fs::create_dir_all(&app_dir).unwrap();
std::fs::write(app_dir.join("marker"), TEST_DMG_MARKER).unwrap();
let dmg_path = test_dir.join("update.dmg");
- let output = Command::new("/usr/bin/hdiutil")
- .args(["create", "-quiet", "-format", "UDZO", "-srcfolder"])
+ let (program, args): (&str, &[&str]) =
+ if super::major_version() >= HDIUTIL_DEPRECATED_MACOS_VERSION {
+ (
+ "/usr/sbin/diskutil",
+ &["image", "create", "from", "--format", "UDZO"],
+ )
+ } else {
+ (
+ "/usr/bin/hdiutil",
+ &["create", "-quiet", "-format", "UDZO", "-srcfolder"],
+ )
+ };
+ let output = Command::new(program)
+ .args(args)
.arg(&source_dir)
.arg(&dmg_path)
.output()
@@ -72,6 +85,34 @@ fn verified_dmg_extracts_from_named_copy() {
assert_eq!(marker.unwrap(), TEST_DMG_MARKER);
}
+#[test]
+fn verified_dmg_guard_ejects_on_drop() {
+ let test_dir = std::env::temp_dir().join(format!(
+ "rustdesk-verified-dmg-eject-test-{}-{}",
+ std::process::id(),
+ hbb_common::rand::random::<u64>()
+ ));
+ let dmg_path = create_test_dmg(&test_dir);
+ let guard = attach_dmg(&dmg_path.to_string_lossy()).unwrap();
+ let mount_point = PathBuf::from(guard.mount_point());
+ assert_ne!(
+ std::fs::metadata(&mount_point).unwrap().dev(),
+ std::fs::metadata(mount_point.parent().unwrap())
+ .unwrap()
+ .dev(),
+ "DMG must be mounted before dropping its guard"
+ );
+
+ drop(guard);
+ let mount_metadata = std::fs::symlink_metadata(&mount_point);
+ std::fs::remove_dir_all(test_dir).unwrap();
+
+ assert!(
+ matches!(mount_metadata, Err(ref err) if err.kind() == std::io::ErrorKind::NotFound),
+ "DMG mount was not removed: {mount_metadata:?}"
+ );
+}
+
#[test]
fn verified_dmg_rejects_replaced_path() {
let test_dir = std::env::temp_dir().join(format!(
diff --git a/src/platform/privileges_scripts/update.scpt b/src/platform/privileges_scripts/update.scpt
index 8c02918f6..f78fc293b 100644
--- a/src/platform/privileges_scripts/update.scpt
+++ b/src/platform/privileges_scripts/update.scpt
@@ -16,9 +16,23 @@ on run {user, cur_pid, source_path, expected_sha256}
set expected_sha256_q to quoted form of expected_sha256
set daemon_plist_q to quoted form of daemon_plist
set daemon_target_q to quoted form of ("system/" & daemon_label)
+ set detach_dmg to "/usr/bin/hdiutil detach \"$dmg_mount\" -force >/dev/null"
+ set attach_dmg to "/usr/bin/hdiutil attach -readonly -nobrowse -mountpoint \"$dmg_mount\" \"$verified_dmg\" >/dev/null"
+ if expected_sha256 is not "" then
+ -- macOS 27.0 deprecates hdiutil; this is not diskutil's minimum supported version.
+ -- Source: hdiutil(1), WHAT'S NEW: https://keith.github.io/xcode-man-pages/hdiutil.1.html
+ set hdiutil_deprecated_macos_version to 27
+ set macos_major to do shell script "set -e; macos_version=$(/usr/bin/sw_vers -productVersion); printf '%s' \"${macos_version%%.*}\""
+ if (macos_major as integer) >= hdiutil_deprecated_macos_version then
+ -- Preserve command-not-found status despite the parent shell's set -e.
+ set detach_dmg to "( set +e; if /usr/sbin/diskutil eject force \"$dmg_mount\" >/dev/null; then exit 0; else detach_status=$?; fi; command_not_found=127; if [ \"$detach_status\" -eq \"$command_not_found\" ] && [ ! -e /usr/sbin/diskutil ]; then echo 'UPDATE_DMG_FALLBACK'; " & detach_dmg & "; else exit \"$detach_status\"; fi )"
+ set attach_dmg to "( set +e; if /usr/sbin/diskutil image attach --readOnly --nobrowse --mountPoint \"$dmg_mount\" \"$verified_dmg\" >/dev/null; then exit 0; else attach_status=$?; fi; command_not_found=127; if [ \"$attach_status\" -eq \"$command_not_found\" ] && [ ! -e /usr/sbin/diskutil ]; then echo 'UPDATE_DMG_FALLBACK'; " & attach_dmg & "; else exit \"$attach_status\"; fi )"
+ end if
+ end if
+
set check_source to "if [ -n " & expected_sha256_q & " ]; then test -f " & source_path_q & "; else test -d " & source_path_q & "; fi;"
-- Rehash the root-owned copy in a clean environment before staging bytes.
- set prepare_verified to "verified_dir=$(/usr/bin/mktemp -d /tmp/.rustdeskupdate-verified.XXXXXX); /bin/chmod 0700 \"$verified_dir\"; verified_app=\"$verified_dir/RustDesk.app\"; dmg_attached=0; if [ -n " & expected_sha256_q & " ]; then verified_dmg=\"$verified_dir/update.dmg\"; /bin/cp " & source_path_q & " \"$verified_dmg\"; /usr/sbin/chown root:wheel \"$verified_dmg\"; /bin/chmod 0400 \"$verified_dmg\"; actual_sha256=$(/usr/bin/env -i /usr/bin/shasum -a 256 \"$verified_dmg\"); actual_sha256=${actual_sha256%% *}; if [ \"$actual_sha256\" != " & expected_sha256_q & " ]; then echo 'Update DMG SHA256 mismatch' >&2; exit 1; fi; dmg_mount=\"$verified_dir/mount\"; /bin/mkdir \"$dmg_mount\"; dmg_attached=1; /usr/bin/hdiutil attach -readonly -nobrowse -mountpoint \"$dmg_mount\" \"$verified_dmg\" >/dev/null; /usr/bin/ditto \"$dmg_mount/RustDesk.app\" \"$verified_app\"; /usr/bin/hdiutil detach \"$dmg_mount\" -force >/dev/null; dmg_attached=0; /bin/rm -f \"$verified_dmg\"; else /usr/bin/ditto " & source_path_q & " \"$verified_app\"; fi; /usr/sbin/chown -R root:wheel \"$verified_app\"; /bin/chmod -R go-w \"$verified_app\";"
+ set prepare_verified to "verified_dir=$(/usr/bin/mktemp -d /tmp/.rustdeskupdate-verified.XXXXXX); /bin/chmod 0700 \"$verified_dir\"; verified_app=\"$verified_dir/RustDesk.app\"; dmg_attached=0; if [ -n " & expected_sha256_q & " ]; then verified_dmg=\"$verified_dir/update.dmg\"; /bin/cp " & source_path_q & " \"$verified_dmg\"; /usr/sbin/chown root:wheel \"$verified_dmg\"; /bin/chmod 0400 \"$verified_dmg\"; actual_sha256=$(/usr/bin/env -i /usr/bin/shasum -a 256 \"$verified_dmg\"); actual_sha256=${actual_sha256%% *}; if [ \"$actual_sha256\" != " & expected_sha256_q & " ]; then echo 'Update DMG SHA256 mismatch' >&2; exit 1; fi; dmg_mount=\"$verified_dir/mount\"; /bin/mkdir \"$dmg_mount\"; dmg_attached=1; " & attach_dmg & "; /usr/bin/ditto \"$dmg_mount/RustDesk.app\" \"$verified_app\"; " & detach_dmg & "; dmg_attached=0; /bin/rm -f \"$verified_dmg\"; else /usr/bin/ditto " & source_path_q & " \"$verified_app\"; fi; /usr/sbin/chown -R root:wheel \"$verified_app\"; /bin/chmod -R go-w \"$verified_app\";"
set validate_verified_app to "installed_bundle_id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' " & installed_info_q & "); candidate_bundle_id=$(/usr/libexec/PlistBuddy -c 'Print :CFBundleIdentifier' \"$verified_app/Contents/Info.plist\"); if [ -z \"$installed_bundle_id\" ] || [ -z \"$candidate_bundle_id\" ] || [ \"$installed_bundle_id\" != \"$candidate_bundle_id\" ]; then echo 'Update app bundle identifier mismatch' >&2; exit 1; fi;"
set resolve_uid to "uid=$(id -u " & quoted form of user & ");"
set unload_agent to "if [ -n \"$uid\" ]; then launchctl bootout gui/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl bootout user/$uid " & quoted form of agent_plist & " 2>/dev/null || launchctl unload -w " & quoted form of agent_plist & " || true; else launchctl unload -w " & quoted form of agent_plist & " || true; fi;"
@@ -40,7 +54,7 @@ on run {user, cur_pid, source_path, expected_sha256}
set install_staged_bundle to "mv \"$temp_bundle\" " & quoted form of app_bundle & "; bundle_swapped=1;"
set rollback_bundle to "if [ \"${bundle_backed_up:-0}\" -eq 1 ]; then if [ ! -e \"$old_bundle\" ]; then rollback_status=1; elif ! rm -rf " & quoted form of app_bundle & "; then rollback_status=1; elif ! mv \"$old_bundle\" " & quoted form of app_bundle & "; then rollback_status=1; fi; elif [ \"${bundle_swapped:-0}\" -eq 1 ]; then rm -rf " & quoted form of app_bundle & " || rollback_status=1; fi;"
set rollback_plists to "if [ \"${daemon_plist_existed:-0}\" -eq 1 ]; then cp -p \"$daemon_plist_backup\" " & daemon_plist_q & " || rollback_status=1; else rm -f " & daemon_plist_q & " || rollback_status=1; fi; if [ \"${agent_plist_existed:-0}\" -eq 1 ]; then cp -p \"$agent_plist_backup\" " & quoted form of agent_plist & " || rollback_status=1; else rm -f " & quoted form of agent_plist & " || rollback_status=1; fi;"
- set cleanup_verified to "if [ \"${dmg_attached:-0}\" -eq 1 ]; then /usr/bin/hdiutil detach \"$dmg_mount\" -force >/dev/null 2>&1 || cleanup_status=1; fi; if [ -n \"${temp_bundle:-}\" ]; then rm -rf \"$temp_bundle\" || cleanup_status=1; fi; if [ -n \"${verified_dir:-}\" ]; then rm -rf \"$verified_dir\" || cleanup_status=1; fi;"
+ set cleanup_verified to "if [ \"${dmg_attached:-0}\" -eq 1 ]; then " & detach_dmg & " || cleanup_status=1; fi; if [ -n \"${temp_bundle:-}\" ]; then rm -rf \"$temp_bundle\" || cleanup_status=1; fi; if [ -n \"${verified_dir:-}\" ]; then rm -rf \"$verified_dir\" || cleanup_status=1; fi;"
-- Generate plist definitions from the installed release that will run them.
set write_new_plists to "write_new_plists() { " & quoted form of service_executable & " --write-plists & write_pid=$!; for _ in $(/usr/bin/seq 1 " & write_plist_attempts & "); do if ! kill -0 \"$write_pid\" 2>/dev/null; then wait \"$write_pid\"; return $?; fi; sleep 1; done; kill -TERM \"$write_pid\" 2>/dev/null || true; sleep 1; kill -KILL \"$write_pid\" 2>/dev/null || true; wait \"$write_pid\" 2>/dev/null || true; return 124; }; write_new_plists;"