match-all.action no longer overwritten during installation if already present
[OSXPackageBuilder.git] / pkg resources / single-binary scripts / postinstall
1 #!/bin/sh
2
3 # File        :  postinstall
4 #
5 # Purpose     :  execute all tasks necessary following installation of 
6 #                Privoxy's files
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 #  This postinstall script:
35 #
36 #  1. Moves config files into place, respecting any existing user config
37 #  2. Creates links to documentation in the app folder
38 #  3. Detects the version of OS X on which we're installing
39 #  4. Creates the logfile if not found and sets its ownership and persmissions
40 #  5. Disables the startup method not necessary for the host's OS X version and start Privoxy
41 #  6. Opens the readme.rtf file for the user to read
42
43 # preinstall created this file; continue to append to it in this script
44 logfile='/var/privoxy_installation.log'
45
46 #  1. Move config files into place, setting ownership and permissions, respecting any existing user config
47 #
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" ] ; then
50                 # for the files that the end user should not edit, 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
61                         else
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
65                         fi
66                 done
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
71         else
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
75         fi
76 done
77 # delete the vanilla config files
78 /bin/rm -rf /usr/local/etc/privoxy/vanilla >> ${logfile} 2>&1
79
80 # 2. Create links to documentation and log file in the app folder
81 #
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/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
87
88 # 3. Detect the version of OS X on which we're installing
89 #
90 darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
91
92 # 4. Create logfile if not found and set its ownership and persmissions
93 #
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
97 fi
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
102
103 # 5. Disable the startup method not necessary for the host's OS X version and start Privoxy
104 #
105 case "${darwin_major_rel_num}" in
106   # Mac OS X 10.5 or higher
107   9|1*)
108                 # delete Privoxy StartupItem
109                 echo 'Delete the Privoxy StartupItem since it is not required for this OS X version' >> ${logfile}
110                 if [ -d /Library/StartupItems/Disabled/Privoxy ]; then
111                         /bin/rm -rf /Library/StartupItems/Disabled/Privoxy >> ${logfile} 2>&1
112                 fi
113                 /bin/rm -rf /Library/StartupItems/Privoxy >> ${logfile} 2>&1
114                 # start Privoxy using launchd
115                 echo 'Start Privoxy via the LaunchDaemon' >> ${logfile}
116                 /bin/launchctl load /Library/LaunchDaemons/org.ijbswa.privoxy.plist >> ${logfile} 2>&1
117   ;;
118   # Mac OS X 10.4, 10.3
119   8|7)
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
126   ;;
127   # default
128   *)
129     ;;
130 esac
131
132 # 6. Open the readme.rtf file for the user to read
133 /usr/bin/su $USER -c "/usr/bin/open /Applications/Privoxy/readme.rtfd"
134
135 /bin/mv ${logfile} /Applications/Privoxy/install.log
136
137 exit 0