2

I need to update a .dmg (a.k.a. Apple disk image) file by adding a folder to it (it's an OSGI application and I want to add a few more bundles) but I would prefer a platform independent solution. My main code is written in Python but I am also comfortable with Java. Is it possible to to edit a .dmg file like so?

Note that I don't necessarily need to created a /dmg file cause I have one but if the best way is to unpack and then re-pack that works too.

jonalv
  • 5,706
  • 9
  • 45
  • 64

1 Answers1

1

Creating .dmg images elsewhere than on a Mac is not as easy task at least not an easy task to do using free software. And with non-free, it is mostly for-Mac software. I have been there and decided this was a waste of time.

If you are on a mac, using hdiutil is the way to manipulate .dmg

There is a Python wrapper for instance here https://bitbucket.org/al45tair/dmgbuild to give you some ideas.

In most cases you cannot "edit" a .dmg directly, as these are fixed size images AFAICR. You can however resize one: hdiutil resize -size 70m

Then you can mount it and copy you files to it.

If this is a one time operation, you are better off doing it by hand than automating IMHO.

Now there are a few tools that can possibly build on Linux, but I did not evaluate them AND the key issues when not using hdiutils is to create a .dmg that will always be readable on a Mac... You could try: -hfsplus-tools: https://apps.fedoraproject.org/packages/hfsplus-tools -libdmg-hfsplus: https://github.com/planetbeing/libdmg-hfsplus and in Debian too. -hfsutils: available in Linux distros

See also http://www.nathancoulson.com/proj_cross_tools.php for a list of these and this SO question too: How to build a dmg Mac OS X file (on a non-Mac platform)?

Again, YMMV but I was never able to get 100% reliable .dmg created outside of a Mac.

Community
  • 1
  • 1
Philippe Ombredanne
  • 2,017
  • 21
  • 36
  • I was afraid it was like that. But my use-case is not a one-time operation. I guess I will just have to provide an `.app` in a zip if nothing else comes up... – jonalv Jun 03 '16 at 07:39
  • For the packaging of EasyEclipse (a fairly popular Eclipse distro in its time that I maintained in the past), we could only run the build of installers on Mac to build pkg and .dmg. I treid hard then to no avail. The Linux and Windows installers could be created on any platforms (as NSIS for Windows runs ok on Linux and Mac). This is painful but I am not sure there are reliable alternative. Reliability is the key word here. – Philippe Ombredanne Jun 03 '16 at 12:16
  • I update the question with a few pointers to Linux-based tools for .dmg. They may work for you in a controlled environment where you have a limited variability of MacOSX versions where your .dmg will be read. – Philippe Ombredanne Jun 03 '16 at 12:28