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 macsetup module.
33 # This postinstall script:
34 # 1. Moves config files into place, respecting any existing user config
35 # 2. Creates links to documentation in the app folder
36 # 3. Detects the version of OS X on which we're installing
37 # 4. Creates the logfile if not found and sets its ownership and persmissions
38 # 5. Disables the startup method not necessary for the host's OS X version and start Privoxy
39 # 6. Writes the package name into the uninstall script
40 # 7. Opens the readme.rtf file for the user to read
42 # preinstall created this file; continue to append to it in this script
43 logfile='/var/privoxy_installation.log'
45 # 1. Move config files into place, setting ownership and permissions, respecting any existing user config
47 for i in default.action default.filter match-all.action config trust user.action user.filter templates; do
48 if [ "$i" = "default.action" ] || [ "$i" = "default.filter" ] || [ "$i" = "match-all.action" ] ; then
49 # for the files a Mac user is very unlikely to have changed, overwrite existing, older versions
50 echo 'Installing config file (overwriting existing file if present):' $i >> ${logfile}
51 /bin/rm -f /usr/local/etc/privoxy/$i
52 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy || exit 1;
53 elif [ "$i" = "templates" ]; then
54 # for the templates subfolder copy across all the templates as .new if they already exist
55 for j in `ls -A /usr/local/etc/privoxy/vanilla/templates`; do
56 if [ -s "/usr/local/etc/privoxy/templates/"$j ]; then
57 # if the template exists in the destination then copy it in as <filename>.new
58 echo 'Installing template file with .new extension:' $j >> ${logfile}
59 /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
61 # if the template doesn't exist in the destination then just copy it across
62 echo 'Installing template file:' $j >> ${logfile}
63 /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
66 elif [ -s "/usr/local/etc/privoxy/"$i ]; then
67 # for all other files, if they already exist in the destination then copy them in as <filename>.new
68 echo 'Installing config file with .new extension:' $i >> ${logfile}
69 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy/$i.new || exit 1
71 # for all files that don't already exist just copy them across
72 echo 'Installing config file:' $i >> ${logfile}
73 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy || exit 1
76 # delete the vanilla config files
77 /bin/rm -rf /usr/local/etc/privoxy/vanilla >> ${logfile} 2>&1
79 # 2. Create links to documentation and log file in the app folder
81 ln /usr/local/share/doc/privoxy/AUTHORS /Applications/Privoxy/
82 ln /usr/local/share/doc/privoxy/ChangeLog /Applications/Privoxy/
83 ln -s /usr/local/share/doc/privoxy/index.html /Applications/Privoxy/Privoxy\ Documentation.html
84 ln /usr/local/share/doc/privoxy/LICENSE /Applications/Privoxy/
85 ln -s /var/log/privoxy/logfile.log /Applications/Privoxy/logfile.log
87 # 3. Detect the version of OS X on which we're installing
89 darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
91 # 4. Create logfile if not found and set its ownership and persmissions
93 if [ ! -d /var/log/privoxy ]; then
94 echo 'Creating Privoxy logfile directory' >> ${logfile}
95 /bin/mkdir -m 0755 /var/log/privoxy >> ${logfile} 2>&1
97 echo 'Creating Privoxy logfile and setting owner and permissions' >> ${logfile}
98 /usr/bin/touch /var/log/privoxy/logfile.log >> ${logfile} 2>&1
99 /usr/sbin/chown privoxy:privoxy /var/log/privoxy/logfile.log >> ${logfile} 2>&1
100 /bin/chmod 0644 /var/log/privoxy/logfile.log >> ${logfile} 2>&1
102 # 5. Disable the startup method not necessary for the host's OS X version and start Privoxy
104 case "${darwin_major_rel_num}" in
105 # Mac OS X 10.7, 10.6, 10.5
107 # disable Privoxy StartupItem
108 if [ ! -d /Library/StartupItems/Disabled ]; then
109 echo 'Delete the Privoxy StartupItem since it is not required for this OS X version' >> ${logfile}
110 /bin/mkdir -m 0755 /Library/StartupItems/Disabled
112 /bin/mv -f /Library/StartupItems/Privoxy /Library/StartupItems/Disabled
113 # start Privoxy using launchd (must be run as a logged-in user, not root)
114 echo 'Start Privoxy via the LaunchDaemon' >> ${logfile}
115 /bin/launchctl load /Library/LaunchDaemons/org.ijbswa.privoxy.plist >> ${logfile} 2>&1
117 # Mac OS X 10.4, 10.3
119 # can safely delete this since these older OS X releases do not support launchd anyway
120 echo 'Delete the Privoxy LaunchDaemon since it is not required for this OS X version' >> ${logfile}
121 /bin/rm -f /Library/LaunchDaemons/org.ijbswa.privoxy.plist
122 # start Privoxy using StartupItem
123 echo 'Start Privoxy via the StartupItem' >> ${logfile}
124 /Library/StartupItems/Privoxy/Privoxy start >> ${logfile} 2>&1
131 # 6. Write the package name into the uninstall script
133 # strip substrings from the front and back of the script path to obtain the package identifier
134 package_identifier=${0#/*p}
135 package_identifier=${package_identifier#/*/}
136 package_identifier=${package_identifier#S*/}
137 package_identifier=${package_identifier%.*l}
138 # search and replace in the uninstall script
139 sed -i 's/PKGNAME/$package_identifier/g' /Applications/Privoxy/uninstall.command >> ${logfile} 2>&1
141 # 7. Open the readme.rtf file for the user to read
142 /usr/bin/su $USER -c "/usr/bin/open /Applications/Privoxy/readme.rtfd"
144 /bin/mv ${logfile} /Applications/Privoxy/install.log