567f0a31c16ffff22abbe55715d974a807314c68
[OSXPackageBuilder.git] / pkg content skeleton / Applications / Privoxy / uninstall.command
1 #!/bin/sh
2
3 # File        :  uninstall.command
4 #
5 # Purpose     :  Remove the Privoxy application and (optionally) its  
6 #                configuration files from the target system
7 #
8 # Copyright   :  Written by and Copyright (C) 2001-2012 the
9 #                Privoxy team. http://www.privoxy.org/
10 #
11 #                This program is free software; you can redistribute it
12 #                and/or modify it under the terms of the GNU General
13 #                Public License as published by the Free Software
14 #                Foundation; either version 2 of the License, or (at
15 #                your option) any later version.
16 #
17 #                This program is distributed in the hope that it will
18 #                be useful, but WITHOUT ANY WARRANTY; without even the
19 #                implied warranty of MERCHANTABILITY or FITNESS FOR A
20 #                PARTICULAR PURPOSE.  See the GNU General Public
21 #                License for more details.
22 #
23 #                The GNU General Public License should be included with
24 #                this file.  If not, you can view it at
25 #                http://www.gnu.org/copyleft/gpl.html
26 #                or write to the Free Software Foundation, Inc.,
27 #                51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
28 #                USA
29 #
30 # Modification : If you modify this file please consider whether your 
31 #                changes ought to be passed back to the macsetup module.
32 #
33
34 root_UID=0   # Root has $UID 0.
35
36 if [ "$UID" -eq "$root_UID" ]; then
37         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38         echo 'About to remove the Privoxy application.  Are you sure? (Y/N)'
39         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
40         read ANSWER
41         if (test z$ANSWER = zY) || (test z$ANSWER = zy) then
42                 echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
43                 echo 'Last chance.  Removing Privoxy...  Are you sure? (Y/N)'
44                 echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
45                 read ANSWER
46                 if (test z$ANSWER = zY) || (test z$ANSWER = zy) then
47                         echo Stopping Privoxy.
48                         kill `ps -ax | grep /privoxy | grep -v grep | awk '{ print $1 }'` 2> /dev/null
49                         # Remove items common to all OS X versions
50                         echo Deleting Privoxy and its documentation
51                         # Delete binary
52                         rm -f /usr/local/sbin/privoxy
53                         # Delete documention
54                         rm -rf /usr/local/share/doc/privoxy
55                         # Delete manpage
56                         rm -f /usr/local/share/man/man1/privoxy.1
57                         # Optionally delete config files
58                         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
59                         echo 'Delete configuration files? (Y/N)'
60                         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
61                         read ANSWER
62                         if (test z$ANSWER = zY) || (test z$ANSWER = zy) then
63                                 rm -rf /usr/local/etc/privoxy
64                         fi
65                         # Delete log files
66                         rm -rf /var/log/privoxy
67                         # Delete folder from /Applications
68                         rm -rf /Applications/Privoxy
69                         
70                         # Delete all items referenced by the installation package
71                         echo 'Delete package installation receipt (ignore errors relating to other bundle identifiers).'
72                         # TODO overwrite PKGNAME during postinstall execution with the name of the package being installed.
73                         # In the meantime, the package name must be manually entered for each release.
74                         #pkgutil --forget PKGNAME
75                         # if OS X 10.5 or newer then use the new pkgutil command else simply delete the receipt file
76                         if [ -x /usr/sbin/pkgutil ]; then
77                                 pkgutil --forget org.ijbswa.privoxy3019.pkg
78                         else
79                                 rm -rf /Library/Receipts/Privoxy\ 3.0.19\ OS\ X\ 10.4.pkg
80                         fi
81
82                         # Check the Trash, just in case the user manually removed the only obvious item from /Applications
83                         if [ -d ~/.Trash/Privoxy ]; then
84                                 echo Removing Privoxy from the trash.
85                                 rm -rf ~/.Trash/Privoxy
86                         fi
87
88                         # Delete host-dependent items - first ascertain OS X version
89                         darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
90
91                         case "${darwin_major_rel_num}" in
92                                 # Mac OS X 10.5 or higher
93                                 9|1*)
94                                         # Delete Privoxy LaunchDaemon
95                                         echo 'Delete Privoxy LaunchDaemon (an error will be thrown regarding "no such process")'
96                                         /bin/launchctl unload /Library/LaunchDaemons/org.ijbswa.privoxy.plist
97                                         /bin/launchctl remove /Library/LaunchDaemons/org.ijbswa.privoxy.plist
98                                         rm -f /Library/LaunchDaemons/org.ijbswa.privoxy.plist
99                                         # The installer might have disabled a previous Privoxy LaunchDaemon
100                                         rm -rf /Library/LaunchDaemons/Disabled/org.ijbswa.privoxy.plist
101                                         # There might have previously been a StartupItem installed
102                                         rm -rf /Library/StartupItems/Privoxy
103                                         # There might have previously been a disabled Privoxy StartupItem
104                                         rm -rf /Library/StartupItems/Disabled/Privoxy
105                                         # Remove user and group
106                                         echo Removing privoxy user and group
107                                         dscl /Local/Default -delete /Users/_privoxy
108                                         dscl /Local/Default -delete /Groups/_privoxy
109                                 ;;
110                                 # Mac OS X 10.4, 10.3
111                                 8|7)
112                                         # Delete Privoxy StartupItem
113                                         echo Delete Privoxy StartupItem
114                                         rm -rf /Library/StartupItems/Privoxy
115                                         # The installer might have disabled a previous Privoxy StartupItem
116                                         rm -rf /Library/StartupItems/Disabled/Privoxy
117                                         # Remove user and group
118                                         echo Removing privoxy user and group
119                                         niutil -destroy / /groups/privoxy
120                                         niutil -destroy / /users/privoxy
121                                 ;;
122                                 # default
123                                 *)
124                                 ;;
125                         esac
126
127                         # Despite the various errors that may have been thrown, give the user a good feeling!
128                         echo
129                         echo Uninstallation complete.
130                 else 
131                         echo Uninstall aborted.
132                 fi
133         else
134                 echo Uninstall aborted.
135         fi
136 else
137         echo
138   echo This script requires administrator privileges.
139         echo "Please run it from Terminal, using an administrator account, as follows:"
140         echo
141         echo "sudo /Applications/Privoxy/uninstall.command"
142         echo
143 fi
144
145 exit 0