#!/bin/bash
# $Header: /cvs/WebShield/wsrc/files/mgmt/uninstall_epo_agent,v 1.3 2004/07/29 17:35:31 bwhittak Exp $
# $Date: 2004/07/29 17:35:31 $
#
# Copyright (C) 2004 Networks Associates Technology Inc. All rights reserved. 
#
if [ -f $NETAWSS/.profile.vars ]; then
    . $NETAWSS/.profile.vars
else
    . /var/NAIENV/.profile.vars
fi
[[ "$PATH" == "$wsPATH":* || -z "$wsPATH" ]] || PATH=$wsPATH:$PATH

LOGFILE=/tmp/epo_uninstall.log

exec >> ${LOGFILE} 2>&1 

echo -e "\n------- Start `date`"  
echo "User has requested that the ePolicy Orchestrator Agent be removed"

inst=${0##*/}.$(date -u +%Y%m%d%H%M%S).$$

trap "rm -f /tmp/*.$inst" EXIT

echo "Resetting config values"
# run style sheet to disable ePO channel /Channel[@name='epo'] set enabled = 'no' (channels.xml)
$NETAWSS/mgmt/xml-replace $NETAWSS/mgmt/uninstall_epo_agent_channels /config/wsxmlconf/channels.xml /tmp/t.$inst &&
    [[ -s /tmp/t.$inst ]] && mv /tmp/t.$inst /config/wsxmlconf/channels.xml || exit
# run style sheet to disable ePO channel /Settings[@name='epoagent'] set enabled = '0' (machines.xml)
$NETAWSS/mgmt/xml-replace $NETAWSS/mgmt/uninstall_epo_agent_machine /config/wsxmlconf/machine.xml /tmp/t1.$inst &&
    [[ -s /tmp/t1.$inst ]] && mv /tmp/t1.$inst /config/wsxmlconf/machine.xml || exit

echo "Applying updated config"
update-xmlconf

sleep 10

umount -f /opt/NETASSOC
umount -f /opt/NETAepoagt/scratch

echo "Removing the rpms"
echo 'rpm -e --nodeps NWA webshield-ePO; rm -rf /opt/NETASSOC /opt/NETAepoagt' | wsmount

echo "Finished Uninstall of ePolicy Orchestrator Agent"

exit 0

