#!/bin/bash ################################################################################ # # File: agent_unload.sh # # Contains: Shell script that unloads the PACE Eden agent. # This script must be run as root in order to work. # # Copyright: (C) 2018 by PACE Anti-Piracy, all rights reserved. # ################################################################################ #------------------------------------------------------------------------------- # Initialize script globals #------------------------------------------------------------------------------- # Define the agent plist and path constants gAgentLabel="com.paceap.eden.licensed.agent" gAgentPlistPath="/Library/LaunchAgents/$gAgentLabel.plist" # macOS 10.10 Yosemite is the first version that supports launchctl 2.0. # We need this version or above to support the launchctl "asuser" option. gYosemiteMajorVersion=14 # Get the OS version gOsVersion=`uname -r` gOsMajorVersion=${gOsVersion%%.*} #echo "Running OS vers $gOsVersion, major version $gOsMajorVersion." # Define the launchctl tool to use. For standalone scripts, this should include the # "sudo" command. gLaunchctlCommand="/bin/launchctl" #------------------------------------------------------------------------------- fatalError() { echo "Error: $1" exit 1 } #------------------------------------------------------------------------------- # Unload LicenseD agent via launchctl for all logged in users. #------------------------------------------------------------------------------- unloadAgentManually() { echo "Unloading LicenseD agent..." # Check to see if the LicenseD agent plist file exists. If it doesn't then # There's nothing to unload if [[ ! -f "$gAgentPlistPath" ]]; then echo "Could not find the LicenseD agent plist file. Nothing to unload." else # Unload the agent for all logged in users if [[ $gOsMajorVersion -ge $gYosemiteMajorVersion ]]; then for pid_uid in $(ps -axo pid,uid,args | grep -i "[l]oginwindow.app" | awk '{print $1 "," $2}'); do pid=$(echo $pid_uid | cut -d, -f1) uid=$(echo $pid_uid | cut -d, -f2) echo "Unloading this plist for user $uid: $gAgentPlistPath" `$gLaunchctlCommand asuser "$uid" $gLaunchctlCommand unload $gAgentPlistPath` done else fatalError "launchctl asuser command not available on this OS version." fi fi } #------------------------------------------------------------------------------- # Script starts here #------------------------------------------------------------------------------- # We only support the agent on Yosemite and above. if [[ $gOsMajorVersion -ge $gYosemiteMajorVersion ]]; then unloadAgentManually else echo "Not unloading the LicenseD agent because the OS is too old." fi # Exit with success exit 0