Running postflight script when installing a package on Mac
Asked Answered
S

1

6

I am trying to build a mac package installer from a script and I want to run postinstall and postflight scripts. My script for building the package looks like this:

pkgbuild --root MyRoot/MyApp.app --identifier com.myapp.MyApp --scripts Scripts --install-location /Applications/MyApp.app MyApp.pkg
productbuild --synthesize --package MyApp.pkg Distribution.xml
productbuild --distribution Distribution.xml --resources Resources --package-path . CompleteInstaller.pkg

I've placed the postinstall script in Scripts and it is being executed successfully. I have a problem with running the postflight script though. It is placed in the Resources directory and doesn't get executed. Is this not enough to specify the path to it? I couldn't find an answer to this question, I'm sorry if I've missed it.

PS: My postflight script does nothing special - for now it tries to create a file in the home directory:

#!/bin/sh
touch ~/file
exit 0
Selfsame answered 14/11, 2013 at 13:12 Comment(1)
How can this possibly work with the typo "Scirpts"?!Undertaker
S
10

I am not sure why do you have both postinstall and postflight in a package. Both are same scripts which must be run after the "copy files" phase of the installation. "postflight" name was used in older style packages - bundles. After the introduction of flat packages, the same script has to be named as "postinstall". In flat packages, installer treats a file as a postinstall script only if its name is "postinstall", not "postflight" and is present inside "Scripts" directory, not "Resources" directory. Probably, this is the reason your script is not being executed.

You can get some more information regarding scripts used in packages here.

Stander answered 17/11, 2013 at 18:59 Comment(3)
I have been trying with post_install like it used to be, for almost an hour :) Thanks a lot :)Adelladella
Nice post @Vikram SinghShani
Extra tip: my scripts seemed to be correctly named but they were not working. Until I noticed they had the extension .command which was hidden by MacOS. Once I removed .command, all was well.Pukka

© 2022 - 2024 — McMap. All rights reserved.