Skip to content

Instantly share code, notes, and snippets.

@chrisgrande
Created March 8, 2023 19:44
Show Gist options
  • Save chrisgrande/add4e0d025cab44883843cc75945d57d to your computer and use it in GitHub Desktop.
Save chrisgrande/add4e0d025cab44883843cc75945d57d to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get Policy Paramamter for the Installer UID.
BOMGAR_CODE=$4
if [ -z "$BOMGAR_CODE" ]; then
echo "You must configure the installer UID in the Jamf Policy!"
exit 1
fi
CACHED_LOCATION="/Library/Application Support/JAMF/Waiting Room"
# Preinstall script for Bomgar Jump Client
# Find any existing Bomgar pkg install receipts and forget them
pkgutil --forget "$( pkgutil --pkgs | grep com.therealreal.pkg.BomgarClient )"
# Find the existing Bomgar install in /Users then run the uninstall command
sd=$( find /Users/Shared /Applications -iname "sdcust" -type f -maxdepth 5 )
[ -f "$sd" ] && "$sd" -uninstall silent
# This is the manual cleanup process in case the previous command didn't work
# Are there any LaunchAgents from a previous install?
test=$( /usr/bin/find /Library/LaunchAgents -iname "com.bomgar.bomgar*.plist" | wc -l | awk '{ print $1 }' )
# More than zero means we have work to do
if [ "$test" -gt 0 ];
then
# Attempt to unload all the launchd agents and daemons
/usr/bin/find /Library/LaunchAgents -iname "com.bomgar*.plist" -type f -exec bash -c '/bin/launchctl unload $@' _ {} +
/usr/bin/find /Library/LaunchDaemons -iname "com.bomgar*.plist" -type f -exec bash -c '/bin/launchctl unload $@' _ {} +
# Remove all the launchd agents and daemons
/usr/bin/find /Library/LaunchAgents -iname "com.bomgar*.plist" -exec rm -rf {} \;
/usr/bin/find /Library/LaunchDaemons -iname "com.bomgar*.plist" -exec rm -rf {} \;
# Remove any existing install folders
rm -rf /Users/Shared/bomgar-scc*
rm -rf /Applications/.com.bomgar*
# Finally kill any running processes
/bin/ps -ax | /usr/bin/grep 'bomg*' | /usr/bin/grep -v grep | /usr/bin/awk '{ print $1 }' | /usr/bin/xargs kill
fi
# Postinstall script for Bomgar Jump Client
# Work out what folder we're operating from
installdir=$( /usr/bin/dirname $0 )
# Find the dmg we're going to process. We're set up only to do one diskimage in this script.
correctdiskimage="$CACHED_LOCATION/bomgar-scc-${BOMGAR_CODE}.dmg"
if [ -z "$correctdiskimage" ]; then
echo "Could not locate bomgar-scc.dmg"
exit 1
fi
sleep 3
# Create a temporary folder to mount the dmg to.
tmpmnt=$( /usr/bin/mktemp -d /private/tmp/tempinstall.XXXXXX )
# Error check to see if temporary folder was created. Fail out if not. Unlikely.
if [ $? -ne 0 ];
then
echo "$0: Cannot create temporary folder. Exiting."
exit 1
fi
# Mount the dmg into the temporary folder we just created. Make sure it doesn't annoy the user by hiding what it's doing.
/usr/bin/hdiutil attach "$correctdiskimage" -mountpoint "$tmpmnt" -nobrowse -noverify -noautoopen
# Find the path of the binary we're looking for
sdc=$( /usr/bin/find "$tmpmnt" -iname "sdcust" -type f )
# Run the install binary
"$sdc" --silent
sleep 60
# Unmount the disk image
/usr/bin/hdiutil detach "$tmpmnt"
# Remove the temporary mount point. It should be automatic but this will catch if it's not.
rm -rf "$tmpmnt"
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment