macos 创建 .DMG
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/367751/
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
Creating a .DMG
提问by lostInTransit
I want to create a dmg file for my Mac project. Can someone please tell me how to do this? This being my first Mac project, I do not have any idea how to proceed. I also want to give the user an option of running the app on start-up. How do I do this?
我想为我的 Mac 项目创建一个 dmg 文件。有人可以告诉我怎么做吗?这是我的第一个 Mac 项目,我不知道如何进行。我还想为用户提供在启动时运行应用程序的选项。我该怎么做呢?
Thanks.
谢谢。
P.S. I also want to add a custom license agreement.
PS 我还想添加自定义许可协议。
回答by dbr
To do this manually:
要手动执行此操作:
Method 1:
方法一:
- Make a folder with the files your DMG will contain.
- 创建一个包含 DMG 将包含的文件的文件夹。
- Open Disk Utility (It's in
/Applications/Utilities/
)
- 打开磁盘工具(在 中
/Applications/Utilities/
)
- Go to File > New > New Image from Folder (
Cmd + Shift + N
)
- 转到文件 > 新建 > 文件夹中的新图像 (
Cmd + Shift + N
)
- Choose the folder containing you files
- Make sure "Compressed" is checked, then set where you want to save the created DMG
- 选择包含您文件的文件夹
- 确保选中“压缩”,然后设置要保存创建的 DMG 的位置
Method 2:
方法二:
To do things like setting a background image can be a bit convoluted (You basically add the background image to the DMG, set the windows properties to use that image, using the command line you move the background image from background.png
to .background.png
to make it hidden)
设置背景图像之类的操作可能有点复杂(您基本上将背景图像添加到 DMG,设置 Windows 属性以使用该图像,使用命令行将背景图像从 移动background.png
到.background.png
以使其隐藏)
I would recommend iDMG, which makes things a bit less tedious.
我会推荐iDMG,这让事情变得不那么乏味了。
You can also script the creation of DMGs using the command hdiutil
. Something along the lines of
您还可以使用命令编写 DMG 创建的脚本hdiutil
。类似的东西
hdiutil create -srcfolder mydirtodmg mydmg.dmg
As for the custom license agreement, you should look into the tool included with the Developer Tools "PackageMaker" - it's pretty self-explanatory. It's in /Developers/Application/Utilities/
至于自定义许可协议,您应该查看开发人员工具“PackageMaker”中包含的工具 - 它非常不言自明。在里面/Developers/Application/Utilities/
回答by user2067021
If you need to add a custom EULA to your disk image, this pagedescribes how to do so using command-line tools. The gist of it is to use the template software licensing agreement resource provided in Apple's slas_for_udifs_1.0.dmg, modify the resource with your EULA text and inject the resource back into your disk image file. (I include brief instructions below in case the above link becomes unavailable, and to update the search term it provides in step 1.)
如果您需要向磁盘映像添加自定义 EULA,本页介绍了如何使用命令行工具执行此操作。它的要点是使用 Apple 的 slas_for_udifs_1.0.dmg 中提供的模板软件许可协议资源,使用您的 EULA 文本修改资源并将资源注入回您的磁盘映像文件。(我在下面提供了简要说明,以防上面的链接不可用,并更新它在步骤 1 中提供的搜索词。)
- Using your Apple Developer account go to the Downloadspage and search for Software Licensing for UDIF
- Download and mount the disk image
In Terminal:
cd /Volumes/SLAs_for_UDIFs_1.0 DeRez SLAResources > /tmp/sla.r
Edit /tmp/sla.r in a text editor, updating the content of the
data 'TEXT' (5000, "English SLA")
resource to contain your new license text.Unflatten the disk image file that contains your installer:
hdiutil unflatten installer_image.dmg
Add the edited license resources to the image:
Rez -a /tmp/sla.r -o installer_image.dmg
- 使用您的 Apple Developer 帐户转到“下载”页面并搜索UDIF 的软件许可
- 下载并挂载磁盘映像
在终端:
cd /Volumes/SLAs_for_UDIFs_1.0 DeRez SLAResources > /tmp/sla.r
在文本编辑器中编辑 /tmp/sla.r,更新
data 'TEXT' (5000, "English SLA")
资源的内容以包含新的许可证文本。解压包含安装程序的磁盘映像文件:
hdiutil unflatten installer_image.dmg
将编辑过的许可证资源添加到图像中:
rez -a /tmp/sla.r -o installer_image.dmg
回答by kent
why don't you just run a script from your xcode project. try something like this:
你为什么不从你的 xcode 项目中运行一个脚本。尝试这样的事情:
# be sure to check the man page for hdiutil
# it is very powerful and has tons of options...
hdiutil create -megabytes 54 -fs HFS+ -volname awesome_app_install myAwesomeApplication.dmg
hdiutil mount myAwesomeApplication.dmg
cp -r /build/Release/AwesomeApplication.app /Volumes/awesome_app_install/
then save your script as something like 'makeDMG.sh' and in your target,
然后将您的脚本另存为“makeDMG.sh”之类的内容并保存在您的目标中,
select add->new build phase->run script build phase
and drag your script into this build phase.
选择添加-> 新构建阶段-> 运行脚本构建阶段
并将您的脚本拖入此构建阶段。
once you've done all that, then when you build your project the script will create the disk image and copy your release build into it...
完成所有这些后,当您构建项目时,脚本将创建磁盘映像并将您的发布版本复制到其中...
of course you should spice your script to flavor... these three lines are just the raw meat
当然你应该给你的剧本调味……这三行只是生肉
ps: your custom EULA should get built into your packagemaker project (which you can also script very nicely)
ps:您的自定义 EULA 应该内置到您的 packagemaker 项目中(您也可以很好地编写脚本)
回答by AdriZ
I made a little bash script to automate a disc image creation.
我制作了一个小 bash 脚本来自动创建光盘映像。
It creates a temporary directory to store all needed files then export it in a new DMG file. Temporary directory is then deleted. You can automatically launch this script at the end of your build process.
它会创建一个临时目录来存储所有需要的文件,然后将其导出到一个新的 DMG 文件中。然后删除临时目录。您可以在构建过程结束时自动启动此脚本。
#!/bin/bash
# Create .dmg file for macOS
# Adapt these variables to your needs
APP_VERS="1.0"
DMG_NAME="MyApp_v${APP_VERS}_macos"
OUTPUT_DMG_DIR="path_to_output_dmg_file"
APP_FILE="path_to_my_app/MyApp.app"
OTHER_FILES_TO_INCLUDE="path_to_other_files"
# The directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# The temp directory used, within $DIR
WORK_DIR=`mktemp -d "${DIR}/tmp"`
# Check if tmp dir was created
if [[ ! "${WORK_DIR}" || ! -d "${WORK_DIR}" ]]; then
echo "Could not create temp dir"
exit 1
fi
# Function to deletes the temp directory
function cleanup {
rm -rf "${WORK_DIR}"
#echo "Deleted temp working directory ${WORK_DIR}"
}
# Register the cleanup function to be called on the EXIT signal
trap cleanup EXIT
# Copy application on temp dir
cp -R "${APP_FILE}" "${WORK_DIR}"
# Copy other files without hidden files
rsync -a --exclude=".*" "${OTHER_FILES_TO_INCLUDE}" "${WORK_DIR}"
# Create .dmg
hdiutil create -volname "${DMG_NAME}" -srcfolder "${WORK_DIR}" -ov -format UDZO "${OUTPUT_DMG_DIR}/${DMG_NAME}.dmg"