Skip to content

Commit

Permalink
Add tools and configs for osx dmg packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
raphendyr committed Feb 21, 2018
1 parent a72062d commit 7a5d71b
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .travis/pre_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ if [ "$BUILD_DIST" = 'true' ]; then
# pyinstaller app image in dmg and zip
(cd simple_gui && ./create_icns_on_osx.sh)
pyinstaller --noconsole --onefile --name Roman --icon simple_gui/roman.icns --osx-bundle-identifier="$appid" simple_gui/roman_tki.py
hdiutil create dist/roman-gui-$version-mac.dmg -srcfolder dist/ -ov
(cd dist && zip -r roman-gui-$version-mac.zip Roman.app)
./packaging/osx/create_dmg.sh dist/roman-gui-$version-mac-unsigned.dmg
(cd dist && zip -r roman-gui-$version-mac-unsigned.zip Roman.app)
else
pip install . simple_gui/
pip install -r requirements_build_linux.txt
Expand Down
35 changes: 35 additions & 0 deletions packaging/osx/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
OS X Packaging
==============

Packing for OS X is bit interesting.
Here are utilities to manage packaging configuration and to create final disk image.

Finder background
-----------------

Disk image is oppened with a Finder window and we use background image to render information texts.
Source file is in `res/dmg-background.svg` and 72DPI and 144DPI renders in `res/dmg-background.png` and `res/[email protected]` respectively.

.DS_Store
---------

DMG installer contains Finder window layout and background in a binary file `.DS_Store`.
Apple has not documented this format.

Tool `setup_volume.sh` is used to create test volume for modifying DS_Store file.
It uses an applescript to create layout.
You can edit the script to test new layout parameters.
Though, resulting DS_Store contains volume mounts and other irrelevant information and thus can not be used for distributing.
For distributable version, there is node script in `createdbstore` directory.

So, first play with the `setup_volume.sh` and applescript to get window that looks correct and then recreate the configuration with `createdbstore`.
Finally, copy `.DS_Store` to `res/DS_store`.

Creating final image
--------------------

Script `create_dmg.sh` creates compressed read-only disk image.
It uses resources from `res` directory.
It requires the destination as parameter.

For example `./packaging/osx/create_dmg.sh dist/roman.dmg`.
47 changes: 47 additions & 0 deletions packaging/osx/create_dmg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/bin/sh -e

scripts=$(dirname "$0")
res=$scripts/res/

out=$1
[ "$out" ] || { echo "ERROR: missing output file"; exit 1; }
dist=$(dirname "$out")

name=Roman
bg1=$res/dmg-background.png
bg2=$res/[email protected]
dss=$res/DS_Store

require_dpi() {
f=$1
i=$2
if [ ! -e "$f" ]; then
echo "ERROR: missing image $f"
exit 1
fi
dpi=$(sips -g dpiHeight "$f" | egrep '^\s*dpiHeight' | awk '{print $2}')
if [ "$dpi" != "$i" ]; then
echo "ERROR: wrong dpi $dpi expected $i, file $f"
exit 1
fi
}

require_dpi "$bg1" "72.000"
require_dpi "$bg2" "144.000"

d=$dist/$name

rm -rf $d
mkdir -p $d/.background/

cp -r $dist/$name.app $d/
cp "$bg1" $d/.background/dmg-background.png
cp "$bg2" $d/.background/[email protected]
cp "$dss" $d/.DS_Store

SetFile -a icnv $d/.background $d/.DS_Store
ln -s /Applications $d/Applications

hdiutil create $out \
-format UDZO -imagekey zlib-level=9 \
-volname $name -srcfolder $d/ -ov
9 changes: 9 additions & 0 deletions packaging/osx/createdsstore/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DS_Store creator
================

This trivial script creates simple .DS_Store file to be used for a disk image layout.
It tool is only needed when size or icon positions of the Finder window changes.
If that happens, then edit the `cli.js` with the new information.
Execute it to obtain a new .DS_Store file.

To install, run `npm install` and to execute run `./cli.js`.
40 changes: 40 additions & 0 deletions packaging/osx/createdsstore/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env node
'use strict';

const fs = require('fs')
const path = require('path')
const DSStore = require('ds-store')

const exit_with_error = (err) => {
console.error(err);
process.exit(1)
}

const create_ds_store = () => {
const ds = new DSStore()

const w = 760
const h = 480
const x = 300
const y = 200
const ixpos = 200
const iypos = 200

ds.vSrn(1)
ds.setIconSize(128)
ds.setBackgroundColor(1, 1, 1)
ds.setBackgroundPath('/Volumes/Roman/.background/dmg-background.png')
ds.setWindowSize(w, h)
ds.setWindowPos(x, y)
ds.setIconPos('Roman.app', ixpos, iypos)
ds.setIconPos('Applications', w-ixpos, iypos)

ds.write('/Volumes/Roman/.DS_Store', (err) => {
if (err)
exit_with_error(err)
else
console.info("Done")
})
}

create_ds_store()
14 changes: 14 additions & 0 deletions packaging/osx/createdsstore/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "createdsstore",
"version": "1.0.0",
"description": "Creates .DS_Store file with hard coded values",
"bin": "./cli.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Jaakko Kantojärvi <[email protected]>",
"license": "ISC",
"dependencies": {
"ds-store": "^0.1.6"
}
}
Binary file added packaging/osx/res/DS_Store
Binary file not shown.
Binary file added packaging/osx/res/dmg-background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 67 additions & 40 deletions packaging/osx/res/dmg-background.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added packaging/osx/res/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions packaging/osx/res/finder_layout.scpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
tell application "Finder"
tell disk "Roman"
open

set theX to 300
set theY to 200
set theW to 760
set theH to 480
set theX2 to (theX + theW)
set theY2 to (theY + theH)
set theI1X to 200
set theI2X to (theW - theI1X)
set theIY to 200

tell container window
set current view to icon view
set toolbar visible to false
set statusbar visible to false
set the bounds to {theX, theY, theX2, theY2}
end tell

set viewOptions to the icon view options of container window
tell viewOptions
set arrangement to not arranged
set icon size to 128
set text size to 14
end tell

set background picture of viewOptions to file ".background:dmg-background.png"
set position of item "Roman.app" of container window to {theI1X, theIY}
set position of item "Applications" of container window to {theI2X, theIY}

close
open
update without registering applications
delay 2
end tell
end tell
Loading

0 comments on commit 7a5d71b

Please sign in to comment.