简体   繁体   English

将PackageMaker命令行构建安装程序移植到pkgbuild

[英]Porting PackageMaker command line build installer to pkgbuild

I've been attempting to port a Mac PackageMaker command line build to pkgbuild and productbuild but I'm stuck. 我一直在尝试将Mac PackageMaker命令行构建移植到pkgbuild和productbuild但是我被卡住了。 Unfortunately I haven't found much of anything documenting how these new programs work except for this StackOverflow post and the pkgbuild and productbuild man pages. 遗憾的是,除了这个StackOverflow帖子以及pkgbuildproductbuild手册页之外,我还没有找到任何记录这些新程序如何工作的内容。

Here's my problem. 这是我的问题。 I've created a root install directory that has the following files in it: 我创建了一个根安装目录,其中包含以下文件:

/some_path/Applications
                       /MyProgram.app
          /Library
                  /Frameworks
                             /MyFramework.framework
                                                   /[library files...]

The command line call below worked great for PackageMaker. 下面的命令行调用对PackageMaker非常有用。 It created an installer that installed all of the files above. 它创建了一个安装程序,安装了上面的所有文件。

$ /Developer/usr/bin/packagemaker \
    --title "My Program" \
    --root /some_path \
    --version 1.0.0 \
    --filter "\.DS_Store" \
    --resources ./resources/ \
    --scripts ./scripts/ \
    --root-volume-only \
    --domain system \
    --verbose \
    --no-relocate \
    --target 10.5 \
    --id com.my_company.pkg \
    --out MyProgram.pkg

Now I'm trying to write this with pkgbuild and having a major problem. 现在我正在尝试用pkgbuild编写这个并遇到一个重大问题。 I use the following call: 我使用以下电话:

$ pkgbuild \
    --root /some_path \
    --version 1.0.0 \
    --install-location "/" \
    --scripts "./scripts/" \
    --identifier "com.my_company.pkg" \
    MyProgram.pkg

This command builds an installer that copies the MyProgram.framework directory into /Library/Frameworks. 此命令构建一个安装程序,将MyProgram.framework目录复制到/ Library / Frameworks中。 However it does not install the MyProgram.app file into the /Applications directory. 但是,它不会将MyProgram.app文件安装到/ Applications目录中。 When I look at the installer logs I see this message: 当我查看安装程序日志时,我看到以下消息:

Applications/MyProgram.app relocated to /some_path/Applications/MyProgram.app Applications / MyProgram.app重定位到/some_path/Applications/MyProgram.app

Can anyone shed some light on why this isn't adding the MyProgram.app file into the /Applications directory like PackageMaker was doing? 任何人都可以解释为什么这不是像PackageMaker那样将MyProgram.app文件添加到/ Applications目录中?

Unfortunately the answer to this question wasn't exactly what I was looking for. 不幸的是,这个问题的答案并不完全是我想要的。 I couldn't figure out how to eliminate PackageMaker from the process. 我无法弄清楚如何从流程中消除PackageMaker。 However there is a solution that includes pkgutil along with PackageMaker to create an installer with custom welcome message, license and background image entirely on the command line. 但是,有一个解决方案包括pkgutil和PackageMaker,以完全在命令行上创建带有自定义欢迎消息,许可证和背景图像的安装程序。 The PackageMaker GUI is NOT required. PackageMaker GUI 不是必需的。 The steps are as follows: 步骤如下:

  1. Run the packagemaker command line executable on the special directory structure. 在特殊目录结构上运行packagemaker命令行可执行文件。 This directory structure reflects the Mac file system. 此目录结构反映了Mac文件系统。 Read more in the old but reliable "PackageMaker How-to" tutorial . 阅读旧的但可靠的“PackageMaker操作方法”教程
  2. Run pkgutil ( pkgutil --expand ) to extract the package contents 运行pkgutil( pkgutil --expand )来提取包内容
  3. Take a look at the contents and identify what you want to alter. 查看内容并确定要更改的内容。 Some options are the welcome message, license and background image. 一些选项是欢迎消息,许可证和背景图像。
  4. Add commands to alter these files via the command line. 添加命令以通过命令行更改这些文件。 Review the "Automating Apple's PackageMaker" tutorial for more information. 查看“自动化Apple的PackageMaker”教程以获取更多信息。 The easiest way is just to run something like this echo '<background file="your_background.png">' . 最简单的方法就是运行类似echo '<background file="your_background.png">'
  5. Run pkgutil ( pkgutil --flatten ) to rebuild the package. 运行pkgutil( pkgutil --flatten )重建包。

