Skip to content

How Does AutoDMG Work

Nate Felton edited this page Jul 7, 2017 · 1 revision

This page serves to document the inner workings of AutoDMG, and will be expanded as needed.

Core Script

At the core of AutoDMG is a shell script called installesdtodmg.sh. If you strip away the sanity checks, error handling, and progress reports, you end up with the equivalent of the following commands:

# Mount the install media.
hdiutil attach -noverify -mountpoint /tmp/installesd /Applications/Install\ OS\ X\ Mavericks.app/Contents/SharedSupport/InstallESD.dmg
# Create a sparse read/write disk image.
hdiutil create -size 32g -type SPARSE -fs HFS+J -volname "Macintosh HD" -uid 0 -gid 80 -mode 1775 /tmp/output.sparseimage
# Attach it.
hdiutil attach -noverify -mountpoint /tmp/os -owners on /tmp/output.sparseimage
# Install the OS.
installer -pkg /tmp/installesd/Packages/OSInstall.mpkg -target /tmp/os
# Detach the images.
hdiutil detach /tmp/os
hdiutil detach /tmp/installesd
# Convert the image to read only.
hdiutil convert -format UDZO /tmp/output.sparseimage -o output.dmg
# Scan the image for restore. (Not actually in installesdtodmg.sh!)
asr imagescan --source /tmp/output.dmg

Application Design

AutoDMG is written in Python with PyObjC, and is developed in Xcode.

Important Classes

There are two core classes in AutoDMG:

IEDController

This is the controller class for the main window, and is the root of all interaction with the user.

IEDWorkflow

The workflow is the meat of the application. It's responsible for setting up and executing the steps needed to create an image.

Helper Processes

installesdtodmg.sh

This script performs the main steps needed to create a deployment image:

  1. Create a new read/write sparse disk image.
  2. Install a list of packages, starting with the OS install, with the sparse image as the target.
  3. Convert the sparse disk to a read only compressed image.

progresswatcher.py

This is a python script that executes the helper processes, captures their output, and sends it back to the main user interface.

IPC Protocol

Upon startup the application creates a unix domain datagram socket, and starts listening for packets. When progresswatcher.py has a message for the UI it encapsulates it in a binary plist and writes it to the socket. The listener decodes it and acts according to the "action" key.