I'm trying to include a postinstall script in my pkg but it doesn't seem to work.
electron-osx-flat MyApp.app --identity="3rd Party Mac Developer Installer: BLAHBLAH LTD (******)" --scripts="./scripts/" --install="/Applications"
./scripts/postinstall
mkdir ~/test
I run the install and the ~/test folder is not there. Hoping this is a pebkac; what am I doing wrong?
Hi @MrPanos thanks for filing this issue! I'm sorry but I haven't tested --scripts myself but syntactically the code should work.
Referring to the original PR https://github.com/electron-userland/electron-osx-sign/pull/86, I think @samb90 may know more about how this option with productbuild works in production.
If I expand the pkg file I can see the postinstall script is in there. It just doesn't seem to get triggered when the installer runs.
@MrPanos would you like to try the following to see if the script indeed runs? I haven't tested it myself however. A file should be created in the temporary folder with this.
#!/bin/sh
echo "Running postinstall" > /tmp/my_postinstall.log
@sethlu I tried this with
#!/bin/sh
mkdir ~/test
The directory was not created.
@MrPanos mmm one question I'm unsure about Installer is that from which user it executes the postinstall script. If it's not initiated from the current user (who started the installation), ~ wouldn't direct to where we want it to (under the current user directory).
Has the /tmp/my_postinstall.log appeared by the way?
Apologies for the late response. I've added your code to the postinstall.sh script and no /tmp/my_postinstall.log does not appear.
Just to add, even though it should be obvious, If I run the script manually the file is created as is the test folder which I've now changed to '/tmp/test'
I've done a bit more digging by making an installer with electron-osx-flat and using another app were the postinstall script runs fine, after expanding the pkg using pkgutil it seems that elextron-osx-flat puts the Scripts folder in the wrong location .
When I expand the pkg file created by the other app (that works properly) the structure is :
However electron-osx-flat creates the following hierarchy
As you can see the Scripts folder is outside the pkg folder with electron-osx-flat, this is the most likely cause.
Also an additional point, the postinstall script in the other app is simply named _postinstall_ without the .sh extension. This isn't something to do with electron-osx-flat, just something which I think is interesting since it's unconventional.
@MrPanos I'm not very sure how the pkg should be organized as electron-osx-sign utilizes the productbuild. However, I have found this online which may be helpful if added to the current workflow, which says a different (but very likely correct) way to create such packages:
http://thegreyblog.blogspot.com/2014/06/os-x-creating-packages-from-command_2.html
If it proves to be useful, I may work on a feature to incorporate this in electron-osx-flat. Let me know!
I think this functionality is out of scope for electron-osx-sign. Today scripts is requested, tomorrow js scripts :) electron-builder 13.3.0 supports scripts for the pkg target. electron-osx-sign for sign, not for build ;)
@sethlu close as out of scope?
Closed, @MrPanos I would recommend checking out electron-builder as it provides options to output pkg with proper embedding of post install scripts I believe.
@develar I think in a next major bump, electron-osx-flat can probably be deprecated in this module as electron-builder has similar features.
@malept I don't think electron-packager is using this feature in the module?
Nope.
postinstall runs as root so your directory gets created in /var/root on macOS.