简体   繁体   English

如何在Mac上使用pkgbuild和productbuild运行postflight脚本来构建安装包

[英]How to run a postflight script using pkgbuild and productbuild on Mac building an installation package

I want to build an installation package for Mac OS X that contains 4 sub packages. 我想为Mac OS X构建一个包含4个子包的安装包。 The sub packages are build with pkgbuild. 子包是使用pkgbuild构建的。 The final package is build with productbuild using a Distribution.xml for welcome and license text and install location choices. 最终的包使用product.xml构建,使用Distribution.xml进行欢迎和许可文本以及安装位置选择。

Now I want to run a script after the installation has succeeded. 现在我想在安装成功后运行脚本。 In particular after the receipts of all packaged are written by the installer. 特别是在所有打包的收据都由安装程序写入之后。

As far as I understand the man pages and documentation and other useful links I should use a postflight script for that. 据我所知,手册页和文档以及其他有用的链接我应该使用postflight脚本。 Unfortunately I can't get it to work. 不幸的是我无法让它发挥作用。 I named it postflight and added to the sub package with pkgbuild using the --script option but it seems pkgbuild does not support postflight scripts. 我将它命名为postflight并使用--script选项添加到pkgbuild的子包中,但似乎pkgbuild不支持postflight脚本。 When I name it postinstall it runs but unfortunately before the receipts are written. 当我将其命名为postinstall时,它会在收据写入之前运行。

I need to run after the receipts are written because I want to write a xcconfig file for XCode constisting of the location of the other packages' install locations using the pkgutil tool. 我需要在写入收据后运行,因为我想使用pkgutil工具为XCode编写一个xcconfig文件,以构成其他软件包的安装位置的位置。

I already tried to use the expand-flatten hack by adding a Scripts/ folder to the expanded pkg but that seems to be ignored after I flatten it. 我已经尝试通过在扩展的pkg中添加Scripts /文件夹来使用expand-flatten hack,但是在我展平后它似乎被忽略了。

Is there a way to accomplish my need? 有没有办法满足我的需求? (Writing the chosen install locations of my packages to a file in the installation location of a sub package) (将我的包的选定安装位置写入子包的安装位置中的文件)

If possible I want to avoid using the deprecated packagemaker tool, at least if there is another better way. 如果可能的话,我想避免使用已弃用的packagemaker工具,至少如果还有其他更好的方法。

Thanks in advance 提前致谢

As I had to find out finally, the postflight script is also executed before the receipts are written. 正如我最终要找到的那样,postflight脚本也会在收据写入之前执行。 So my solution to this problem is now the following: 所以我现在解决这个问题的方法如下:

I add postinstall scripts to my packages that read the DSTROOT environment variable set by the Mac OS installer and write them to a file in the shared temp folder: 我将postinstall脚本添加到我的包中,该包读取由Mac OS安装程序设置的DSTROOT环境变量,并将它们写入共享临时文件夹中的文件:

echo "${DSTROOT}" > "${SHARED_INSTALLER_TEMP}/my_install_location"

Then in my package, that needs these information, I read the old receipts via a postinstall script (in case the sub package is already installed and the user "reinstalls" leaving out some of the sub packages) and then the temp file from the other package. 然后在我的包中,需要这些信息,我通过postinstall脚本读取旧的收据(如果已经安装了子包并且用户“重新安装”而忽略了一些子包),那么来自另一个的临时文件包。

So, if the package is already installed and not reinstalled it uses the current install location otherwise it uses the new install location via the temp files. 因此,如果软件包已安装但未重新安装,则使用当前安装位置,否则它将通过临时文件使用新的安装位置。 If nothing is present the required package was not installed so I use default values and write them to the xcconfig file (that probably won't work): 如果没有任何内容,则未安装所需的软件包,因此我使用默认值并将其写入xcconfig文件(这可能不起作用):

pkgutil --pkg-info-plist my.package.bundle > "${SHARED_INSTALLER_TEMP}/tmp.plist"
if [ -e "${SHARED_INSTALLER_TEMP}/tmp.plist" ];
then
    MY_PACKAGE_VOL=`/usr/libexec/PlistBuddy -c "Print :volume" "${SHARED_INSTALLER_TEMP}/tmp.plist"`
    MY_PACKAGE_DIR=`/usr/libexec/PlistBuddy -c "Print :install-location" "${SHARED_INSTALLER_TEMP}/tmp.plist"`      
    MY_PACKAGE_DIR="${MY_PACKAGE_VOL}${MY_PACKAGE_DIR}"
fi

After reading the "old" install location, I check if I have a new install location using the previously written temp file from the other packages: 阅读“旧”安装位置后,我使用以前写入的其他软件包中的临时文件检查我是否有新的安装位置:

if [ -e "${SHARED_INSTALLER_TEMP}/my_install_location" ];
then
    MY_PACKAGE_DIR=`cat "${SHARED_INSTALLER_TEMP}/my_install_location"`
fi 

...
Write the xcconfig file...
...

If someone has a better solution let me know. 如果有人有更好的解决方案,请告诉我。

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

相关问题 Mac安装程序包-如何以root或admin身份运行脚本? (飞行后) - Mac installer package - how to run scripts as root or admin? (postflight) 在 Mac 上安装软件包时运行 postflight 脚本 - Running postflight script when installing a package on Mac 使用postflight脚本构建发行版安装程序包(.pkg),无需身份验证 - Building distribution Installer package (.pkg) with postflight script without requiring authentication 如何在pkgbuild和productbuild中区分OS X版本 - How to distinguish OS X version in pkgbuild and productbuild 如何从pkgbuild / productbuild正确使用“defaults write”? - How do I use “defaults write” correctly from pkgbuild / productbuild? MacPorts安装-Shell命令/ Postflight脚本 - MacPorts Installation — Shell Commands/Postflight Script 如何在使用pkgbuild / productbuild构建的OS X安装程序中询问用户问题? - How do you ask the user questions in an OS X installer built with pkgbuild/productbuild? Mac Installer软件包(productbuild)要求输入管理员密码,但不应该 - Mac Installer package (productbuild) asks for admin password, but shouldn't 需要使用pkgbuild重新启动组件包 - Requiring restart in component package using pkgbuild mac:如何使用--component选项将license.txt添加到使用productbuild构建的pkg中? - mac: How to add a License.txt to a pkg built with productbuild using --component option?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM