mac packaging improvements
This commit is contained in:
5 files changed
+332
-9
No files matched your search
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
# Package macOS build as a .dmg disk image
|
||||
# Package macOS build as a styled .dmg disk image
|
||||
# Usage: package-macos.sh <build-dir> <qt-dir> <output-dir>
|
||||
set -euo pipefail
|
||||
|
||||
@@ -9,17 +9,45 @@ OUTPUT_DIR="${3:?}"
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
PROJECT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
|
||||
|
||||
APP_PATH="$BUILD_DIR/asteria-qt.app"
|
||||
SRC_APP_PATH="$BUILD_DIR/asteria-qt.app"
|
||||
DMG_NAME="Asteria.dmg"
|
||||
VOL_NAME="Asteria"
|
||||
APP_BUNDLE_NAME="Asteria.app"
|
||||
BG_SOURCE="$PROJECT_DIR/packaging/dmg-background.png"
|
||||
ICON_SOURCE="$PROJECT_DIR/src/assets/asteria-qt.icns"
|
||||
CODESIGN="${CODESIGN:-true}"
|
||||
CODESIGN_IDENTITY="${CODESIGN_IDENTITY:--}"
|
||||
|
||||
if [ ! -d "$APP_PATH" ]; then
|
||||
echo "ERROR: App bundle not found at $APP_PATH" >&2
|
||||
if [ ! -d "$SRC_APP_PATH" ]; then
|
||||
echo "ERROR: App bundle not found at $SRC_APP_PATH" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Deploy Qt frameworks into the .app bundle
|
||||
if [ ! -f "$BG_SOURCE" ]; then
|
||||
echo "ERROR: DMG background image not found at $BG_SOURCE" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
WORK_DIR="$(mktemp -d)"
|
||||
STAGING_DIR="$WORK_DIR/staging"
|
||||
RW_DMG="$WORK_DIR/Asteria-rw.dmg"
|
||||
APP_PATH="$STAGING_DIR/$APP_BUNDLE_NAME"
|
||||
MOUNT_DIR=""
|
||||
DEVICE=""
|
||||
|
||||
cleanup() {
|
||||
if [ -n "$DEVICE" ]; then
|
||||
hdiutil detach "$DEVICE" -quiet 2>/dev/null || \
|
||||
hdiutil detach "$DEVICE" -force -quiet 2>/dev/null || true
|
||||
fi
|
||||
rm -rf "$WORK_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
mkdir -p "$STAGING_DIR/.background"
|
||||
ditto "$SRC_APP_PATH" "$APP_PATH"
|
||||
|
||||
# Deploy Qt frameworks into the staged .app bundle
|
||||
"$QT_DIR/bin/macdeployqt" "$APP_PATH" -qmldir="$PROJECT_DIR/src/qml"
|
||||
|
||||
if [ "$CODESIGN" = "true" ]; then
|
||||
@@ -47,9 +75,68 @@ if [ "$CODESIGN" = "true" ]; then
|
||||
codesign --verify --deep --strict --verbose=2 "$APP_PATH"
|
||||
fi
|
||||
|
||||
# Create .dmg directly in output directory
|
||||
# Populate standard macOS drag-to-Applications DMG layout
|
||||
ln -s /Applications "$STAGING_DIR/Applications"
|
||||
cp "$BG_SOURCE" "$STAGING_DIR/.background/dmg-background.png"
|
||||
if [ -f "$ICON_SOURCE" ]; then
|
||||
cp "$ICON_SOURCE" "$STAGING_DIR/.VolumeIcon.icns"
|
||||
fi
|
||||
|
||||
# Create temporary read-write HFS+ DMG to configure Finder metadata
|
||||
hdiutil create -srcfolder "$STAGING_DIR" -volname "$VOL_NAME" \
|
||||
-fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW -ov "$RW_DMG" >/dev/null
|
||||
|
||||
ATTACH_PLIST="$WORK_DIR/attach.plist"
|
||||
hdiutil attach -readwrite -noverify -noautoopen -plist "$RW_DMG" > "$ATTACH_PLIST"
|
||||
|
||||
IFS=$'\t' read -r DEVICE MOUNT_DIR < <(python3 - "$ATTACH_PLIST" <<'PY'
|
||||
import plistlib, sys
|
||||
with open(sys.argv[1], "rb") as f:
|
||||
data = plistlib.load(f)
|
||||
dev = ""
|
||||
mnt = ""
|
||||
for ent in data.get("system-entities", []):
|
||||
if "mount-point" in ent:
|
||||
dev = ent.get("dev-entry", "")
|
||||
mnt = ent["mount-point"]
|
||||
break
|
||||
print(f"{dev}\t{mnt}")
|
||||
PY
|
||||
)
|
||||
|
||||
if [ -z "$DEVICE" ] || [ -z "$MOUNT_DIR" ]; then
|
||||
echo "ERROR: Failed to attach temporary DMG" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Hide background directory and enable custom volume icon
|
||||
if command -v SetFile >/dev/null 2>&1; then
|
||||
SetFile -a V "$MOUNT_DIR/.background" || true
|
||||
if [ -f "$MOUNT_DIR/.VolumeIcon.icns" ]; then
|
||||
SetFile -a V "$MOUNT_DIR/.VolumeIcon.icns" || true
|
||||
SetFile -c icnC "$MOUNT_DIR/.VolumeIcon.icns" || true
|
||||
SetFile -a C "$MOUNT_DIR" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Configure Finder view options and icon coordinates (.DS_Store) without AppleEvents/TCC
|
||||
python3 "$SCRIPT_DIR/generate_ds_store.py" \
|
||||
"$MOUNT_DIR" \
|
||||
"$MOUNT_DIR/.background/dmg-background.png" \
|
||||
"$APP_BUNDLE_NAME"
|
||||
|
||||
if command -v SetFile >/dev/null 2>&1; then
|
||||
SetFile -a V "$MOUNT_DIR/.DS_Store" || true
|
||||
fi
|
||||
|
||||
sync
|
||||
sleep 1
|
||||
hdiutil detach "$DEVICE" >/dev/null || hdiutil detach "$DEVICE" -force >/dev/null
|
||||
DEVICE=""
|
||||
|
||||
# Convert to compressed read-only DMG
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
hdiutil create -volname "Asteria" -srcfolder "$APP_PATH" \
|
||||
-ov -format UDZO "$OUTPUT_DIR/$DMG_NAME"
|
||||
hdiutil convert "$RW_DMG" -format UDZO -imagekey zlib-level=9 -ov -o "$OUTPUT_DIR/$DMG_NAME" >/dev/null
|
||||
hdiutil verify "$OUTPUT_DIR/$DMG_NAME" >/dev/null
|
||||
|
||||
echo "Created: $OUTPUT_DIR/$DMG_NAME"
|
||||
Reference in new issue
Block a user