Skip to content

Instantly share code, notes, and snippets.

@metasim
Created January 2, 2012 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metasim/1552175 to your computer and use it in GitHub Desktop.
Save metasim/1552175 to your computer and use it in GitHub Desktop.
Disk image creation fragment
<!-- Fragment from an Ant build.xml file for creating a disk image with bells and whistles. -->
<property name="dmgname" value="${build.dir}/install-${name}.dmg" />
<property name="tmpdmg" value="/tmp/${app.name}-installer-tmp.dmg" />
<property name="volname" value="${app.name}-${VERSION}-Install" />
<delete file="${tmpdmg}" quiet="yes" failonerror="false" />
<!-- Create the temporary image -->
<echo>Making initial image...</echo>
<exec executable="hdiutil" failonerror="yes" os="Mac OS X">
<arg value="create" />
<arg value="-srcfolder" />
<arg value="${macos.root.dir}" />
<arg value="-volname" />
<arg value="${volname}" />
<arg value="-ov" />
<arg value="${tmpdmg}" />
<arg value="-format" />
<arg value="UDRW" />
</exec>
<property name="mnt" value="/tmp" />
<property name="mntvol" value="/tmp/${volname}" />
<!-- Attach the temporary image -->
<exec executable="/usr/bin/hdiutil" os="Mac OS X" failonerror="true">
<arg value="attach" />
<arg value="${tmpdmg}" />
<arg value="-mountroot" />
<arg value="${mnt}" />
</exec>
<echo>Tweaking image look...</echo>
<!-- Copy the background, the volume icon and DS_Store files -->
<mkdir dir="${mntvol}/.background" />
<copy file="${resources.dir}/images/installer-background.png"
tofile="${mntvol}/.background/background.png"
verbose="yes"
overwrite="true" />
<copy file="${resources.dir}/images/my-volume-icon.icns"
tofile="${mntvol}/.VolumeIcon.icns"
verbose="yes"
overwrite="true" />
<copy file="${resources.dir}/My_DS_Store" tofile="${mntvol}/.DS_Store" verbose="yes" overwrite="true" />
<!-- Indicate that we want a custom icon -->
<exec executable="/Developer/Tools/SetFile" os="Mac OS X" failonerror="true">
<arg value="-a" />
<arg value="C" />
<arg value="${mntvol}" />
</exec>
<!-- Add a symbolic link to the Applications directory -->
<symlink link="${mntvol}" resource="/Applications" />
<!-- Get the dmg to auto-open on mounting -->
<echo>Making image auto-open...</echo>
<exec executable="bless" os="Mac OS X" failonerror="true">
<arg value="-folder" />
<arg value="${mntvol}" />
<arg value="-openfolder" />
<arg value="${mntvol}" />
</exec>
<!-- Detach the temporary image -->
<exec executable="hdiutil" os="Mac OS X" failonerror="true">
<arg value="detach" />
<arg value="${mntvol}" />
</exec>
<!-- Compress it to a new image -->
<echo>Compressing image...</echo>
<exec executable="hdiutil" os="Mac OS X" failonerror="true">
<arg value="convert" />
<arg value="${tmpdmg}" />
<arg value="-format" />
<arg value="UDZO" />
<arg value="-ov" />
<arg value="-o" />
<arg value="${dmgname}" />
</exec>
<!-- Set custom folder icon (requires locally available tool)-->
<exec executable="${resources.dir}/tools/seticon" os="Mac OS X" failonerror="false">
<arg value="-d" />
<arg value="${resources.dir}/images/my-volume-icon.icns" />
<arg value="${dmgname}" />
</exec>
<!-- Delete the temporary image -->
<!-- Comment out the following line to keep temp image around to
customize the background, layout, etc. and copy the .DS_Store
file to My_DS_Store. -->
<delete file="${tmpdmg}" quiet="yes" failonerror="false" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment