home *** CD-ROM | disk | FTP | other *** search
/ ftp.f-secure.com / 2014.06.ftp.f-secure.com.tar / ftp.f-secure.com / support / tools / uitool / mac / MacProtection / uninstall_MacProtection < prev   
Text File  |  2011-11-28  |  9KB  |  294 lines

  1. #!/bin/sh
  2.  
  3. PARTIAL=false
  4. NUKE_CUSTOMIZATIONS=true
  5.  
  6. while getopts uc opt
  7. do
  8.     case "$opt" in
  9.     u) PARTIAL=true
  10.             ;;
  11.     c) NUKE_CUSTOMIZATIONS=false
  12.         ;;
  13.     \?) echo "Usage: $0"
  14.             exit 1
  15.             ;;
  16.     esac
  17. done
  18.  
  19. MAGIC=/var/db/.com.f-secure.fsmac.uninstall
  20. LOG="/Library/Logs/F-Secure Mac Protection uninstall.log"
  21.  
  22. date "+%Y-%m-%d %T: Uninstall script starting: $0 $*" >> "$LOG"
  23. syslog -s -l Critical "Uninstall script starting: $0 $*"
  24.  
  25. exec 3>&1
  26. exec 1>>"$LOG"
  27. exec 2>>"$LOG"
  28.  
  29. uname -a
  30.  
  31. set -x
  32.  
  33. if [ -r "`dirname $0`/safer_remove_dir" ] ; then
  34.     . "`dirname $0`/safer_remove_dir"
  35. elif [ -r /usr/local/f-secure/bin/safer_remove_dir ] ; then
  36.     . /usr/local/f-secure/bin/safer_remove_dir
  37. else
  38.     echo "Warning: safer_remove_dir not found, using built-in fallback" >&2
  39.     echo "Warning: safer_remove_dir not found, using built-in fallback" >&3
  40.     safer_rmrf() {
  41.     rm -rf "$@"
  42.     }
  43. fi
  44.  
  45. # Make firewall not block
  46. echo '<firewall block="0"/>' > /usr/local/f-secure/signal/firewall
  47.  
  48. # This is the old uninstall trigger which is no longer needed.
  49. launchctl remove com.f-secure.fsmac.uninstall
  50. rm -f /Library/LaunchDaemons/com.f-secure.fsmacuninstall.plist
  51. rm -f /var/db/.com.f-secure.fsmac.uninstall
  52.  
  53. check_error() {
  54.     if test $? -ne 0 ; then
  55.     ERROR=true
  56.     echo "ERROR: $@" >&3
  57.     fi
  58. }
  59.  
  60. fatalexit() {
  61.     {
  62.     echo 
  63.     echo "Uninstallation failed!"
  64.     echo "Please contact support and email them the uninstall log file:"
  65.     echo "$LOG"
  66.     } >&3
  67.     syslog -s -l Critical "Uninstallation failed! Please contact support and email them the uninstall log file: $LOG"
  68.     exit 1
  69. }
  70.  
  71. ####
  72. #
  73. # Main()
  74. #
  75. date "+%Y-%m-%d %H:%M:%S Uninstalling FS Mac:"
  76.  
  77. if [ "`id -u`" != "0" ] ; then
  78.     echo "Need root permissions to perform uninstallation. Run the command as" >&3
  79.     echo "sudo $0" >&3
  80.     exit 1
  81. fi
  82. date "+%Y-%m-%d %H:%M:%S checkpoint 1"
  83. echo "Uninstalling..." >&3
  84.  
  85. id -a
  86.  
  87. ERROR=false
  88.  
  89. ps axo "user,pid,comm" | 
  90.     awk '$1 != "root" && /loginwindow/ {printf "user=%s pid=%s\n", $1, $2}' | 
  91.         while read e ; do 
  92.             eval $e
  93.             errors=`launchctl bsexec $pid su -l $user -c "launchctl unload -S Aqua /Library/LaunchAgents/com.f-secure.gui.plist" 2>&1`
  94.             if [ -n "$errors" ]; then
  95.                 echo "$errors"
  96.                 echo "Unloading launch agents is not fatal, continuing..."
  97.             fi
  98.             errors=`launchctl bsexec $pid su -l $user -c "launchctl unload /Library/LaunchAgents/com.f-secure.trasher.plist" 2>&1`
  99.             if [ -n "$errors" ]; then
  100.                 echo "$errors"
  101.                 echo "Unloading launch agents is not fatal, continuing..."
  102.             fi
  103.                         errors=`launchctl bsexec $pid su -l $user -c "launchctl remove com.f-secure.fsmac.subsvars" 2>&1`
  104.                         if [ -n "$errors" ]; then
  105.                             echo "$errors"
  106.                             echo "Unloading old launch agent (subsvars) is not fatal, continuing..."
  107.                         fi
  108.         done
  109. check_error "Failed to unload GUI" 
  110. date "+%Y-%m-%d %H:%M:%S checkpoint 2"
  111. echo "LaunchAgents unloaded" >&3
  112.  
  113. if killall fscuif; then
  114.     sleep 2
  115.     if killall -0 fscuif ; then
  116.     killall -9 fscuif
  117.     fi
  118. fi
  119. date "+%Y-%m-%d %H:%M:%S checkpoint 3"
  120. echo "GUI killed" >&3
  121.  
  122. /usr/local/f-secure/bin/loginitem - "`find /Applications -maxdepth 2 -name 'F-Secure Mac Protection.app'|head -1`"
  123.  
  124. /bin/rm -f "/Library/LaunchAgents/com.f-secure.gui.plist"
  125. rm -f /Library/LaunchAgents/com.f-secure.fsmac.subsvars.plist
  126. /bin/rm -f "/Library/LaunchAgents/com.f-secure.trasher.plist"
  127.  
  128. # NOTE: uninstall is not listed in labels because if we unloaded it
  129. # launchd would kill this script
  130. daemon_labels="com.f-secure.fsavd.dbver_update com.f-secure.clstate-dbupdate com.f-secure.clstate-periodic com.f-secure.fsmac.fsupdated com.f-secure.fsmac.firewall com.f-secure.fsavd.dbhelper com.f-secure.fsavd com.f-secure.aua"
  131. daemon_plists="com.f-secure.fsavd.dbver_update.plist com.f-secure.clstate-dbupdate.plist com.f-secure.clstate-periodic.plist com.f-secure.fsmac.fsupdated.plist com.f-secure.fsmac.firewall.plist com.f-secure.fsavd.dbhelper.plist com.f-secure.fsavd.plist com.f-secure.aua.plist com.f-secure.fsmacuninstall.plist"
  132.  
  133. for daemon in $daemon_labels; do
  134.     echo "Stopping $daemon"
  135.     if [ "$daemon" = "com.f-secure.aua" ]; then
  136.         # Wait for dbupdate to finish before shutting down AUA.
  137.         # Otherwise dbupdate will run fsav --copyright --print-license that
  138.         # will delay for a half a minute or so before giving up trying to
  139.         # connect to AUA that is no longer running.
  140.         waiting=30
  141.         while killall -0 dbupdate && [ $waiting -gt 0 ]; do
  142.             echo "dbupdate still running, waiting for it to exit"
  143.             sleep 1
  144.             waiting=$(($waiting - 1))
  145.         done
  146.         if killall -0 dbupdate; then
  147.             echo "dbupdate is still running, falling back to kill -9"
  148.             killall -9 dbupdate
  149.             sleep 1
  150.         fi
  151.     fi
  152.     launchctl remove $daemon
  153. done
  154.  
  155. for plist in $daemon_plists; do
  156.     rm -f /Library/LaunchDaemons/$plist
  157. done
  158.  
  159. date "+%Y-%m-%d %H:%M:%S checkpoint 4"
  160. echo "LaunchDaemons unloaded" >&3
  161.  
  162. # Remove infections.db for all users
  163. /bin/rm -f /Users/*/Library/Application\ Support/F-Secure/Mac\ Protection/infections.db
  164. # Remove F-Secure directories, only if they're empty
  165. /bin/rmdir /Users/*/Library/Application\ Support/F-Secure/Mac\ Protection
  166. /bin/rmdir /Users/*/Library/Application\ Support/F-Secure
  167.  
  168. if ! ${PARTIAL} ; then
  169.     /bin/rm -f /Users/*/Library/Preferences/com.f-secure.F-Secure\ ControlLayer-*.plist
  170. fi
  171. date "+%Y-%m-%d %H:%M:%S checkpoint 5"
  172. echo "Removing in /Applications" >&3
  173.  
  174. remove_app() {
  175.     app="$1"
  176.     bundleid="$2"
  177.     find /Applications -maxdepth 2 -type d -name "$app" | while read app_path; do
  178.     if [ -z "$app_path" ]; then
  179.         echo "$app was not found. Maybe someone (re)moved it?" >&3
  180.         continue
  181.     fi
  182.     if grep "<string>${bundleid}</string>" "${app_path}/Contents/Info.plist"; then
  183.         :
  184.     else
  185.         echo "$app_path found, but bundle id does not match $bundleid" >&3
  186.         continue
  187.     fi
  188.     if [ "$app_path" = "/Applications" -o "$app_path" = "/" ]; then
  189.         echo "Something is wrong! Installation folder was detected as $app_path" >&3
  190.     else
  191.         safer_rmrf "$app_path"
  192.     fi
  193.     app_parent=`dirname "$app_path"`
  194.     if [ "$app_parent" = "/Applications" -o "$app_parent" = "/" ]; then
  195.         echo "app parent dir $app_parent, not removing" >&3
  196.     else
  197.         rmdir "$app_parent"
  198.     fi
  199.     done
  200. }
  201.  
  202. remove_app 'F-Secure Mac Protection.app' 'com.f-secure.fsmac.gui'
  203. remove_app 'F-Secure Support Tool.app' 'com.f-secure.fsmac.gui.fsdiag'
  204. remove_app 'uninstall.app' 'com.f-secure.fsmac.gui.uninstall'
  205.  
  206. date "+%Y-%m-%d %H:%M:%S checkpoint 6"
  207. echo "Removing daemons and command line tools" >&3
  208.  
  209. if ${PARTIAL} ; then
  210.     /bin/sh -c '/usr/bin/find -d /usr/local/f-secure/ -type f -or -type l |  /usr/bin/grep -v fsaua/var | while read file ; do /bin/rm -v "$file"; done'
  211.     /bin/sh -c '/usr/bin/find -d /usr/local/f-secure/ -type d |  /usr/bin/grep -v fsaua/var | while read dir ; do /bin/rmdir "$dir"; done'
  212. else
  213.     safer_rmrf "/usr/local/f-secure/"
  214.     dscl . -delete /Groups/fsc
  215.     dscl . -delete /Users/fsaua
  216. fi
  217.  
  218. safer_rmrf /usr/local/f-secure/fsaua/var/handlers
  219.  
  220. /bin/rm -f /usr/local/bin/dbupdate /usr/local/bin/fsav
  221.  
  222.  
  223. date "+%Y-%m-%d %H:%M:%S checkpoint 7"
  224. echo "Removing driver" >&3
  225.  
  226. waiting=10
  227. while killall -0 fsavd && [ $waiting -gt 0 ]; do
  228.     echo "fsavd still running, waiting for it to exit"
  229.     sleep 1
  230.     waiting=`expr $waiting - 1`
  231. done
  232. if killall -0 fsavd; then
  233.     echo "fsavd is still running, falling back to kill -9"
  234.     killall -9 fsavd
  235.     sleep 1
  236. fi
  237.  
  238. if kextstat -b com.f-secure.kext.fsauth | grep -q com.f-secure.kext.fsauth; then
  239.     kextunload -b com.f-secure.kext.fsauth
  240.     check_error "Failed to remove kernel extension fsauth"
  241. fi
  242. safer_rmrf "/System/Library/Extensions/fsauth.kext"
  243.  
  244. if $NUKE_CUSTOMIZATIONS ; then
  245.     echo "Removing customizations" >&3
  246.  
  247.     safer_rmrf "/Library/F-Secure/fsmac"
  248.  
  249.     pkgutil --pkgs | grep ^com.f-secure.fsmac | grep customiz | xargs -n 1 pkgutil --forget
  250.     ls -d /Library/Receipts/com.f-secure.fsmac* | grep customiz | xargs rm -rf
  251. fi
  252.  
  253. date "+%Y-%m-%d %H:%M:%S checkpoint 8"
  254. echo "Removing receipts" >&3
  255. echo `pkgutil --pkgs | grep ^com.f-secure.fsmac | grep -v customiz` com.f-secure.fssp.pkg com.f-secure.agents-and-daemons.pkg com.f-secure.aua.pkg | xargs -n 1 pkgutil --forget
  256.  
  257. ls -d /Library/Receipts/com.f-secure.fsmac* | grep -v customiz | xargs rm -rf
  258. rm -rf /Library/Receipts/com.f-secure.fssp.*
  259. rm -rf /Library/Receipts/com.f-secure.aua.*
  260. rm -rf /Library/Receipts/com.f-secure.fsauth.*
  261.  
  262. rm -rf /tmp/.com.f-secure.fsav
  263. rm -f /tmp/ods-*.db
  264. rm -f /tmp/ods-*.db.real
  265. rm -f /Users/*/Library/Application\ Support/F-Secure/Mac\ Protection/infections.db
  266. rm -f /var/log/fsavd.log
  267. rm -rf /Library/Caches/com.f-secure.MacProtection.*
  268.  
  269. echo >&3
  270.  
  271. if ! ${PARTIAL} ; then
  272.     safer_rmrf /Library/F-Secure/fsmac
  273. fi
  274.  
  275. # Empty the contents of the magic file to prevent further accidental uninstalls.
  276. echo >$MAGIC
  277.  
  278. date "+%Y-%m-%d %H:%M:%S checkpoint 9"
  279.  
  280. if $ERROR ; then
  281.     echo "Some errors were encountered during uninstallation." >&3
  282.     echo "Please email uninstall log file ($LOG) " >&3
  283.     echo "to address <mac-tp@f-secure.com>" >&3
  284.     echo "Please reboot before installing F-Secure Mac Protection again" >&3
  285.     rc=1
  286. else
  287.     echo "Uninstallation complete." >&3
  288.     syslog -s -l Critical "Uninstallation complete."
  289.     rc=0
  290. fi
  291. echo $rc > /tmp/.com.f-secure.fsmac.uninstall-rc
  292. date "+%Y-%m-%d %H:%M:%S checkpoint 10"
  293. exit $rc
  294.