#!/bin/bash

# get necessary plists
appInfoPlistName="/Library/ManageEngine/UEMS_Agent/data/dcconfig_data.plist"

# make this computer imaging ready
/usr/libexec/PlistBuddy -c "Delete :ImageDetectTime" $appInfoPlistName 2>/dev/null

/usr/libexec/PlistBuddy -c "Delete :ImagedComputer" $appInfoPlistName 2>/dev/null

/usr/libexec/PlistBuddy -c "Delete :ImageWaitDays" $appInfoPlistName 2>/dev/null

/usr/libexec/PlistBuddy -c "Delete :StopAgentReporting" $appInfoPlistName 2>/dev/null

/usr/libexec/PlistBuddy -c "Delete :ImageRetryCount" $appInfoPlistName 2>/dev/null

/usr/libexec/PlistBuddy -c "Delete :ImageReportInterval" $appInfoPlistName 2>/dev/null

/usr/libexec/PlistBuddy -c "Delete :ImageReportTime" $appInfoPlistName 2>/dev/null

/usr/libexec/PlistBuddy -c "Add :ImagedComputer string Yes" $appInfoPlistName 2>/dev/null

exitCode=$?

if [ "$exitCode" = "0" ]; then
    killall -KILL dcondemand
    killall kill dcagenttrayicon
    echo "Successfully executed."
else
    echo $exitCode
    echo "Failed to set ImagedComputer, Please contact Endpoint Central support."
fi

exit $exitCode