#!/bin/sh

INSTPREFIX="/opt/cisco/anyconnect"
BINDIR="${INSTPREFIX}/bin"
PLUGINSDIR="${BINDIR}/plugins"
LIBDIR="${INSTPREFIX}/lib"
PROFILESDIR="${INSTPREFIX}/umbrella"
ACMANIFESTDAT="${INSTPREFIX}/VPNManifest.dat"
OPENDNSMANIFEST="ACManifestUmbrella.xml"
UNINSTALLLOG="/tmp/umbrella-swg-disable.log"

ANYCONNECT_OPENDNS_PACKAGE_ID=com.cisco.pkg.anyconnect.umbrella

# Array of files to remove
FILELIST=("${INSTPREFIX}/${OPENDNSMANIFEST}" \
          "${BINDIR}/acswgagent")

echo "Removing AnyConnect SWG Agent"
echo "Removing AnyConnect SWG Agent" > ${UNINSTALLLOG}
echo `whoami` "invoked $0 from " `pwd` " at " `date` >> ${UNINSTALLLOG}

# Check for root privileges
if [ `whoami` != "root" ]; then
  echo "Sorry, you need super user privileges to run this script."
  echo "Sorry, you need super user privileges to run this script." >> ${UNINSTALLLOG}
  exit 1
fi

# move acswgagent to a different folder to stop the service from respawning.
echo "Moving acswgagent from ${BINDIR} to ${INSTPREFIX}" >> ${UNINSTALLLOG}
echo "mv -f ${BINDIR}/acswgagent ${INSTPREFIX}" >> ${UNINSTALLLOG}
mv -f ${BINDIR}/acswgagent ${INSTPREFIX}

# unload anyconnect to remove swg agent
launchctl unload /Library/LaunchDaemons/com.cisco.anyconnect.vpnagentd.plist 

# wait for 2 seconds for anyconnect to exit
#sleep 2

# load anyconnect (sans swg agent)
launchctl load /Library/LaunchDaemons/com.cisco.anyconnect.vpnagentd.plist 

echo "Successfully removed Cisco AnyConnect SWG Agent from the system." >> ${UNINSTALLLOG}
echo "Successfully removed Cisco AnyConnect SWG Agent from the system."

exit 0
