PostInstall script not running on MacOS

I have created a package installer for MacOS with "productbuild" command line and adding the postinstall script in the package through command. And even I have changed the file mode to executable "chmod a+x" before using it in "productbuild" command.

Here is what I am using for command line and in postinstall script and I have name the file to "postinstall.sh".

command line:-
productbuild --component "$appDir" "/Applications" --scripts "../Scripts" --sign "Developer ID Installer: $DEVNAME" "$appName.pkg"

postinstall.sh:-
#!/usr/bin/env bash

open -n -a /Applications/appname.app

exit 0

when package is created and I try to install the application on my mac, Installation runs smooth and app is install under application folder but postinstall script does not for some reason.

please advise if I have missed out something or anything on running the postinstall script would be appreciated.

Thanks in advance

Note : This app is generated by Unity engine.
How are you checking the postinstall script is failing? Are you examining /var/log/install.log (also in Console.app) to see if there are any messages?
In general, the environments for package scripts are restricted, I would be surprised if "/usr/bin/env bash" is runnable there.
Yes, I am checking it in install.log in Console app.
I am fairly new to installer and adding the postinstall script to package. whatever help I could get on postinstall scripts, I collected it by google. I don't know how It is supposed to work and Is the correct way to load the app?

By google, I know this much that open command will run any application given if the application is locate at correct path. I think, for my case the path is also correct. Maybe you are right, due environment issue it might not be running. So, What do you suggest on changes that need to do in postinstall script to open the application right after installation.
It would be best to post the error messages from the log here (they will likely describe the exact issue), but you might just try changing the interpreter to "/bin/bash".
Normally macOS installers don't open installed targets on the user's behalf (installers just install), and the only other case would be to load and start a service, which usually involves launchctl(1).
I changed the env to "/bin/bash" still application did not open after the installation. I have attached log of installer of the application.

I agreed that, macOS installers does not open installed targets but I have since couple of installer which has launch option in the summary part of installer and even if you check Zoom installer, you will see that it opens up right after installation is completed. I'm not sure about how to add the launch option in the installer but postinstall script seems to be easiest way to do it at least for me.



It worked for me after I removed ".sh" extension from the script file name.
I am facing the same issue? is there any solution for this. Above suggestions did not work for me.

The postinstall script should be executable. chmod 755

The problem here is that the postinstall script must be supplied to pkgbuild --scripts

Then supply that package to productbuild

I was having the same issue but then I found a solution.

Instead of running only 1 command like you were trying to do (productbuild --component "$appDir" "/Applications" --scripts "../Scripts" --sign "Developer ID Installer: $DEVNAME" "$appName.pkg")

I now run 3 commands:

1: pkgbuild --root "MyApp.app" --identifier com.my.app --sign "Developer ID Installer: $DEVNAME" --scripts Scripts --install-location "/Applications/MyApp.app" Distribution.pkg

2: productbuild --synthesize --package Distribution.pkg Distribution.xml

3: productbuild --distribution Distribution.xml --sign "Developer ID Installer: $DEVNAME" --resources Resources --package-path . MyApp.pkg

Then when I run MyApp.pkg the installer runs the postinstall script opening the app.

Note: I have the postinstall file without extension.

PostInstall script not running on MacOS
 
 
Q