How to create nice MacOS DMG installer

In this article I will show how to create DMG installer in reusable way. The most of things and ideas presented here are ideas from several articles mentioned on the end of this article.

1) As first step we need to create our DMG template with link to Applications.
2) Next we have to modify the visual representation of DMG file.
3) Next we store created DMG as template
4) Now mount copied template as directory, fill DMG with real files
5) Detach mounted DMG, pack DMG
6) Distribute app 😉

More detailed info about all these steps you will find in articles mentioned below. Here is a short script I wrote for three-phase deploying (1) create template, 2) pack template, 3)fill template with real data and compress it)

#! /bin/bash

TEMPLATE_DMG=atomix-development-template.dmg
VOLUME_NAME="Atomix Development"
APPLICATION_FILE_NAME="AtomixDevelopment.app"

if [ "$1" = "create-template" ]
then
  echo Create DMG template
  mkdir template
  cd template
  mkdir $APPLICATION_FILE_NAME
  touch $APPLICATION_FILE_NAME/fake
  ln -s /Applications/ Applications
  cd ..
  rm $TEMPLATE_DMG
  rm $TEMPLATE_DMG.bz2
  hdiutil create -fs HFSX -layout SPUD -size 100m "$TEMPLATE_DMG" -srcfolder template -format UDRW -volname "$VOLUME_NAME" -quiet
  rm -rf template
elif [ "$1" = "zip-template" ]
then
  echo Zipping DMG template
  bzip2 "$TEMPLATE_DMG"
elif [ "$1" = "create-dmg" ]
then
  echo Creating DMG file from template and data

  #unzip template
  rm $TEMPLATE_DMG
  bunzip2 -k $TEMPLATE_DMG.bz2

  #create pack path and attach DMG
  PACK_PATH=`pwd`/dmg-pack
  mkdir $PACK_PATH
  hdiutil attach "$TEMPLATE_DMG" -noautoopen -quiet -mountpoint "$PACK_PATH"

  #copy new content to DMG
  cp -r "$2" "$PACK_PATH"
  rm $PACK_PATH/$APPLICATION_FILE_NAME/fake

  #detach DMG, remove mount path
  hdiutil detach "$PACK_PATH" -force -quiet
  rm -rf $PACK_PATH

  #compress DMG
  hdiutil convert -format UDZO -o tmp-packer-output.dmg "$TEMPLATE_DMG" -imagekey zlib-level=9
  rm ./$TEMPLATE_DMG
  mv ./tmp-packer-output.dmg $TEMPLATE_DMG

  #rm $TEMPLATE_DMG
else
  echo Missing parameter
  echo "create-dmg [create|zip-template|create-dmg Path/Application.app]"
fi

So, it looks like that DMG file for ORM Designer2 is ready 😉

Another tools to create DMG package

External links

http://codevarium.gameka.com.br/how-to-create-your-own-beautiful-dmg-files/
http://el-tramo.be/guides/fancy-dmg/
http://stackoverflow.com/questions/96882/how-do-i-create-a-nice-looking-dmg-for-mac-os-x-using-command-line-tools
http://stackoverflow.com/questions/8680132/creating-nice-dmg-installer-for-mac-os-x
http://stackoverflow.com/questions/2104364/how-to-install-a-qt-application-on-a-customers-system

Leave a Reply

Your email address will not be published. Required fields are marked *