First of all, are you sure that you need an installer? 首先,您确定需要安装人员吗? You could put the framework inside the application. 您可以将框架放在应用程序中。 The Installer and pkgbuild are a bit flaky, to say the least. 至少可以说,安装程序和pkgbuild有点不稳定。

Now to the problem at hand: Relocation has to do with the fact that a user could move the Application from /Applications to say /WorkApplications /PrivateApplications. 现在解决手头的问题:重定位与用户可以将应用程序从/ Applications移动到/ WorkApplications / PrivateApplications这一事实有关。 In your case the Installer probably finds your Application in the build folder and installs it over this one. 在您的情况下,安装程序可能会在构建文件夹中找到您的应用程序并将其安装在此文件夹中。

I think the Installer uses the Application Bundle Identifier and Spotlight for the relocation, so for testing you could add the build folder to the Spotlight ignore list. 我认为安装程序使用Application Bundle Identifier和Spotlight进行重定位,因此对于测试,您可以将build文件夹添加到Spotlight忽略列表中。

You can define in the Component Property List BundleIsRelocatable . 您可以在Component Property List BundleIsRelocatable定义。 If you really have to install a framework global, this is one bundle where you want to set BundleIsRelocatable to false. 如果您确实需要安装全局框架,那么这是一个要将BundleIsRelocatable设置为false的包。

The question you reference has pretty much everything you need to eliminate Package Maker entirely. 您引用的问题几乎包含了完全消除Package Maker所需的一切。 One thing I added is to use sed after the productbuild --synthesize ... invocation to insert lines into the distribution file. 我添加的一件事是在productbuild --synthesize ...调用之后使用sed将行插入到分发文件中。 For example, here are some Terminal commands I use once I've already built the component package: 例如,以下是我已经构建组件包后使用的一些终端命令:

productbuild --synthesize --package "components/SubPackage.pkg" "distribution.xml"
sed -i "" \
-e '$ i\
\    <title>Installer Title</title>' \
-e '$ i\
\    <background file="background.png" alignment="left" scaling="proportional" />' \
-e '$ i\
\    <welcome file="welcome.rtf" />' \
"distribution.xml"
productbuild --distribution "distribution.xml" --resources "resources/" --package-path "components/" "Installer.pkg"

This avoids having to use pkgutil --expand and pkgutil --flatten to modify the installer. 这避免了必须使用pkgutil --expandpkgutil --flatten来修改安装程序。

Create component plist file, which has value for relocatable property. 创建组件plist文件,该文件具有可重定位属性的值。

pkgbuild --analyze --root "$dst_src_root" "$installer_root/Components.plist"

Edit component plist and Set "BundleIsRelocatable" to false. 编辑组件plist并将“BundleIsRelocatable”设置为false。 This is done one time in my project, as installer contents does not change (One application and one plugin). 这在我的项目中完成了一次,因为安装程序内容没有改变(一个应用程序和一个插件)。 I am reusing same component plist everytime to create contents package. 我每次都重复使用相同的组件plist来创建内容包。

sudo pkgbuild --root "$dst_src_root" --component-plist "$installer_root/Components.plist" --identifier "com.company.app" --version "1.0" --scripts "$dst_scpt_root" "$dst_pkg_root/InstallPackage/cisContents.pkg" 

Then using productbuild, we can create final package 然后使用productbuild,我们可以创建最终包

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM