Skip to content

Commit

Permalink
rm maid.dmg
Browse files Browse the repository at this point in the history
  • Loading branch information
danemadsen committed Jul 4, 2024
1 parent ae1a564 commit 3cf0cb3
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 18 deletions.
Binary file removed .github/assets/maid.dmg
Binary file not shown.
115 changes: 97 additions & 18 deletions .github/scripts/create_dmg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,112 @@ set -e

APP_NAME="maid"
APP_DIR="build/macos/Build/Products/Release/${APP_NAME}.app"
DMG_TEMPLATE="./.github/assets/maid.dmg"
DMG_OUTPUT="./dmg/${APP_NAME}.dmg"
DMG_DIR="dmg"
TMP_MOUNT="/tmp/Maid"
TMP_DMG="/tmp/${APP_NAME}_tmp.dmg"
DMG_SIZE=1g
DMG_BACKGROUND_IMG="./media/dmg.png"
WINX=0
WINY=0
WINW=700
WINH=1000
ICON_SIZE=64
TEXT_SIZE=12

# Create the dmg directory if it does not exist
mkdir -p "$(dirname ${DMG_OUTPUT})"
# Create the dmg and app directories if they do not exist
mkdir -p ${DMG_DIR}
mkdir -p ${TMP_MOUNT}

# Create a new writable DMG with the specified size
hdiutil create -srcfolder ${DMG_TEMPLATE} -volname "${APP_NAME}" -format UDRW -size ${DMG_SIZE} ${TMP_DMG}
# Create temporary DMG
hdiutil create ${DMG_DIR}/${APP_NAME}_tmp.dmg -volname "${APP_NAME}" -srcfolder "${APP_DIR}" -ov -format UDRW

# Mount the writable DMG
hdiutil attach ${TMP_DMG}.dmg -mountpoint ${TMP_MOUNT} -nobrowse -noverify -noautoopen
# Mount the temporary DMG
hdiutil attach ${DMG_DIR}/${APP_NAME}_tmp.dmg -mountpoint ${TMP_MOUNT}

# Replace the TARGET file with maid.app
rm -rf "${TMP_MOUNT}/TARGET"
cp -R "${APP_DIR}" "${TMP_MOUNT}/maid.app"
# Copy background image
mkdir -p ${TMP_MOUNT}/.background
cp ${DMG_BACKGROUND_IMG} ${TMP_MOUNT}/.background/feature.png

# Unmount the writable DMG
# Create a symbolic link to the Applications folder
ln -s /Applications ${TMP_MOUNT}/Applications

# AppleScript to set DMG properties
osascript <<EOF
on run
tell application "Finder"
tell disk "${APP_NAME}"
open
set theXOrigin to ${WINX}
set theYOrigin to ${WINY}
set theWidth to ${WINW}
set theHeight to ${WINH}
set theBottomRightX to (theXOrigin + theWidth)
set theBottomRightY to (theYOrigin + theHeight)
set dsStore to "\"" & "/Volumes/${APP_NAME}/.DS_Store\""
tell container window
set current view to icon view
set toolbar visible to false
set statusbar visible to false
set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
set statusbar visible to false
end tell
set opts to the icon view options of container window
tell opts
set icon size to ${ICON_SIZE}
set text size to ${TEXT_SIZE}
set arrangement to not arranged
end tell
set background picture of opts to file ".background:feature.png"
-- Positioning
set position of item "${APP_NAME}.app" of container window to {150, 50}
set position of item "Applications" of container window to {150, 300}
close
open
-- Force saving of the size
delay 1
tell container window
set statusbar visible to false
set the bounds to {theXOrigin, theYOrigin, theBottomRightX - 10, theBottomRightY - 10}
end tell
end tell
delay 1
tell disk "${APP_NAME}"
tell container window
set statusbar visible to false
set the bounds to {theXOrigin, theYOrigin, theBottomRightX, theBottomRightY}
end tell
end tell
--give the finder some time to write the .DS_Store file
delay 3
set waitTime to 0
set ejectMe to false
repeat while ejectMe is false
delay 1
set waitTime to waitTime + 1
if (do shell script "[ -f " & dsStore & " ]; echo $?") = "0" then set ejectMe to true
end repeat
log "waited " & waitTime & " seconds for .DS_Store to be created."
end tell
end run
EOF

# Unmount the temporary DMG
hdiutil detach ${TMP_MOUNT}

# Convert the writable DMG to a compressed DMG
hdiutil convert ${TMP_DMG}.dmg -format UDZO -o ${DMG_OUTPUT}
# Convert to final DMG
hdiutil convert ${DMG_DIR}/${APP_NAME}_tmp.dmg -format UDZO -o ${DMG_DIR}/${APP_NAME}.dmg

# Clean up the temporary writable DMG
rm ${TMP_DMG}.dmg
# Remove temporary DMG
rm ${DMG_DIR}/${APP_NAME}_tmp.dmg

echo "DMG creation completed successfully!"

0 comments on commit 3cf0cb3

Please sign in to comment.