#!/bin/bash ################################################################################ # # File: agent_load.sh # # Contains: Shell script that loads 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 } #------------------------------------------------------------------------------- # Load LicenseD agent via launchctl for all logged in users. #------------------------------------------------------------------------------- loadAgentManually() { echo "Loading LicenseD agent..." # Check to see if the LicenseD agent plist file exists. If it doesn't then it's # an unrecoverable error. if [[ ! -f "$gAgentPlistPath" ]]; then fatalError "Could not find the LicenseD agent plist file. Please reinstall License Support." fi # Load 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 "Loading this plist for user $uid: $gAgentPlistPath" `$gLaunchctlCommand asuser "$uid" $gLaunchctlCommand load $gAgentPlistPath` done else fatalError "launchctl asuser command not available on this OS version." fi } #------------------------------------------------------------------------------- # Script starts here #------------------------------------------------------------------------------- # We only support the agent on Yosemite and above. if [[ $gOsMajorVersion -ge $gYosemiteMajorVersion ]]; then # Load the agent for all logged in users loadAgentManually else echo "Not loading the LicenseD agent because the OS is too old." fi # Exit with success exit 0