-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_DMG.sh
More file actions
executable file
·60 lines (49 loc) · 1.78 KB
/
build_DMG.sh
File metadata and controls
executable file
·60 lines (49 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# === CONFIGURATION ===
APP_NAME="MyApp"
VOLUME_NAME="MyApp Installer"
STAGING_DIR="$HOME/dmg-staging"
APP_PATH="/path/to/MyApp.app" # Change this to your .app path
FINAL_DMG="$HOME/Desktop/$APP_NAME.dmg"
TEMP_DMG="$HOME/Desktop/$APP_NAME-temp.dmg"
BACKGROUND_IMAGE="/path/to/background.png" # Optional: leave blank if none
# === PREPARE STAGING FOLDER ===
echo "Preparing staging folder..."
rm -rf "$STAGING_DIR"
mkdir -p "$STAGING_DIR/$APP_NAME"
cp -R "$APP_PATH" "$STAGING_DIR/"
if [ -f "$BACKGROUND_IMAGE" ]; then
mkdir "$STAGING_DIR/.background"
cp "$BACKGROUND_IMAGE" "$STAGING_DIR/.background/"
fi
# === CREATE TEMP READ/WRITE DISK IMAGE ===
echo "Creating temporary read/write disk image..."
hdiutil create -srcfolder "$STAGING_DIR" \
-volname "$VOLUME_NAME" \
-fs HFS+ \
-format UDRW \
"$TEMP_DMG"
# === MOUNT DISK IMAGE ===
echo "Mounting disk image..."
MOUNT_DIR=$(hdiutil attach "$TEMP_DMG" | grep -o '/Volumes/.*')
echo "Mounted at: $MOUNT_DIR"
# === PAUSE FOR CUSTOMIZATION ===
echo "PLEASE DO THE FOLLOWING:"
echo "1. Open Finder to '$MOUNT_DIR'"
echo "2. Arrange icons, set background (View > Show View Options)"
echo " (N.B. Always use Icon View and add any desired background images from inside the mounted DMG using Finder's view options.)"
echo "3. Close the window to save .DS_Store"
read -p "Press [Enter] once done customizing in Finder..."
# === SET PERMISSIONS ===
echo "Setting permissions..."
chmod -Rf go-w "$MOUNT_DIR"
# === UNMOUNT IMAGE ===
echo "Unmounting..."
hdiutil detach "$MOUNT_DIR"
# === CONVERT TO COMPRESSED READ-ONLY DMG ===
echo "Creating final DMG..."
hdiutil convert "$TEMP_DMG" -format UDZO -imagekey zlib-level=9 -o "$FINAL_DMG"
# === CLEANUP ===
rm "$TEMP_DMG"
rm -rf "$STAGING_DIR"
echo "DMG created successfully at: $FINAL_DMG"