Skip to main content
Question

How to exit with exit code from pkg installer


Forum|alt.badge.img+5

I have a pkg that I need to install, however, it must be installed from a specific location:

/Library/Application\\ Support/TheApp/installer.pkg (not the real name)

If I run sudo installer -pkg /Library/Application\\ Support/TheApp/installer.pkg -target / the script ends and I get a return code, 125, 160, whatever, not just 0 or 1. I need to get the same result from from log of the installer.

So I have a DMG that delivers the pkg to the proper location.

I then have a script that runs last:

sudo installer -pkg /Library/Application\\ Support/TheApp/installer.pkg -target /
pkgexitcode=$?
echo $pkgexitcode > /Users/Shared/AppExitCode.log
echo $pkgexitcode
exit $pkgexitcode

It will only return 0 in JAMF, and the log file also returns 0, though I know it is not (based off other log files that are generated)

3 replies

Forum|alt.badge.img+8
  • Valued Contributor
  • 109 replies
  • June 18, 2022

Maybe use an if else conditional statement.

As for grabbing the correct exit code, I suspect you could grep it from install.log but I can’t see what you’re looking at.


if [ -x /Applications/program.app ]; then
echo “App exists”
exit 0
else
echo “App doesn’t exist”
fi

exit 1


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • June 21, 2022

Taking a couple of steps back here, why does this installer need to be installed from that specific location? You may want to dig into this a bit to understand why it requires this. For example, does it need to be able to see a configure file in the same location when it's being installed? If so, there are other ways to approach this so you don't have to jump through all these hoops to get their wares installed.


Forum|alt.badge.img+6
  • Contributor
  • 20 replies
  • June 21, 2022

you could try running your package like this : 

pkgexitcode=$(installer -pkg /Library/Application\\ Support/TheApp/installer.pkg -target /)

exitcode=$pkgexitcode


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings