Package preinstall and postinstall errors

jhbush
Valued Contributor II

I'm having a problem figuring out some packaging errors. Any idea why these scripts would fail when added to a package? I'm basically just looking to kill the app prior to replacing it. Both scripts work fine when run manually. It's only when they are packaged do they cause the install to fail. Any help is greatly appreciated.

#!/bin/sh
## preinstall
##
## Not supported for flat packages.

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

pid=$(ps axo pid,command | grep "[A]DPassMon" | awk '{print $1}')

echo $pid

if [ "$pid" ]; then

    kill $pid

else

    echo "Does not exist"

fi

if [ -d "$3/Applications/ADPassMon.app" ]; then

    rm -rf "$3/Applications/ADPassMon.app"

else

    echo "Does not exist"

fi

exit 0
#!/bin/sh
## postinstall

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3


## Finding local user
user=`ls -l /dev/console | cut -d " " -f 4`

## Launching ADPassMon
sudo -u $user open -a /Applications/ADPassMon.app


exit 0
8 REPLIES 8

bentoms
Esteemed Contributor
Esteemed Contributor

Hi @jhbush1973,

We deploy via a DMG, so we uninstall the version that was there before, then push down the new one.

Also, I launch it via a LaunchAgent... This can then be ran post install too.

Oh & I'm doing some big fixes to my fork of ADPassMon.. If that's then version you're using.. Lemme know if anything isn't quite right.

franton
Valued Contributor III

Tested it this morning actually. Version 2 doesn't seem to change the user password!

franton
Valued Contributor III

Might be us however ...

stevewood
Honored Contributor II
Honored Contributor II

@jhbush1973 can you post the log from a failed attempt to install?

jhbush
Valued Contributor II

@stevewood this is the error I get Install Failed: Error Domain=PKInstallErrorDomain Code=112 "An error occurred while running scripts from the package “ADPassMon196.pkg”

themacdweeb
Contributor

@jhbush1973 i'll assume that you already researched that error code online. best practices suggests making sure that the permissions/ownership of each part of your package is set correctly.

one way to ensure that it's not a permission issue is to set things to 777.

you can do this manually via CLI or, if you're using composer, you can click on each folder and sub-folder and file and change permissions with the checkboxes at the bottom. in this case, i created a launchD script and needed to make sure all users had permission to execute, so i changed it to 777.

external image link

http://www.evernote.com/shard/s261/sh/f178dfdc-8543-48e5-b7fd-335fcbd46240/dcf2b8df5b85ff0529401af09...

Josh_S
Contributor III

@jhbush1973

The problem is that you're searching for processes that have the name 'ADPassMon', without excluding processes that have to do with the installer. You're excluding the 'grep' process by using the bracket expression, but your .pkg includes the string you're searching for too. Because of that, the script actually kills itself.

Give these a try:

#!/bin/sh
## preinstall

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

pid="$(ps axo pid,command | grep "[A]DPassMon.app" | awk '{ print $1 }')"

echo "${pid}"

if [ -n "${pid}" ]; then
    kill ${pid}
else
    echo "Does not exist"
fi

if [ -d "${3}/Applications/ADPassMon.app" ]; then 
    rm -rf "${3}/Applications/ADPassMon.app"
else
    echo "Does not exist"
fi

exit 0
#!/bin/sh
## postinstall

pathToScript=$0
pathToPackage=$1
targetLocation=$2
targetVolume=$3

## Finding local user
user="$(ls -l /dev/console | cut -d " " -f 4)"

## Launching ADPassMon
sudo -u "${user}" open -a /Applications/ADPassMon.app

exit 0

bentoms
Esteemed Contributor
Esteemed Contributor

I've been looking at this, (sorry for not replying sooner here or via email).

You can just update in whilst it's running.

We just have a dmg that installs the newer version.

When the user then calls the app, it'll launch the needed. No need to stop it.