#!/bin/sh
# $1 has the path to the source package
# $2 has the path to the target folder
# $3 has the path to the target volume
# $USER has the name of the user who launched the installer

if [ -f "$1/Contents/Resources/KeyboardChooser.app/Contents/MacOS/KeyboardChooser" ]; then
	/usr/bin/sudo -u $USER "$1/Contents/Resources/KeyboardChooser.app/Contents/MacOS/KeyboardChooser"
fi

if [ -e "$1/Contents/Resources/LCC Uninstaller Tool" ] ; then
	"$1/Contents/Resources/LCC Uninstaller Tool" --preinstall
fi

"$1/Contents/Resources/RMover" "$1" --preflight

# enforce permissions

if [ -e "/System/Library/Extensions/LogitechHIDDevices.kext" ] ; then
	/usr/sbin/chown -R root:wheel "/System/Library/Extensions/LogitechHIDDevices.kext"
	/bin/chmod -R ug+r,go-w "/System/Library/Extensions/LogitechHIDDevices.kext"
elif [ -e "/System/Library/Extensions/LogicoolHIDDevices.kext" ] ; then
	/usr/sbin/chown -R root:wheel "/System/Library/Extensions/LogicoolHIDDevices.kext"
	/bin/chmod -R ug+r,go-w "/System/Library/Extensions/LogicoolHIDDevices.kext"
fi

exit 0
