Removed version numbering from installer package internal identifier
[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 OSXPackageBuilder
32 #                module.
33 #
34
35 root_UID=0   # Root has $UID 0.
36
37 if [ "$UID" -eq "$root_UID" ]; then
38         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
39         echo 'About to remove the Privoxy application.  Are you sure? (Y/N)'
40         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
41         read ANSWER
42         if (test z$ANSWER = zY) || (test z$ANSWER = zy) then
43                 echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
44                 echo 'Last chance.  Removing Privoxy...  Are you sure? (Y/N)'
45                 echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
46                 read ANSWER
47                 if (test z$ANSWER = zY) || (test z$ANSWER = zy) then
48                         echo Stopping Privoxy.
49                         kill `ps -ax | grep /privoxy | grep -v grep | awk '{ print $1 }'` 2> /dev/null
50                         # Remove items common to all OS X versions
51                         echo Deleting Privoxy and its documentation
52                         # Delete binary
53                         rm -f /usr/local/sbin/privoxy
54                         # Delete documention
55                         rm -rf /usr/local/share/doc/privoxy
56                         # Delete manpage
57                         rm -f /usr/local/share/man/man1/privoxy.1
58                         # Optionally delete config files
59                         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
60                         echo 'Delete configuration files? (Y/N)'
61                         echo  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
62                         read ANSWER
63                         if (test z$ANSWER = zY) || (test z$ANSWER = zy) then
64                                 rm -rf /usr/local/etc/privoxy
65                         fi
66                         # Delete log files
67                         rm -rf /var/log/privoxy
68                         # Delete folder from /Applications
69                         rm -rf /Applications/Privoxy
70                         
71                         # Delete all items referenced by the installation package
72                         echo 'Delete package installation receipt (ignore errors relating to other bundle identifiers).'
73                         # On OS X 10.5 or newer we can use the new pkgutil command else simply delete the receipt file
74                         if [ -x /usr/sbin/pkgutil ]; then
75                                 pkgutil --forget org.ijbswa.privoxy.pkg
76                         else
77                                 rm -rf /Library/Receipts/Privoxy\ OS\ X\ 10.4.pkg
78                         fi
79
80                         # Check the Trash, just in case the user manually removed the only obvious item from /Applications
81                         if [ -d ~/.Trash/Privoxy ]; then
82                                 echo Removing Privoxy from the trash.
83                                 rm -rf ~/.Trash/Privoxy
84                         fi
85
86                         # Delete host-dependent items - first ascertain OS X version
87                         darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
88
89                         case "${darwin_major_rel_num}" in
90                                 # Mac OS X 10.5 or higher
91                                 9|1*)
92                                         # Delete Privoxy LaunchDaemon
93                                         echo 'Delete Privoxy LaunchDaemon (an error will be thrown regarding "no such process")'
94                                         /bin/launchctl unload /Library/LaunchDaemons/org.ijbswa.privoxy.plist
95                                         /bin/launchctl remove /Library/LaunchDaemons/org.ijbswa.privoxy.plist
96                                         rm -f /Library/LaunchDaemons/org.ijbswa.privoxy.plist
97                                         # The installer might have disabled a previous Privoxy LaunchDaemon
98                                         rm -rf /Library/LaunchDaemons/Disabled/org.ijbswa.privoxy.plist
99                                         # There might have previously been a StartupItem installed
100                                         rm -rf /Library/StartupItems/Privoxy
101                                         # There might have previously been a disabled Privoxy StartupItem
102                                         rm -rf /Library/StartupItems/Disabled/Privoxy
103                                         # Remove user and group
104                                         echo Removing privoxy user and group
105                                         dscl /Local/Default -delete /Users/_privoxy
106                                         dscl /Local/Default -delete /Groups/_privoxy
107                                 ;;
108                                 # Mac OS X 10.4, 10.3
109                                 8|7)
110                                         # Delete Privoxy StartupItem
111                                         echo Delete Privoxy StartupItem
112                                         rm -rf /Library/StartupItems/Privoxy
113                                         # The installer might have disabled a previous Privoxy StartupItem
114                                         rm -rf /Library/StartupItems/Disabled/Privoxy
115                                         # Remove user and group
116                                         echo Removing privoxy user and group
117                                         niutil -destroy / /groups/privoxy
118                                         niutil -destroy / /users/privoxy
119                                 ;;
120                                 # default
121                                 *)
122                                 ;;
123                         esac
124
125                         # Despite the various errors that may have been thrown, give the user a good feeling!
126                         echo
127                         echo Uninstallation complete.
128                 else 
129                         echo Uninstall aborted.
130                 fi
131         else
132                 echo Uninstall aborted.
133         fi
134 else
135         echo
136   echo This script requires administrator privileges.
137         echo "Please run it from Terminal, using an administrator account, as follows:"
138         echo
139         echo "sudo /Applications/Privoxy/uninstall.command"
140         echo
141 fi
142
143 exit 0