Skip to content

Commit

Permalink
MacOS DMG creation update (#14)
Browse files Browse the repository at this point in the history
* Initial attempt for making the resulting DMG better

* Hidden files solved

* DMG to ignored files
  • Loading branch information
vookimedlo authored Jan 19, 2018
1 parent d809f43 commit 79ae24f
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ build/cmake/mac/package
# Installer
*.wixobj
*.wixpdb

*.dmg
100 changes: 94 additions & 6 deletions build/cmake/mac/package.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,96 @@
#!/bin/sh

target=package
rm -rf "$target"
mkdir "$target"
cp -fr ./build/VookiImageViewer.app "$target/"
ln -s /Applications "$target/Applications"
hdiutil create -volname 'VookiImageViewer [https://VookiImageViewer.cz]' -srcfolder "$target/" -ov -format ULFO VookiImageViewer.dmg
set -e;

VOLUME_NAME="VookiImageViewer"
DMG_NAME="VookiImageViewer.dmg"
DMG_TEMP_NAME="tmp-$DMG_NAME"
VOLUME_ICON_FILE="../../../src/resource/openclipart/vookiimageviewericon.icns"
BACKGROUND_FILE="support/vookiimageviewer-dmg-bg.png"

TARGET=package

echo "Removing old files"
rm -f "$DMG_NAME" || true
rm -f "$DMG_TEMP_NAME" || true
rm -rf "$TARGET" || true
mkdir "$TARGET" || true

echo "Creating disk image"
cp -rf ./build/VookiImageViewer.app "$TARGET/"
ln -s /Applications "$TARGET/Applications"
hdiutil create -volname "$VOLUME_NAME" -srcfolder "$TARGET/" -nocrossdev -ov -fs HFS+ -fsargs "-c c=64,a=16,e=16" -format UDRW "$DMG_TEMP_NAME"

echo "Mounting disk image"
MOUNT_DIR="/Volumes/$VOLUME_NAME"
DEV_NAME=`hdiutil attach -readwrite -noverify -noautoopen $DMG_TEMP_NAME | egrep '^/dev/' | sed 1q | awk '{print $1}'`

echo "Setting background image"
test -d "$MOUNT_DIR/.background" || mkdir "$MOUNT_DIR/.background"
cp -f "$BACKGROUND_FILE" "$MOUNT_DIR/.background/background.png"

echo "Setting custom volume icon"
cp -f "$VOLUME_ICON_FILE" "$MOUNT_DIR/.VolumeIcon.icns"

echo "Executing script"
cat <<EOF | /usr/bin/osascript -l JavaScript
var finder = Application("Finder");
var disk = finder.disks["$VOLUME_NAME"];
disk.open();
var window = disk.containerWindow();
window.currentView = "icon view";
window.toolbarVisible = false;
window.statusbarVisible = false;
window.sidebarWidth = 135;
window.bounds = {"x":30, "y":50, "width":550+135, "height":450};
var options = window.iconViewOptions();
options.iconSize = 64;
options.arrangement = "not arranged";
options.backgroundPicture = disk.files[".background:background.png"];
disk.items[".VolumeIcon.icns"].position = {"x":1000, "y":1000};
disk.items[".fseventsd"].position = {"x":1000, "y":1000};
disk.items[".background"].position = {"x":1000, "y":1000};
disk.items["VookiImageViewer.app"].position = {"x":280, "y":130};
disk.items["Applications"].position = {"x":580, "y":130};
disk.update({registeringApplications: false});
delay(2);
window.bounds = {"x":31, "y":50, "width":550+135, "height":450};
window.bounds = {"x":30, "y":50, "width":550+135, "height":450};
disk.update({registeringApplications: false});
delay(2);
disk.close();
var dsStoreFile = disk.files[".DS_Store"];
ObjC.import('Foundation');
var fileManager = $.NSFileManager.defaultManager;
while (!ObjC.unwrap(fileManager.fileExistsAtPath("$MOUNT_DIR/.DS_Store"))) {
// give the finder time to write the .DS_Store file
delay(1);
}
EOF

echo "Setting custom volume icon"
cp -f "$VOLUME_ICON_FILE" "$MOUNT_DIR/.VolumeIcon.icns"
SetFile -c nC "$MOUNT_DIR/.VolumeIcon.icns"
SetFile -a C "$MOUNT_DIR"

echo "Fixing permissions"
chmod -Rf go-w "$MOUNT_DIR" || true

echo "Blessing image"
bless --folder "$MOUNT_DIR" --openfolder "$MOUNT_DIR"

echo "Unmounting disk image"
hdiutil detach "$DEV_NAME"

echo "Compressing disk image"
hdiutil convert "$DMG_TEMP_NAME" -format ULFO -o "$DMG_NAME"
rm -f "$DMG_TEMP_NAME"

echo "Done"

exit 0;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 79ae24f

Please sign in to comment.