Create pkg with preinstall removal script then points to installer

JayD
New Contributor II

Hey everyone not sure if i worded that properly but looking to create a preinstall script that installs and runs Lotus Notes uninstall silently in the background and installs Lotus Notes 10 after its down.

i created the package with composer yet im stuck on what's next i added a preinstall script that's built in yet don't know how to edit it properly 18e25aad5d3645ca9a7e0a65a14a8193
a04330efdb944c77a306be2d9ddf6103

6 REPLIES 6

WellsJtech
New Contributor III

@JayD I’m not sure how to do the uninstall itself, but to write that you just delete those 4 variables and write the script how you want. When you’re done just click on a different part of the pkg and it’ll ask if you want to save it.

Look
Valued Contributor III

Also your package is going to drop all those files on the root level of the drive. You probably want to put them in a folder in /tmp or similar if they are only needed during the uninstall / install process.
You can create this in the PKG by putting the files you want in that location, then dragging them from there to the PKG in Composer.

CreativeB
New Contributor III

you should put those temporary things to /tmp like Look said. Also, you need to test if the uninstaller is executable with root rights. In the POST-Install you should try to run the binary itself from the uninstaller app - similar to this below. After that you could try to install the pkg. Thereafter you should clean up your mess ;)

#!/bin/sh
#uninstall the app with the recommended tool...
/tmp/MyPackageName/Uninstaller.app/Contents/MacOS/uninstaller

sleep 5

#installing fancy stuff
/usr/sbin/installer -pkg /tmp/MyPackage/Name/IBM Lotus Notes.pkg -target / 

#moving stuff to their destinations...
cp /tmp/MyPackageName/license/ /Users/Shared/license

#cleaning up the mess
rm -R /tmp/MyPackageName


exit 0

If the Uninstaller needs an active user session, you should consider using "Packages" - there is a nice tutorial from rtrouton on his blog

https://derflounder.wordpress.com/2014/02/20/deploying-sophos-anti-virus-for-mac-os-x-9-x/

JayD
New Contributor II

Thanks guys for the info. Also after all this is said and done im supposed to convert this to munki. the same scripts should still run and compile properly right?

@Look @foo_BeBu @Andy_W

alexjdale
Valued Contributor III

I would actually do all of this in a postflight/postinstall script using Packages. Use the PKG to place all of the files you need in a place in /tmp, then the postflight script does the heavy lifting (run the uninstall, then install the new version afterwards).

edward_stewart
New Contributor II

While this thread is two years old and the issue is likely long since solved, I'll add this for posterity anyway, since someone else might come across it later. The original poster mentioned that the package will be distributed with Munki. With Munki, you can include the uninstall script directly in the pkginfo file as a preinstall_script for the installer without needing to create a custom package with Composer or other tools. This method offers more flexibility for future changes since the script exists outside of the package (i.e. you do not need to modify the package to change the script).

makepkginfo --preinstall_script /path/to/a/script

https://github.com/munki/munki/wiki/Pre-And-Postinstall-Scripts 

Munki can coexist with Jamf Pro or any other MDM.