The .dmg disk image is a particularly tricky format. The main reason for this is that a .dmg file must be mounted by the macOS file system before the installation files contained within it can be examined and installed.
For this reason, Addigy recommends that you remove .pkg installations from within the .dmg and upload them individually when at all possible.
However, sometimes the software will require installation from within the .dmg volume. In this case, you will need to generate your own Installation script. The other steps for this Smart Software should mirror the .pkg installation described in our article Creating Smart Software.
In our example, we’ll be installing Firefox. Specifically, Firefox 75.0.dmg has a ".app" file inside of the .dmg file.
I've entered the basic information of the Smart Software item and already uploaded the .dmg file.
All that's left are the scripts.
To install from a .dmg we need to accomplish these three major steps:
1) Mount the .dmg file.
2) Install files and software from the mounted volume.
3) Unmount the .dmg file.
Steps 1 and 3 are largely the same for every .dmg installation, all that needs to be changed are the paths for the commands to work.
Here's the Installation Script that performs all these steps:
hdiutil attach -nobrowse "/Library/Addigy/ansible/packages/Firefox Example (75.0.0)/Firefox 75.0.dmg" cp -R /Volumes/Firefox/Firefox.app /Applications/ sudo hdiutil detach /Volumes/Firefox/
Note: Since I’ve used Firefox for my example, be sure to change the directory names to match your Smart Software and file names.
If you're unsure where to get the Smart Software directory, you can find it at the top of the Edit Software page.
Don't forget to put the .dmg file path in after the Smart Software name, and if there are spaces in the directory, be sure to add quotes just like the example below:
"/Library/Addigy/ansible/packages/My Smart Software (1.0.0)/My DMG.dmg"
The Condition script for this software is quite simple. It checks to see if the software we installed is in the correct folder.
if [ -f '/Applications/Firefox.app' ]; then exit 1 fi exit 0
The Condition Script for your Smart Software will likely be very different, but even a simple script similar to this which checks for existing files can serve as a perfectly good Condition.
If you'd also like to ensure the removal of your Smart Software when a device is removed from the appropriate policy, you may want to add a Removal script to the Smart Software payload.
How would I get the volume information for the second and third lines?
Let's use Firefox as an example again. When you expand a DMG file, there will be another file within it. To know what volume is being mounted, you'd need to drag that file into a terminal and get that path.
For example, when expanding FireFox's DMG file, you get the below, a .app file:
Here is a quick gif on how to get the volume path of a .app file using terminal:
From there, you'd add cp -R (This command will copy a file) in front of /Volumes/Firefox/FireFox.app and then the directory you want to copy the .app file to, in most cases, it will be the /Applications directory.
What if there's a .pkg file inside of the DMG?
Don't panic, we have you covered! If you find a .pkg when you expand a .dmg file, you'd use the same terminal workflow above, except, you will put the directory you get from a terminal, into the following snippet so that the .pkg file runs in the second line. In this case, you will not need to cp command:
Here is the snippet:
installer -pkg OUTPUT_FROM_TERMINAL_GOES_HERE -target /
You'd only need to replace OUTPUT_FROM_TERMINAL_GOES_HERE with what you've got in the terminal, here is what the snippet would be using the above example:
installer -pkg /Volumes/Deep\ Instinct\ 1/\ .pkg -target /
How do I know what directory to detach?
The last line of the example includes the command to detach the DMG file after files are run.
Referring to our Firefox example, the volume we'd want to detach is /Volumes/Firefox/
The volume that you include there will always be what's before the .pkg or .app.
If you have any questions, please do not hesitate to reach out to us by contacting firstname.lastname@example.org