#!/bin/bash #check if this script runs in root user account whoami | grep -i "root" errcode=$? #echo "Error code of previous command: $errcode" if [ "$errcode" -ne 0 ]; then echo "" echo "Script failed! Execute this script as shown below(sudo or as root user):" echo "sudo ./configurePMPAgentServerCommunication.sh " echo "" exit 0 fi if [ "$#" != "5" ] then echo "Script failed! Execute this script with correct arguments:" echo "sudo ./configurePMPAgentServerCommunication.sh " exit 0 fi servicePath="/Library/PatchManagerPlus_Agent/bin/dcagentservice" if [ -f "$servicePath" ] then echo "" else echo "PatchManagerPlus Agent is not installed on this machine.Refer this link" echo "https://www.manageengine.com/patch-management/help/managing-mac-computers.html" exit 0 fi echo "Setting PatchManagerPlus Server details..." dupserverinfoPath="/Library/PatchManagerPlus_Agent/data/dupserverinfo.plist" serverinfoPath="/Library/PatchManagerPlus_Agent/data/serverinfo.plist" metadataPath="/Library/PatchManagerPlus_Agent/data/meta-data.xml" ifmodifiedfilePath="/Library/PatchManagerPlus_Agent/data/if_modified.plist" if [ "$#" == "1" ] then #This sleep time is required to let the dcconfig process to finish its execution. sleep 5 fi if [ -f "$metadataPath" ] then rm -rf $metadataPath fi if [ -f "$ifmodifiedfilePath" ] then rm -rf $ifmodifiedfilePath fi /usr/libexec/PlistBuddy -c "Set :SERVERNAME $1" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERFLATNAME $1" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERIPADDRESS $2" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERSECIPADDRESS $2" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERPORT $3" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERSECUREPORT $4" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERPROTOCOL $5" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Delete :dclastaccessname" $dupserverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERNAME $1" $serverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERFLATNAME $1" $serverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERIPADDRESS $2" $serverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERSECIPADDRESS $2" $serverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERPORT $3" $serverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERSECUREPORT $4" $serverinfoPath /usr/libexec/PlistBuddy -c "Set :SERVERPROTOCOL $5" $serverinfoPath /usr/libexec/PlistBuddy -c "Delete :dclastaccessname" $serverinfoPath killall kill dcagentservice #Restart service echo "Return code :$?" echo "" echo "Successfully changed PatchManagerPlus Server details" exit 0