How to run postflight script using pkgbuild and productbuild on Mac by creating an installation package

I want to create an installation package for Mac OS X that contains 4 subpackages. Subpackages are created using pkgbuild. The final package is created using productbuild using Distrib.xml to greet and license text and set the location.

Now I want to run the script after the installation is complete. In particular, after the receipts of all packaged are recorded by the installer.

As far as I understand the manual pages and the documentation and other useful links, I should use a postflight script for this. Unfortunately, I cannot get it to work. I called it postflight and added it to the extra package with pkgbuild using the - script option, but it seems that pkgbuild does not support postfile scripts. When I call it postinstall, it starts, but unfortunately, before the receipts are written.

I need to run after the recordings are made, because I want to write an xcconfig file for Xcode containing the location of the installation locations of other packages using the pkgutil tool.

I already tried to use the hacked extension, adding Scripts / folder to the extended pkg, but it seems to be ignored after I flatten it.

Is there a way to fulfill my need? (Writing the selected installation locations of my packages to a file at the installation location of the additional package)

If possible, I want to avoid using an outdated packaging tool, at least if there is another better way.

Thanks in advance

+5
source share
1 answer

As I had to finally find out, the postflight script is also executed before receipts are received. 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 temp shared folder:

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

, , postinstall script ( , , "", ), .

, , , . , , 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

"" , , , temp :

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

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

- , .

+1

All Articles