macos 如何构建 dmg Mac OS X 文件(在非 Mac 平台上)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/286419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 05:58:23  来源:igfitidea点击:

How to build a dmg Mac OS X file (on a non-Mac platform)?

macosinstallerdmg

提问by michelemarcon

Is it possible to build a .dmg file (for distributing apps) from a non-Mac platform? And if yes, how?

是否可以从非 Mac 平台构建 .dmg 文件(用于分发应用程序)?如果是,如何?

采纳答案by Nik Reiman

It does seem possible to create DMG files with some third party tools. A quick google search reveals at least a few commercial tools:

似乎可以使用某些第三方工具创建 DMG 文件。一个快速的谷歌搜索至少揭示了一些商业工具:

Not sure about any OSS/freeware options, but it does at least seem possible if you are so inclined.

不确定任何 OSS/免费软件选项,但如果您如此倾向,它至少看起来是可能的。

Edit: I also forgot about MacDrive, which is another great tool for working with HFS+ filesystems under windows. Since a DMG is basically just a HFS+ filesystem snapshot, it is probably possible with MacDrive to create DMG's as well.

编辑:我也忘记了MacDrive,它是另一个在 Windows 下使用 HFS+ 文件系统的好工具。由于 DMG 基本上只是一个 HFS+ 文件系统快照,因此 MacDrive 也可能创建 DMG。

回答by jstck

Yep, mkfs.hfsplus does it.

是的,mkfs.hfsplus 做到了。

dd if=/dev/zero of=/tmp/foo.dmg bs=1M count=64
mkfs.hfsplus -v ThisIsFoo /tmp/foo.dmg

This creates a dmg file (in this case 64M) that can be mounted on a mac. It can also be mounted on linux, with something like

这将创建一个可以安装在 mac 上的 dmg 文件(在本例中为 64M)。它也可以安装在 linux 上,类似于

mount -o loop /tmp/foo.dmg /mnt/foo

after wich you just copy the content you want to it (in /mnt/foo). Unmount it, and the dmg can be copied over to a mac and mounted there.

之后你只需复制你想要的内容(在 /mnt/foo 中)。卸载它,dmg 可以复制到 Mac 并安装在那里。

回答by uckelman

A project I work on creates DMG files on Linux using genisoimage:

我从事的一个项目使用 genisoimage 在 Linux 上创建 DMG 文件:

mkdir -p dmgdir/progname.app/Contents/{MacOS,Resources}
...copy your PkgInfo, Info.plist to Contents...
...copy your .icns to Resources...
...copy your other things to where you expect them to go...
genisoimage -V progname -D -R -apple -no-pad -o progname.dmg dmgdir 

If you want to be really fancy, you can steal the .DS_Storefile from a DMG made on a Mac with a volume name prognameand app bundle called progname.app(i.e., matching what you want to create off the Mac) where you've put a background in .background/background.pngand a symbolic link to /Applications in the root dir, and put that in dmgdiralong with your own a symbolic link to /Applications.

如果你真的很喜欢,你可以.DS_Store从在 Mac 上制作的 DMG 中窃取文件,该 DMG 具有卷名progname和名为的应用程序包progname.app(即匹配你想在 Mac 上创建的内容),你已经在其中放置了背景.background/background.png和一个指向根目录中 /Applications 的符号链接,并将其dmgdir与您自己的指向/Applications.

回答by name

git clone https://github.com/hamstergene/libdmg-hfsplus
cd libdmg-hfsplus && cmake . && make && cd dmg
./dmg --help

Makefile:

生成文件:

dmg:
    genisoimage -D -V "$(PROJECT) $(VERSION)" -no-pad -r -apple -o project-$(VERSION)-uncompressed.dmg $(DARWIN_DIR)
    ./dmg dmg project-$(VERSION)-uncompressed.dmg project-$(VERSION).dmg

uncompressed works out of the box, compression may cause problems - the origin/master at least produces a 'checksum' error on snow-leopard

未压缩的开箱即用,压缩可能会导致问题 - 源/主至少会在雪豹上产生“校验和”错误

回答by MattWeiler

I'm not sure if anyone is still watching this thread, but I tried TransMacas recommended by Nik Reiman.

我不确定是否有人还在看这个帖子,但我按照Nik Reiman 的推荐尝试了TransMac

Using this tool I was able to, running on Windows 7, create dmgfiles which were mountable on OSX 10.8.3.

使用这个工具,我能够在Windows 7上运行,创建可安装在OSX 10.8.3上的dmg文件。



Downside

缺点

The only downside for us is that this tool doesn't appear to be command-line friendly; for us that's a deal-breaker as we need to be able to have an automated tool which our build server (Windows based) can use to build dmg files on-the-fly.

对我们来说唯一的缺点是这个工具似乎对命令行不友好;对我们来说,这是一个交易破坏者,因为我们需要能够拥有一个自动化工具,我们的构建服务器(基于 Windows)可以使用它来即时构建 dmg 文件。

回答by Josh

See mkfs.hfsplus

参见 mkfs.hfsplus

回答by Sherm Pendley

If you're distributing Mac apps, then surely you have a Mac to write and test them. Why not simply use that same Mac to create the disk image?

如果您要分发 Mac 应用程序,那么您肯定有一台 Mac 可以编写和测试它们。为什么不简单地使用同一台 Mac 来创建磁盘映像?

[Edit] Alternatively, if you're distributing a portable app, for example a Java .jar file, why bother with a disk image? Macs understand .zip and .tar.gz archives just fine.

[编辑] 或者,如果您要分发便携式应用程序,例如 Java .jar 文件,为什么还要使用磁盘映像?Mac 理解 .zip 和 .tar.gz 档案就好了。

I guess what I'm getting at is, I don't understand how one might need a DMG disk image, but not have a Mac with which to create it.

我想我的意思是,我不明白一个人可能需要 DMG 磁盘映像,但没有 Mac 来创建它。