Requiring restart in component package using pkgbu

2019-06-07 07:46发布

I'm updating some build scripts to use pkgbuild instead of PackageMaker, but I'm not seeing an option to require restarts on a component package. In PackageMaker, requiring a restart could be done using either of the following two methods:

  • (Legacy compatibility mode) In the Info.plist, set IFPkgFlagRestartAction to RequiredRestart.
  • In the PackageInfo file, set pkg-info>postinstall-action to restart.

I don't see any similar options for pkgbuild or its component package plist. I understand that, when we build our distribution using productbuild, we can choose to require a restart on a per-package basis using the distribution file's pkg-ref>onConclusion key. But is this the only way to do this now (without using PackageMaker)? If so, I'm wondering why this requirement was moved out of the component packages and into the distribution that depends on them. In my mind, the component packages remained more modular when they could specify their own requirements.

EDIT: If you set postinstall-action="restart" in the resulting PackageInfo you can force the reboot. Now the question is just how to teach pkgbuild to write that automatically to the PackageInfo-file.

标签: macos package
2条回答
Juvenile、少年°
2楼-- · 2019-06-07 08:15

Note that if you use productbuild as shown in this answer, you can modify the distribution.xml file to require a restart as well, and that format is well-documented. Here's an example using sed:

sed -i "" -e 's/onConclusion="None"/onConclusion="RequireRestart"/' distribution.xml

This avoids having to expand and flatten the package, and allows you to include a custom background, welcome text, etc. :-)

查看更多
狗以群分
3楼-- · 2019-06-07 08:19

It is not possible to accomplish this through a parameter or the component.plist

Therefore I did it by expanding, editing and flattening the package via a shell-script:

#Replace the value of the postinstall-action attribute to restart
echo "Expanding archive ${BDIR}/${NAME}-Installer.pkg"
pkgutil --expand "Installer.pkg" installertmp

echo "Replacing postinstall-action \"none\" with \"restart\""
sed -e 's/postinstall-action=\"none\"/postinstall-action=\"restart\"/' -i '' installertmp/PackageInfo

echo "Flattening archive Installer.pkg"
pkgutil --flatten installertmp "Installer.pkg"

rm -f -r "installertmp"
查看更多
登录 后发表回答