Fix a couple of non-cleared key issues in hidden services
[tor/rransom.git] / contrib / osx / uninstall_tor_bundle.sh
blobb7c439429e6e332dcc0619084a0db8f2dc32def8
1 #!/bin/sh
3 # not a psueber-pretty uninstall script for the Tor bundle package
4 # . this currently leaves ~/.tor, /var/log/tor and empty
5 # directories /Library/Tor, /Library/Privoxy (see comment below)
6 # . this relies on the fact that the startup items directories (if any)
7 # will be named the same as the package name (ie. Tor)
10 # version history
11 # initial version - 21 may, 2005 - loki der quaeler
14 # comments
15 # loki: because of the way the Tor package installs itself (the root directory
16 # is the filesystem root, as opposed to the much nicer way that privoxy
17 # installs itself with the privoxy home (/Library/Privoxy) as its
18 # install root directory), i thought it more prudent to leave empty
19 # directories laying around rather than try to incorrectly intuit from
20 # the bom contents what directories should exist and which ones could be
21 # deleted (ie, the Tor package has /Library listed in its bom --
22 # obviously this is a Bad Thing(tm) to delete).
23 # + when the Tor installer is changed, this uninstaller could be modified.
24 # loki: /bin/ps, when run from a terminal window in osX, restricts information
25 # based on the width of the window. an 80 col window will stupidly cause
26 # the grep search for the privoxy pid to not find the pid, whereas the grep
27 # in a wider window succeeds. consider using killall. in the meantime,
28 # advise uninstall runners to drag wide their terminal window.. ugh
32 ### this is the location of a file which contains all the actual package names
33 ## (ie "Tor", "torstartup", ...) the list should be new-line-delimited.
34 PACKAGE_LIST_SRC=/Library/Tor/package_list.txt
36 ### this is the name of the user created in the install process of Tor
37 TOR_USER=_tor
39 ### these should be constant across all osX installs (so leave them be)
40 STARTUP_ITEMS_DIR=/Library/StartupItems
41 PKG_RCPT_BASE_DIR=/Library/Receipts
42 BOM_INTERMEDIATE_DIR=Contents/Resources
43 INFO_INTERMEDIATE_DIR=$BOM_INTERMEDIATE_DIR/English.lproj
44 TEMP_BOM_CONTENTS=/tmp/tor_uninst_scratch
46 ### make sure the script is being run as root, barf if not
47 if [ "`whoami`" != "root" ]; then
48 echo "Must be root to run the uninstall script."
49 exit -1
53 ### check to see if tor is currently running, kill it if it is
54 ## we grep on 'Tor/tor ' because 'tor' is too common (like in 'directory')
55 ## -- this relies on the fact that tor has been started with command
56 ## line arguments.. :-/
57 TOR_PID=`ps -uax | grep 'Tor/tor ' | grep -v grep | awk '{print $2;}'`
58 if [ ${#TOR_PID} -gt 0 ]; then
59 echo ". Killing currently running tor process, pid is $TOR_PID"
60 kill -9 $TOR_PID
61 else
62 echo ". tor process appears to already be stopped"
66 ### check to see if privoxy is currently running, kill it if it is
67 PRIVOXY_PID=`ps -uax | grep privoxy | grep -v grep | awk '{print $2;}'`
68 if [ ${#PRIVOXY_PID} -gt 0 ]; then
69 echo ". Killing currently running privoxy process, pid is $PRIVOXY_PID"
70 kill -9 $PRIVOXY_PID
71 else
72 echo ". privoxy process appears to already be stopped"
76 ## grab each package name from the package list file
77 while read LINE; do
78 if [ ${#LINE} -gt 0 ]; then
79 PACKAGE_NAME=$LINE.pkg
80 PACKAGE_PATH=$PKG_RCPT_BASE_DIR/$PACKAGE_NAME
81 echo ". Uninstalling $PACKAGE_NAME"
82 if [ ! -d $PACKAGE_PATH ]; then
83 echo " . No receipt exists for this package -- skipping."
85 continue
89 ## get rid of the startup item if it exists
90 STARTUP_DIR=$STARTUP_ITEMS_DIR/$LINE
91 if [ -d $STARTUP_DIR ]; then
92 echo " . Deleting startup item $STARTUP_DIR"
93 rm -rf $STARTUP_DIR
97 ## determine the root directory of the the relative paths specified in the bom
98 DEFAULT_LOC=`grep DefaultLocation $PACKAGE_PATH/$INFO_INTERMEDIATE_DIR/$LINE.info | awk '{print $2;}'`
99 if [ ${#DEFAULT_LOC} -eq 0 ]; then
100 echo "!! Could not find default location for $LINE package -- skipping package."
102 continue
105 ## examine the list of installed items desribed in the bom
106 BOM_FILE=$PACKAGE_PATH/$BOM_INTERMEDIATE_DIR/$LINE.bom
107 lsbom $BOM_FILE > $TEMP_BOM_CONTENTS
108 while read BOM_ITEM; do
109 ## 3 column items describe just directories, 5 column items describe actual files
110 COL_COUNT=$(echo $BOM_ITEM | awk '{print NF;}')
111 if [ "$COL_COUNT" -eq 5 ]; then
112 FILE_NAME=$DEFAULT_LOC/$(echo $BOM_ITEM | awk '{print $1;}')
114 echo " . Removing $FILE_NAME"
115 rm -rf $FILE_NAME
117 done < $TEMP_BOM_CONTENTS
119 ## remove package receipt
120 echo " . Removing package receipt $PACKAGE_PATH"
121 rm -rf $PACKAGE_PATH
123 done < $PACKAGE_LIST_SRC
126 ## nuke the user created by the install process.
127 echo ". Removing created user $TOR_USER"
128 if [ -x /usr/bin/dscl ]; then
129 dscl . -delete /users/$TOR_USER
130 else
131 niutil -destroy . /users/$TOR_USER
134 ## clean up
135 echo ". Cleaning up"
136 rm -rf $TEMP_BOM_CONTENTS
137 rm -rf /Library/Privoxy/ /Library/StartupItems/Privoxy/ /Library/Tor/ /Library/StartupItems/Tor/ /Library/Torbutton/ /Library/Receipts/Privoxy.pkg /Library/Receipts/torbutton.pkg /Library/Receipts/Tor.pkg /Library/Receipts/Vidalia.pkg /Library/Receipts/TorStartup.pkg
139 echo ". Finished"