1#!/bin/sh
2
3INSTPREFIX="/opt/cisco/anyconnect"
4BINDIR="${INSTPREFIX}/bin"
5PLUGINSDIR="${BINDIR}/plugins"
6LIBDIR="${INSTPREFIX}/lib"
7PROFILESDIR="${INSTPREFIX}/websecurity"
8ACMANIFESTDAT="${INSTPREFIX}/VPNManifest.dat"
9WEBSECMANIFEST="ACManifestWebSecurity.xml"
10UNINSTALLLOG="/tmp/websecurity-uninstall.log"
11
12ANYCONNECT_WEBSECURITY_PACKAGE_ID=com.cisco.pkg.anyconnect.websecurity
13
14# Array of files to remove
15FILELIST=("${INSTPREFIX}/${WEBSECMANIFEST}"
16 "${BINDIR}/acwebsecagent"
17 "${BINDIR}/websecurity_uninstall.sh"
18 "${LIBDIR}/libboost_filesystem.dylib"
19 "${LIBDIR}/libboost_system.dylib"
20 "${LIBDIR}/libboost_thread.dylib"
21 "${LIBDIR}/libboost_date_time.dylib"
22 "${INSTPREFIX}/libacwebsecapi.dylib"
23 "${INSTPREFIX}/libacwebsecctrl.dylib")
24
25echo "Uninstalling Cisco AnyConnect Web Security Module..."
26echo "Uninstalling Cisco AnyConnect Web Security Module..." > ${UNINSTALLLOG}
27echo `whoami` "invoked $0 from " `pwd` " at " `date` >> ${UNINSTALLLOG}
28
29# Check for root privileges
30if [ `whoami` != "root" ]; then
31 echo "Sorry, you need super user privileges to run this script."
32 echo "Sorry, you need super user privileges to run this script." >> ${UNINSTALLLOG}
33 exit 1
34fi
35
36# update the VPNManifest.dat; if no entries remain in the .dat file then
37# this tool will delete the file - DO NOT blindly delete VPNManifest.dat by
38# adding it to the FILELIST above - allow this tool to delete the file if needed
39if [ -f "${BINDIR}/manifesttool" ]; then
40 echo "${BINDIR}/manifesttool -x ${INSTPREFIX} ${INSTPREFIX}/${WEBSECMANIFEST}" >> ${UNINSTALLLOG}
41 ${BINDIR}/manifesttool -x ${INSTPREFIX} ${INSTPREFIX}/${WEBSECMANIFEST}
42fi
43
44# check the existence of the manifest file - if it does not exist, remove the manifesttool
45if [ ! -f ${ACMANIFESTDAT} ] && [ -f ${BINDIR}/manifesttool ]; then
46 echo "Removing ${BINDIR}/manifesttool" >> ${UNINSTALLLOG}
47 rm -f ${BINDIR}/manifesttool
48fi
49
50# move the plugins to a different folder to stop the websec agent and then remove
51# these plugins once websec agent is stopped.
52echo "Moving plugins from ${PLUGINSDIR}" >> ${UNINSTALLLOG}
53mv -f ${PLUGINSDIR}/libacwebsecapi.dylib ${INSTPREFIX} 2>&1 >/dev/null
54echo "mv -f ${PLUGINSDIR}/libacwebsecapi.dylib ${INSTPREFIX}" >> ${UNINSTALLLOG}
55mv -f ${PLUGINSDIR}/libacwebsecctrl.dylib ${INSTPREFIX} 2>&1 >/dev/null
56echo "mv -f ${PLUGINSDIR}/libacwebsecctrl.dylib ${INSTPREFIX}" >> ${UNINSTALLLOG}
57
58# wait for 2 seconds for the websecagent to exit
59sleep 2
60
61# ensure that the websec agent is not running
62WEBSECPROC=`ps -A -o pid,command | grep '(${BINDIR}/acwebsecagent)' | egrep -v 'grep|websecurity_uninstall' | cut -c 1-5`
63if [ ! "x${WEBSECPROC}" = "x" ] ; then
64 echo Killing `ps -A -o pid,command -p ${WEBSECPROC} | grep ${WEBSECPROC} | egrep -v 'ps|grep'` >> ${UNINSTALLLOG}
65 kill -TERM ${WEBSECPROC} >> ${UNINSTALLLOG} 2>&1
66fi
67
68# Remove only those files that we know we installed
69INDEX=0
70while [ $INDEX -lt ${#FILELIST[@]} ]; do
71 echo "rm -rf "${FILELIST[${INDEX}]}"" >> ${UNINSTALLLOG}
72 rm -rf "${FILELIST[${INDEX}]}"
73 let "INDEX = $INDEX + 1"
74done
75
76# Remove the plugins directory if it is empty
77if [ -d ${PLUGINSDIR} ]; then
78 if [ ! -z `find "${PLUGINSDIR}" -prune -empty` ] ; then
79 echo "rm -df "${PLUGINSDIR}"" >> ${UNINSTALLLOG}
80 rm -df "${PLUGINSDIR}" >> ${UNINSTALLLOG} 2>&1
81 fi
82fi
83
84# Remove the bin directory if it is empty
85if [ -d ${BINDIR} ]; then
86 if [ ! -z `find "${BINDIR}" -prune -empty` ] ; then
87 echo "rm -df "${BINDIR}"" >> ${UNINSTALLLOG}
88 rm -df "${BINDIR}" >> ${UNINSTALLLOG} 2>&1
89 fi
90fi
91
92# Remove the bin directory if it is empty
93if [ -d ${LIBDIR} ]; then
94 if [ ! -z `find "${LIBDIR}" -prune -empty` ] ; then
95 echo "rm -df "${LIBDIR}"" >> ${UNINSTALLLOG}
96 rm -df "${LIBDIR}" >> ${UNINSTALLLOG} 2>&1
97 fi
98fi
99
100# Remove the profiles directory
101# During an upgrade, the profiles will be moved and restored by
102# preupgrade and postupgrade scripts.
103
104if [ -d ${PROFILESDIR} ]; then
105 echo "rm -rf "${PROFILESDIR}"" >> ${UNINSTALLLOG}
106 rm -rf "${PROFILESDIR}" >> ${UNINSTALLLOG} 2>&1
107fi
108
109# remove installer receipt
110pkgutil --forget ${ANYCONNECT_WEBSECURITY_PACKAGE_ID} >> ${UNINSTALLLOG} 2>&1
111
112echo "Successfully removed Cisco AnyConnect Web Security Module from the system." >> ${UNINSTALLLOG}
113echo "Successfully removed Cisco AnyConnect Web Security Module from the system."
114
115exit 0