Also use diskutil in a couple more scripts

This commit is contained in:
Kovid Goyal 2026-09-24 09:32:05 +05:30
parent c6f5f0c89f
commit 3e0b395068
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 56 additions and 4 deletions

View file

@ -144,13 +144,39 @@ linux_install() {
command mv "$tdir/mp" "$dest" || die "Failed to move kitty.app to $dest"
}
has_diskutil_image() {
# hdiutil is deprecated in macOS 27
macos_major=$(command sw_vers -productVersion 2> /dev/null)
macos_major="${macos_major%%.*}"
case "$macos_major" in
''|*[!0-9]*) return 1;;
esac
[ "$macos_major" -ge 27 ]
}
mount_dmg() {
if has_diskutil_image; then
command diskutil image attach --readOnly --mountPoint "$2" "$1"
else
command hdiutil attach "$1" "-mountpoint" "$2"
fi
}
unmount_dmg() {
if has_diskutil_image; then
command diskutil eject "$1"
else
command hdiutil detach "$1"
fi
}
macos_install() {
command mkdir "$tdir/mp"
command hdiutil attach "$installer" "-mountpoint" "$tdir/mp" || die "Failed to mount kitty.dmg"
mount_dmg "$installer" "$tdir/mp" || die "Failed to mount kitty.dmg"
ensure_dest
command ditto -v "$tdir/mp/kitty.app" "$dest"
rc="$?"
command hdiutil detach "$tdir/mp"
unmount_dmg "$tdir/mp"
[ "$rc" != "0" ] && die "Failed to copy kitty.app from mounted dmg"
}

View file

@ -23,6 +23,32 @@ exec_kitty() {
}
has_diskutil_image() {
# hdiutil is deprecated in macOS 27
macos_major=$(command sw_vers -productVersion 2> /dev/null)
macos_major="${macos_major%%.*}"
case "$macos_major" in
''|*[!0-9]*) return 1;;
esac
[ "$macos_major" -ge 27 ]
}
mount_dmg() {
if has_diskutil_image; then
command diskutil image attach --readOnly --mountPoint "$2" "$1"
else
command hdiutil attach "$1" "-mountpoint" "$2"
fi
}
unmount_dmg() {
if has_diskutil_image; then
command diskutil eject "$1"
else
command hdiutil detach "$1"
fi
}
is_wrapped_kitten() {
wrapped_kittens="clipboard icat hyperlinked_grep ask hints unicode_input ssh themes diff show_key transfer query_terminal choose-files command-palette resize_window broadcast remote_file"
[ -n "$1" ] && {
@ -121,10 +147,10 @@ else
[ $? = 0 ] || die "Creating temp directory failed"
fetch "$url" > "$tdir/kitty.dmg"
command mkdir "$tdir/mp"
command hdiutil attach "$tdir/kitty.dmg" "-mountpoint" "$tdir/mp" || die "Failed to mount kitty.dmg"
mount_dmg "$tdir/kitty.dmg" "$tdir/mp" || die "Failed to mount kitty.dmg"
command ditto -v "$tdir/mp/kitty.app" "$install_dir/kitty.app"
rc="$?"
command hdiutil detach "$tdir/mp"
unmount_dmg "$tdir/mp"
command rm -rf "$tdir"
[ "$rc" != "0" ] && die "Failed to copy kitty.app from mounted dmg"
command mkdir "$install_dir/bin"