Compare commits
2 Commits
9e0e1b2873
...
b0cec977a5
| Author | SHA1 | Date | |
|---|---|---|---|
| b0cec977a5 | |||
| 41d39b9bf7 |
@ -337,8 +337,32 @@ main() {
|
|||||||
create_launchers
|
create_launchers
|
||||||
validate_package
|
validate_package
|
||||||
create_zip
|
create_zip
|
||||||
|
create_dmg
|
||||||
|
|
||||||
log INFO "Done. Package available at $PACKAGE_DIR"
|
log INFO "Done. Package available at $PACKAGE_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_dmg() {
|
||||||
|
if [[ -z ${APP_BUNDLE_PATH:-} ]]; then
|
||||||
|
log INFO "No app bundle detected; skipping DMG creation"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local app_name="${APP_BUNDLE_PATH##*/}"
|
||||||
|
local dmg_name="TetrisGame-mac-${VERSION}.dmg"
|
||||||
|
local dmg_path="$OUTPUT_DIR/$dmg_name"
|
||||||
|
|
||||||
|
if [[ ! -f "scripts/create-dmg.sh" ]]; then
|
||||||
|
log WARN "scripts/create-dmg.sh not found; skipping DMG creation"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
log INFO "Creating DMG installer: $dmg_path"
|
||||||
|
bash scripts/create-dmg.sh "$PACKAGE_DIR/$app_name" "$dmg_path" || log WARN "DMG creation failed"
|
||||||
|
|
||||||
|
if [[ -f "$dmg_path" ]]; then
|
||||||
|
log OK "DMG created: $dmg_path"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
main "$@"
|
main "$@"
|
||||||
|
|||||||
72
scripts/create-dmg.sh
Normal file
72
scripts/create-dmg.sh
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Create a distributable DMG for the macOS Tetris app
|
||||||
|
# Usage: ./scripts/create-dmg.sh <app-bundle-path> <output-dmg>
|
||||||
|
# Example: ./scripts/create-dmg.sh dist/TetrisGame-mac/tetris.app dist/TetrisGame.dmg
|
||||||
|
|
||||||
|
if [[ $# -lt 2 ]]; then
|
||||||
|
echo "Usage: $0 <app-bundle-path> <output-dmg>"
|
||||||
|
echo "Example: $0 dist/TetrisGame-mac/tetris.app dist/TetrisGame.dmg"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
APP_BUNDLE="$1"
|
||||||
|
OUTPUT_DMG="$2"
|
||||||
|
|
||||||
|
if [[ ! -d "$APP_BUNDLE" ]]; then
|
||||||
|
echo "Error: App bundle not found at $APP_BUNDLE" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ ! "$APP_BUNDLE" =~ \.app$ ]]; then
|
||||||
|
echo "Error: First argument must be a .app bundle" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Remove existing DMG if present
|
||||||
|
rm -f "$OUTPUT_DMG"
|
||||||
|
|
||||||
|
APP_NAME=$(basename "$APP_BUNDLE" .app)
|
||||||
|
VOLUME_NAME="$APP_NAME"
|
||||||
|
TEMP_DMG="${OUTPUT_DMG%.dmg}-temp.dmg"
|
||||||
|
|
||||||
|
echo "[create-dmg] Creating temporary DMG..."
|
||||||
|
# Create a temporary read-write DMG (generous size to fit the app + padding)
|
||||||
|
hdiutil create -size 200m -fs HFS+ -volname "$VOLUME_NAME" "$TEMP_DMG"
|
||||||
|
|
||||||
|
echo "[create-dmg] Mounting temporary DMG..."
|
||||||
|
MOUNT_DIR=$(hdiutil attach "$TEMP_DMG" -nobrowse | grep "/Volumes/$VOLUME_NAME" | awk '{print $3}')
|
||||||
|
|
||||||
|
if [[ -z "$MOUNT_DIR" ]]; then
|
||||||
|
echo "Error: Failed to mount temporary DMG" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[create-dmg] Copying app bundle to DMG..."
|
||||||
|
cp -R "$APP_BUNDLE" "$MOUNT_DIR/"
|
||||||
|
|
||||||
|
# Create Applications symlink for drag-and-drop installation
|
||||||
|
echo "[create-dmg] Creating Applications symlink..."
|
||||||
|
ln -s /Applications "$MOUNT_DIR/Applications"
|
||||||
|
|
||||||
|
# Set custom icon if available
|
||||||
|
VOLUME_ICON="$APP_BUNDLE/Contents/Resources/AppIcon.icns"
|
||||||
|
if [[ -f "$VOLUME_ICON" ]]; then
|
||||||
|
echo "[create-dmg] Setting custom volume icon..."
|
||||||
|
cp "$VOLUME_ICON" "$MOUNT_DIR/.VolumeIcon.icns"
|
||||||
|
SetFile -c icnC "$MOUNT_DIR/.VolumeIcon.icns" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Unmount
|
||||||
|
echo "[create-dmg] Ejecting temporary DMG..."
|
||||||
|
hdiutil detach "$MOUNT_DIR"
|
||||||
|
|
||||||
|
# Convert to compressed read-only DMG
|
||||||
|
echo "[create-dmg] Converting to compressed DMG..."
|
||||||
|
hdiutil convert "$TEMP_DMG" -format UDZO -o "$OUTPUT_DMG"
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -f "$TEMP_DMG"
|
||||||
|
|
||||||
|
echo "[create-dmg] Created: $OUTPUT_DMG"
|
||||||
Reference in New Issue
Block a user