How to exit with exit code from pkg installer

adamberns
New Contributor III

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 3

Qwheel
Contributor II

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
Legendary Contributor III

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.

DebstepFRB
New Contributor III

you could try running your package like this : 

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

exitcode=$pkgexitcode