5 # Purpose : execute all tasks necessary following installation of Privoxy's files
7 # Copyright : Written by and Copyright (C) 2001-2012 the
8 # Privoxy team. http://www.privoxy.org/
10 # This program is free software; you can redistribute it
11 # and/or modify it under the terms of the GNU General
12 # Public License as published by the Free Software
13 # Foundation; either version 2 of the License, or (at
14 # your option) any later version.
16 # This program is distributed in the hope that it will
17 # be useful, but WITHOUT ANY WARRANTY; without even the
18 # implied warranty of MERCHANTABILITY or FITNESS FOR A
19 # PARTICULAR PURPOSE. See the GNU General Public
20 # License for more details.
22 # The GNU General Public License should be included with
23 # this file. If not, you can view it at
24 # http://www.gnu.org/copyleft/gpl.html
25 # or write to the Free Software Foundation, Inc.,
26 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
29 # Modification : If you modify this file please consider whether your
30 # changes ought to be passed back to the OSXPackageBuilder
34 # This postinstall script:
35 # 1. Moves config files into place, respecting any existing user config
36 # 2. Creates links to documentation in the app folder
37 # 3. Detects the version of OS X on which we're installing
38 # 4. Creates the logfile if not found and sets its ownership and persmissions
39 # 5. Disables the startup method not necessary for the host's OS X version and start Privoxy
40 # 6. Writes the package name into the uninstall script
41 # 7. Opens the readme.rtf file for the user to read
43 # preinstall created this file; continue to append to it in this script
44 logfile='/var/privoxy_installation.log'
46 # 1. Move config files into place, setting ownership and permissions, respecting any existing user config
48 for i in default.action default.filter match-all.action config trust user.action user.filter templates; do
49 if [ "$i" = "default.action" ] || [ "$i" = "default.filter" ] || [ "$i" = "match-all.action" ] ; then
50 # for the files a Mac user is very unlikely to have changed, overwrite existing, older versions
51 echo 'Installing config file (overwriting existing file if present):' $i >> ${logfile}
52 /bin/rm -f /usr/local/etc/privoxy/$i
53 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy || exit 1;
54 elif [ "$i" = "templates" ]; then
55 # for the templates subfolder copy across all the templates as .new if they already exist
56 for j in `ls -A /usr/local/etc/privoxy/vanilla/templates`; do
57 if [ -s "/usr/local/etc/privoxy/templates/"$j ]; then
58 # if the template exists in the destination then copy it in as <filename>.new
59 echo 'Installing template file with .new extension:' $j >> ${logfile}
60 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/templates/$j /usr/local/etc/privoxy/templates/$j.new || exit 1
62 # if the template doesn't exist in the destination then just copy it across
63 echo 'Installing template file:' $j >> ${logfile}
64 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/templates/$j /usr/local/etc/privoxy/templates/$j || exit 1
67 elif [ -s "/usr/local/etc/privoxy/"$i ]; then
68 # for all other files, if they already exist in the destination then copy them in as <filename>.new
69 echo 'Installing config file with .new extension:' $i >> ${logfile}
70 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy/$i.new || exit 1
72 # for all files that don't already exist just copy them across
73 echo 'Installing config file:' $i >> ${logfile}
74 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy || exit 1
77 # delete the vanilla config files
78 /bin/rm -rf /usr/local/etc/privoxy/vanilla >> ${logfile} 2>&1
80 # 2. Create links to documentation and log file in the app folder
82 ln /usr/local/share/doc/privoxy/AUTHORS /Applications/Privoxy/
83 ln /usr/local/share/doc/privoxy/ChangeLog /Applications/Privoxy/
84 ln -s /usr/local/share/doc/privoxy/index.html /Applications/Privoxy/Privoxy\ Documentation.html
85 ln /usr/local/share/doc/privoxy/LICENSE /Applications/Privoxy/
86 ln -s /var/log/privoxy/logfile.log /Applications/Privoxy/logfile.log
88 # 3. Detect the version of OS X on which we're installing
90 darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
92 # 4. Create logfile if not found and set its ownership and persmissions
94 if [ ! -d /var/log/privoxy ]; then
95 echo 'Creating Privoxy logfile directory' >> ${logfile}
96 /bin/mkdir -m 0755 /var/log/privoxy >> ${logfile} 2>&1
98 echo 'Creating Privoxy logfile and setting owner and permissions' >> ${logfile}
99 /usr/bin/touch /var/log/privoxy/logfile.log >> ${logfile} 2>&1
100 /usr/sbin/chown privoxy:privoxy /var/log/privoxy/logfile.log >> ${logfile} 2>&1
101 /bin/chmod 0644 /var/log/privoxy/logfile.log >> ${logfile} 2>&1
103 # 5. Disable the startup method not necessary for the host's OS X version and start Privoxy
105 case "${darwin_major_rel_num}" in
106 # Mac OS X 10.7, 10.6, 10.5
108 # disable Privoxy StartupItem
109 if [ ! -d /Library/StartupItems/Disabled ]; then
110 echo 'Delete the Privoxy StartupItem since it is not required for this OS X version' >> ${logfile}
111 /bin/mkdir -m 0755 /Library/StartupItems/Disabled
113 /bin/mv -f /Library/StartupItems/Privoxy /Library/StartupItems/Disabled
114 # start Privoxy using launchd (must be run as a logged-in user, not root)
115 echo 'Start Privoxy via the LaunchDaemon' >> ${logfile}
116 /bin/launchctl load /Library/LaunchDaemons/org.ijbswa.privoxy.plist >> ${logfile} 2>&1
118 # Mac OS X 10.4, 10.3
120 # can safely delete this since these older OS X releases do not support launchd anyway
121 echo 'Delete the Privoxy LaunchDaemon since it is not required for this OS X version' >> ${logfile}
122 /bin/rm -f /Library/LaunchDaemons/org.ijbswa.privoxy.plist
123 # start Privoxy using StartupItem
124 echo 'Start Privoxy via the StartupItem' >> ${logfile}
125 /Library/StartupItems/Privoxy/Privoxy start >> ${logfile} 2>&1
132 # 6. Write the package name into the uninstall script
134 # strip substrings from the front and back of the script path to obtain the package identifier
135 package_identifier=${0#/*p}
136 package_identifier=${package_identifier#/*/}
137 package_identifier=${package_identifier#S*/}
138 package_identifier=${package_identifier%.*l}
139 # search and replace in the uninstall script
140 sed -i 's/PKGNAME/$package_identifier/g' /Applications/Privoxy/uninstall.command >> ${logfile} 2>&1
142 # 7. Open the readme.rtf file for the user to read
143 /usr/bin/su $USER -c "/usr/bin/open /Applications/Privoxy/readme.rtfd"
145 /bin/mv ${logfile} /Applications/Privoxy/install.log