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

ANYCONNECT_OPENDNS_PACKAGE_ID=com.cisco.pkg.anyconnect.umbrella

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

echo "Restoring AnyConnect RSM Agent"
echo "Restoring AnyConnect RSM 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 acumbrellaagent to a different folder to stop the service from respawning.
echo "Moving acumbrellaagent from ${INSTPREFIX} to ${BINDIR}" >> ${UNINSTALLLOG}
echo "mv -f ${INSTPREFIX}/acumbrellaagent ${BINDIR}" >> ${UNINSTALLLOG}
mv -f ${INSTPREFIX}/acumbrellaagent ${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 RSM Agent from the system." >> ${UNINSTALLLOG}
echo "Successfully restored Cisco AnyConnect RSM Agent from the system."

exit 0
