App intermittently disappearing after installation

We're build a pkg with three apps in it from the command line. There is one primary app and two supporting apps. We build a folder structure inside a temp directory like below (some folder names replaced with generic ones):

mkdir -p ./tmp/Applications/.hiddenfolder/
mkdir -p ./tmp/Library/Application\ Support/Company/
mkdir -p ./tmp/Library/Preferences/
mkdir -p ./tmp/Library/Logs/Company/
mkdir -p ./tmp/Library/LaunchAgents/
mkdir -p ./tmp/Library/Company/
mkdir -p ./tmp/Library/LaunchDaemons/

#Grant Logs Folder Read-Write Access to All
chmod a+rw ./tmp/Library/Logs/Company/
chmod a+rw ./tmp/Library/Application\ Support/Company/

We then build and sign each app dependency and place them into the temporary folder. For each app we're calling:

xcodebuild -workspace "$PROJECT" -scheme "$TARGET" -configuration Release -derivedDataPath "$WORKING" clean build
codesign --force --deep -o runtime --entitlements "../$TARGET/$APPLICATION.entitlements" --sign "$DEVKEY" "$WORKING/Build/Products/Release/$APPLICATION.app"
cp -R "$WORKING/Build/Products/Release/$APPLICATION.app" "$DESTINATION"

The primary app is copied into ./tmp/Applications/.hiddenfolder/ . The other two apps are put in ./tmp/Library/Company/ and ./tmp/Applications/

We then create the component list, build, and notarize the final pkg using the script below:

Some definitions of the variables used below:

  • IDENTIFIER=com.company.pkg.app1 (not real id but an example)
  • ROOT=./tmp
  • SCRIPTS=./scripts
  • GUI=./pkggui
pkgbuild --analyze --identifier "$IDENTIFIER" --version "$VERSION" --root "$ROOT" --scripts "$SCRIPTS" "$NAME-tmp.plist"

/usr/libexec/PlistBuddy -c "SET 0:BundleIsRelocatable NO" "$NAME-tmp.plist"
/usr/libexec/PlistBuddy -c "SET 1:BundleIsRelocatable NO" "$NAME-tmp.plist"
/usr/libexec/PlistBuddy -c "SET 2:BundleIsRelocatable NO" "$NAME-tmp.plist"

pkgbuild --identifier "$IDENTIFIER" --version "$PKGVERSION" --root "$ROOT" --scripts "$SCRIPTS" --component-plist "$NAME-tmp.plist" "$NAME-tmp.pkg"
productbuild --synthesize --package "$NAME-tmp.pkg" distribution.xml
sed -i "" \
-e '$ i\
\    <title>App1</title>' \
-e '$ i\
\    <background file="background.icns" alignment="bottomleft" scaling="proportional" />' \
-e '$ i\
\    <welcome file="welcome.txt" />' \
-e '$ i\
\    <installation-check script="InstallationCheck()"/> \
    <script> \
        function InstallationCheck(prefix) { \
            if (system.compareVersions(system.version.ProductVersion, '12.0') &lt; 0) { \
                my.result.message = "This update requires OS X version 12.0 or later."; \
                my.result.type = "Fatal"; \
                return false; \
            } \
            return true; \
        } \
    </script>' \
"distribution.xml"

productbuild --distribution distribution.xml --resources "$GUI" --package-path "./$NAME-tmp.pkg" --sign "$DEVKEY" "$NAME.pkg"

Once built and notarized this pkg becomes the base for the installers we give to customers. For each customer we have some custom parameters we set in a plist file inside the pkg, which requires us to expand the pkg out, add the plist file to /Library/Preferences/ in the expanded pkg, and then flattent/re-notarize the edited pkg.

What we're running into is that the primary app (App1 above) will intermittently disappear after installation. We check all of the files we lay down in the postinstall script, and usually it detects the app in the correct location (/Applications/.hiddenfolder/), so it appears that it is correctly laying the files down but something is removing the app after installation. A couple of times the postinstall script has detected that the app is not in the correct place and fails, but usually the install will finish and only the other two apps remain. So far we've found no logs or evidence of it being moved or deleted; it just ceases to exist after installation.

Has anyone else had this issue and found a solution?

I think intermittently is a misnomer. It is sysem-dependent and consistently happening, just not on any of the systems in our control. To give additional context, we can see it existed in our postinstall check, but then at the end it says it can't find the file instead of "PackageKit: Registered bundle ..." but we can't find a message explaining why it is being removed.

2024-10-02 09:43:06-04 MBA-L-8114 package_script_service[9897]: ./postinstall: App Name: /Applications/.hiddenfolder/app1.app found.
...
2024-10-02 09:43:06-04 MBA-L-8114 package_script_service[9897]: PackageKit: Hosted team responsible for script has been cleared.
2024-10-02 09:43:06-04 MBA-L-8114 package_script_service[9897]: Responsibility set back to self.
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Writing receipt for com.company.pkg.app1 to /
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Touched bundle /Applications/HelperApp.app
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Touched bundle /Applications/.hiddenfolder/app1.app
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Touched bundle /Library/Company/HelperApp2.app
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: Installed "App Name" ()
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: Successfully wrote install history to /Library/Receipts/InstallHistory.plist
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: releasing backupd
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: allow user idle system sleep
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: ----- End install -----
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: 2.2s elapsed install time
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Cleared responsibility for install from 9894.
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Hosted team responsible for install has been cleared.
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Running idle tasks
2024-10-02 09:43:06-04 MBA-L-8114 installd[3215]: PackageKit: Done with sandbox removals
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: PackageKit: Registered bundle file:///Applications/HelperApp.app/ for uid 0
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: Error getting application status info for file:///Applications/.hiddenfolder/app1.app: Error Domain=NSCocoaErrorDomain Code=260 "The file “app1.app” couldn’t be opened because there is no such file." UserInfo={NSURL=file:///Applications/.hiddenfolder/app1.app, NSFilePath=/Applications/.hiddenfolder/app1.app, NSUnderlyingError=0x6000026a0d50 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: PackageKit: Registered bundle file:///Library/Company/HelperApp2.app/ for uid 0
2024-10-02 09:43:07-04 MBA-L-8114 installd[3215]: PackageKit: Removing client PKInstallDaemonClient pid=9894, uid=0 (/usr/sbin/installer)
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: Running install actions
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: Removing temporary directory "/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T//Install.98948eFhHX"
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: Finalize disk "MacOS"
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: Notifying system of updated components
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: 
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: **** Summary Information ****
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]:   Operation      Elapsed time
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: -----------------------------
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]:        disk      0.01 seconds
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]:      script      0.00 seconds
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]:        zero      0.00 seconds
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]:     install      3.56 seconds
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]:     -total-      3.57 seconds
2024-10-02 09:43:07-04 MBA-L-8114 installer[9894]: 
App intermittently disappearing after installation
 
 
Q