Using pkgbuild I create installer for my OSX application. Is there any way to add extra install step, which will delete some files? In this particular example - when I run my application it creates new file in directory where binary is located. Installation of new version replaces binary, but leaves that previously created file. I need "fresh start" after installation of new version.
You can add a postinstall script to your package and delete all the files that are not required any more. Create a shell script and put your code for deleting those files in it. Name that script postinstall (without extension) and put is in a folder named script. Create your package with this command:
/usr/bin/pkgbuild \
--root "$ROOT_LOCATION" \
--install-location "$INSTALL_LOCATION" \
--identifier "$IDENTIFIER" \
--version "$VERSION" \
--scripts "scripts" \
"$NAME.pkg"
when the installer runs the postinstall script it also passes some useful information as the path on which the script is running and so on. You can read these information as input arguments $1, $2, ...