Modify postinstall to open readme.pdf instead of readme.rtfd
[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 OSXPackageBuilder
32 #                module.
33 #
34
35 #  This postinstall script:
36 #
37 #  1. Moves config files into place, respecting any existing user config
38 #  2. Creates links to documentation in the app folder
39 #  3. Detects the version of OS X on which we're installing
40 #  4. Creates the logfile if not found and sets its ownership and persmissions
41 #  5. Disables the startup method not necessary for the host's OS X version and start Privoxy
42 #  6. Opens the readme.rtf file for the user to read
43
44 # preinstall created this file; continue to append to it in this script
45 logfile='/var/privoxy_installation.log'
46
47 #  1. Move config files into place, setting ownership and permissions, respecting any existing user config
48 #
49 for i in default.action default.filter match-all.action config trust user.action user.filter templates; do
50         if [ "$i" = "default.action" ] || [ "$i" = "default.filter" ] ; then
51                 # for the files that the end user should not edit, overwrite existing, older versions
52                 echo 'Installing config file (overwriting existing file if present):' $i >> ${logfile}
53                 /bin/rm -f /usr/local/etc/privoxy/$i
54                 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy || exit 1;
55         elif [ "$i" = "templates" ]; then
56                 # for the templates subfolder copy across all the templates as .new if they already exist
57                 for j in `ls -A /usr/local/etc/privoxy/vanilla/templates`; do
58                         if [ -s "/usr/local/etc/privoxy/templates/"$j ]; then
59                                 # if the template exists in the destination then copy it in as <filename>.new
60                                 echo 'Installing template file with .new extension:' $j >> ${logfile}
61                                 /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                         else
63                                 # if the template doesn't exist in the destination then just copy it across
64                                 echo 'Installing template file:' $j >> ${logfile}
65                                 /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                         fi
67                 done
68         elif [ -s "/usr/local/etc/privoxy/"$i ]; then
69                 # for all other files, if they already exist in the destination then copy them in as <filename>.new
70                 echo 'Installing config file with .new extension:' $i >> ${logfile}
71                 /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         else
73                 # for all files that don't already exist just copy them across
74                 echo 'Installing config file:' $i >> ${logfile}
75                 /usr/bin/install -c -m 0664 -o privoxy -g privoxy /usr/local/etc/privoxy/vanilla/$i /usr/local/etc/privoxy || exit 1
76         fi
77 done
78 # delete the vanilla config files
79 /bin/rm -rf /usr/local/etc/privoxy/vanilla >> ${logfile} 2>&1
80
81 # 2. Create links to documentation and log file in the app folder
82 #
83 ln /usr/local/share/doc/privoxy/AUTHORS /Applications/Privoxy/
84 ln /usr/local/share/doc/privoxy/ChangeLog /Applications/Privoxy/
85 ln -s /usr/local/share/doc/privoxy/privoxy-index.html /Applications/Privoxy/Privoxy\ Documentation.html
86 ln /usr/local/share/doc/privoxy/LICENSE /Applications/Privoxy/
87 ln -s /var/log/privoxy/logfile.log /Applications/Privoxy/logfile.log
88
89 # 3. Detect the version of OS X on which we're installing
90 #
91 darwin_major_rel_num="`/usr/bin/uname -r | /usr/bin/sed 's/\..*//'`"
92
93 # 4. Create logfile if not found and set its ownership and persmissions
94 #
95 if [ ! -d /var/log/privoxy ]; then
96         echo 'Creating Privoxy logfile directory' >> ${logfile}
97         /bin/mkdir -m 0755 /var/log/privoxy >> ${logfile} 2>&1
98 fi
99 echo 'Creating Privoxy logfile and setting owner and permissions' >> ${logfile}
100 /usr/bin/touch /var/log/privoxy/logfile.log >> ${logfile} 2>&1
101 /usr/sbin/chown privoxy:privoxy /var/log/privoxy/logfile.log >> ${logfile} 2>&1
102 /bin/chmod 0644 /var/log/privoxy/logfile.log >> ${logfile} 2>&1
103
104 # 5. Disable the startup method not necessary for the host's OS X version and start Privoxy
105 #
106 case "${darwin_major_rel_num}" in
107   # Mac OS X 10.5 or higher
108   9|1*)
109                 # delete Privoxy StartupItem
110                 echo 'Delete the Privoxy StartupItem since it is not required for this OS X version' >> ${logfile}
111                 if [ -d /Library/StartupItems/Disabled/Privoxy ]; then
112                         /bin/rm -rf /Library/StartupItems/Disabled/Privoxy >> ${logfile} 2>&1
113                 fi
114                 /bin/rm -rf /Library/StartupItems/Privoxy >> ${logfile} 2>&1
115                 # start Privoxy using launchd
116                 echo 'Start Privoxy via the LaunchDaemon' >> ${logfile}
117                 /bin/launchctl load /Library/LaunchDaemons/org.ijbswa.privoxy.plist >> ${logfile} 2>&1
118   ;;
119   # Mac OS X 10.4, 10.3
120   8|7)
121                 # can safely delete this since these older OS X releases do not support launchd anyway
122                 echo 'Delete the Privoxy LaunchDaemon since it is not required for this OS X version' >> ${logfile}
123                 /bin/rm -f /Library/LaunchDaemons/org.ijbswa.privoxy.plist
124                 # start Privoxy using StartupItem
125                 echo 'Start Privoxy via the StartupItem' >> ${logfile}
126                 /Library/StartupItems/Privoxy/Privoxy start >> ${logfile} 2>&1
127   ;;
128   # default
129   *)
130     ;;
131 esac
132
133 # 6. Open the readme.pdf file for the user to read
134 /usr/bin/su $USER -c "/usr/bin/open /Applications/Privoxy/readme.pdf"
135
136 /bin/mv ${logfile} /Applications/Privoxy/install.log
137
138 exit 0