Intermittent App Package Installation failure.

I work on a macOS application that functions as a daemon. To test it, I:

  1. Compile executables.

  2. Use pkgbuild and productbuild to build an application bundle.

  3. Use codesign and notarytool to sign and notarize the app.

  4. Install the app with /usr/sbin/installer -target LocalSystem -pkg .... This often overwrites the previous version of the app.

Sometimes, the installation fails at the postinstall stage, when it can not find the application's install directory. We explicitly check for this error in our script:

if ! [ -d "$APP_INSTALL_DIR"/Contents ]; then
    echo "directory ${APP_INSTALL_DIR}/Contents is missing"
    exit 1
fi

This is unexpected!

Even worse, some of our customers have occasionally seen the same issue!

We use a postinstall script in order to install files into the /Library/LaunchDaemons and /Library/ LaunchAgents directories, and start the agent with launchctl bootstrap.

Our preinstall script makes sure that the previous version of our application is fully uninstalled (so there is no confusion), and we wonder if that is part of the problem.

While researching this error, I ran across a discussion of a similar issue on Stackoverflow: <https:// stackoverflow.com/questions/19283889>. One of the commenters there wrote:

It appears that the OS X installer uses information about already installed packages and application bundles in order to decide where and if to install new packages. As a result, sometimes my installer did not install any files whatsoever, and sometimes it just overwrote the .app bundle in my build tree. Not necessarily the one used to build the installer, but any .app bundle that OS X had found. In order to get the installer to install the files properly I had to do two things:

  1. Tell OS X to forget about the installed package. sudo pkgutil --forget <package id> Not sure if this is needed for you nor in my case, but it is probably a good idea anyway.

  2. Delete all existing .app bundles for the app. If I didn't do this, the existing app bundle was overwritten on install instead of the app being placed in /Applications. Maybe there is a way to prevent this while building the installer package, but I haven't found it.

On the other hand, the man page for pkgutil says not to use --forget from an installer:

Discard all receipt data about package-id, but do not touch the installed files. DO NOT use this command from an installer package script to fix broken package design.

What is the correct approach to fix this problem?

Does anyone have any insight here?

I'm still looking for any information here. Has anyone from Apple looked at this? Because it is intermittent, I don't know how to create a focused test project for a code-level support request.

Hello @Hal_Canary, thank you for your post. Are you providing pkgbuild a components.plist file? If so, what values are you giving to the BundleIsRelocatable, BundleIsVersionChecked and BundleOverwriteAction keys?

Thanks for the reply!

Here's the component.plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist
  PUBLIC '-//Apple//DTD PLIST 1.0//EN'
  'http://www.apple.com/DTDs/PropertyList-1.0.dtd'>
<plist version="1.0">
  <array>
    <dict>
      <key>BundleHasStrictIdentifier</key>
      <true/>
      <key>BundleIsRelocatable</key>
      <false/>
      <key>BundleIsVersionChecked</key>
      <true/>
      <key>BundleOverwriteAction</key>
      <string>upgrade</string>
      <key>RootRelativeBundlePath</key>
      <string>Applications/AternityAgent.app</string>
    </dict>
  </array>
</plist>
Intermittent App Package Installation failure.
 
 
Q