mkdmg.pl: MacOSX Disk Image Script

about | archive


[ 2003-May-30 16:09 ]

Inspired by the createDiskImage script mentioned by an article on creating disk images as part of the build process, this Perl script will create a compressed disk image from a list of files. The script refuses to run if the image already exists and will clean up all of its temporary files correctly if something fails. It is used by Fink to build their disk images.

Download mkdmg

Usage

mkdmg has two modes: command line mode and script mode. In command line mode, mkdmg acts like tar: it packages a list of files into a compressed disk image. In script mode, mkdmg will create the specified disk image using "source, destination" pairs in the supplied script files. This mode can use shell metacharacters to find files and can place them in arbitrary locations in the disk image.

Example of Command Line Mode:

./mkdmg.pl out file1 file2 file3 file4

Creates a disk imaged called out.dmg (or out.dmg.bz2, depending on the compression settings) containing files: file1 file2 file3 file4. The files can be directories, their contents will be copied recursively into the disk image.

Example of Script Mode:

./mkdmg.pl -s RowResizableViews imagescript

Contents of imagescript:

*.[chm] source/
*.pl source/
English.lproj/*.* source/English.lproj/
RowResizableViews.pbproj/project.pbxproj source/RowResizableViews.pbproj/ build/*.app .

This is the script used by RowResizableViews to build a disk image including the binary and the source code, with the source code relocated to the source subdirectory of the disk image. Specific shell patterns are used to avoid including the CVS subdirectories that exist.

Integrating mkdmg.pl with Project Builder

This tool was created to automate the creation of disk images, and to do it in a safe and reliable fashion. To achieve this goal, the script refuses to run if any of the temporary files it uses exists, and will detect and clean up after itself if anything fails. This means that it is ideal to integrate with Project Builder. For an example project which integrates mkdmg, see RowResizableViews. Here is how add mkdmg to a Project Builder project:

  1. Copy mkdmg to your project's source code directory.
  2. Open your project. Click the Targets tab and click on the target you wish mkdmg to act on. Expand the Build Phases tree node if it is not already. Select Project -> New Build Phase -> New Shell Script Build Phase from the menu. If it is not activated, you need to click on Build Phases to focus on it.
  3. Move the Shell Script Files phase down to the very bottom of the application, so mkdmg will be run after the executable has been built.
  4. Change Script to the command you want to run. The following command will package your applications into a disk image of the same name: ./mkdmg.pl $TARGET_NAME.dmg.bz2 $TARGET_BUILD_DIR/*.app

Resources