Question

I have an issue in my custom installer that occurs when I append a postinstall script to the pkg. On my computer the installation works just fine, but on other users' systems the .app is installed but the postinstall script fails without execution.

If I remove the --scripts argument on pkgbuild, the installer produces no issues. If I add it (and even if the postinstall script is empty) a "failed installation" message is shown. No logs are produced.

The pkg is built using a script similar to this:

pkgbuild --identifier $PKG_IDENTIFIER \
         --version $APP_VERSION \
         --root $APP_PATH \
         --scripts Scripts/ \
         --install-location /Applications/$APP_NAME.app $TMP_PKG_PATH

productbuild --sign "Developer ID Installer: $COMPANY_NAME" \
             --distribution Distribution.xml \
             --package-path $INSTALLER_BUILD_PATH $INSTALLER_PKG_PATH

On my system the app is installed into /Applications and the postinstall script runs and does it's business. On other systems the postinstall doesn't even seem to be executed at all.

It has been tested on OSX 10.8 and 10.7 and both get the same issue. The postinstall script is tested independently on all systems (using ./postinstall in the Terminal) and works.

The script looks like this:

#!/usr/bin/env sh
set -e

# Install launch agent
LAUNCH_AGENT_SRC="/Applications/MyApp.app/Contents/Resources/launchd.plist"
LAUNCH_AGENT_DEST="$HOME/Library/LaunchAgents/com.company.myapp.agent.plist"

# Uninstall old launch agent
if [ -f "$LAUNCH_AGENT_DEST" ]; then
  launchctl unload "$LAUNCH_AGENT_DEST"
  rm -f "$LAUNCH_AGENT_DEST"
fi

cp "$LAUNCH_AGENT_SRC" "$LAUNCH_AGENT_DEST"
launchctl load "$LAUNCH_AGENT_DEST"

# Open application
open -a "MyApp"

exit 0

What could be causing this issue?

Was it helpful?

Solution

It seems the cause of the issue was the if statement. And when it wasn't present the contents of the if could cause the error to fire unless the launch agent was installed already.

I solved it by switching the code for:

#!/usr/bin/env sh
set -e

# Launch agent location
LAUNCH_AGENT_SRC="/Applications/MyApp.app/Contents/Resources/launchd.plist"
LAUNCH_AGENT_DEST="$HOME/Library/LaunchAgents/com.company.myapp.agent.plist"

# Uninstall old launch agent
launchctl unload "$LAUNCH_AGENT_DEST" || true
rm -f "$LAUNCH_AGENT_DEST" || true

# Install launch agent
cp "$LAUNCH_AGENT_SRC" "$LAUNCH_AGENT_DEST" || true
launchctl load "$LAUNCH_AGENT_DEST" || true

# Open application
open -a "MyApp"

exit 0

The error I made before when testing an empty script was not having exit 0 at the end. So now when I got that working I could activate different rows of the code and see what was causing an error.

OTHER TIPS

You might have found your answer already, and it's a bit hard to say without looking at the script, but can you make sure that you have "exit 0" at the end of your postinstall script?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top