#!/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-enable.log"

ANYCONNECT_OPENDNS_PACKAGE_ID=com.cisco.pkg.anyconnect.umbrella

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

echo "Restoring AnyConnect SWG Agent"
echo "Restoring 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 ${INSTPREFIX} to ${BINDIR}" >> ${UNINSTALLLOG}
echo "mv -f ${INSTPREFIX}/acswgagent ${BINDIR}" >> ${UNINSTALLLOG}
mv -f ${INSTPREFIX}/acswgagent ${BINDIR}

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

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

# load anyconnet with swg!
launchctl load /Library/LaunchDaemons/com.cisco.anyconnect.vpnagentd.plist 

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

exit 0
