Actually get torbutton to install into Firefox
[tor.git] / contrib / osx / TorPostflight
blob00a91b9c99b727d44a084b16b128e4056d630010
1 #!/bin/sh
2 # ====================================================================
3 # TorPostFlight is distributed under this license
5 # Copyright (c) 2006 Andrew Lewman
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are
9 # met:
11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following disclaimer
16 # in the documentation and/or other materials provided with the
17 # distribution.
19 # * Neither the names of the copyright owners nor the names of its
20 # contributors may be used to endorse or promote products derived from
21 # this software without specific prior written permission.
23 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 # ======================================================================
36 # TorPostflight gets invoked after any install or upgrade.
38 ADDSYSUSER=$RECEIPT_PATH/addsysuser
39 if [ ! -x "$ADDSYSUSER" ]; then
40 echo "Could not find addsysuser script."
41 exit 1
44 TORUSER=_tor
45 TORGROUP=daemon
46 TARGET=$2/Library/Tor
47 TORDIR=$TARGET/var/lib/tor
48 LOGFILE=/var/log/tor.log
49 TORBUTTON_VERSION="1.1.17-alpha"
51 # Check defaults for TARGET
52 if [ "$TARGET" == "//Library/Tor" ]; then
53 TARGET=/Library/Tor
56 # Create user $TORUSER in group daemon. If it's already there, great.
57 $ADDSYSUSER $TORUSER "Tor System user" $TORDIR
59 # Create the tor directory, if it doesn't exist.
60 if [ ! -d $TORDIR ]; then
61 mkdir -p $TORDIR
63 # Check its permissions.
64 chown $TORUSER $TORDIR
65 chgrp daemon $TORDIR
66 chmod 700 $TORDIR
68 if [ ! -f $LOGFILE ]; then
69 touch $LOGFILE
70 chown $TORUSER $LOGFILE
71 chgrp daemon $LOGFILE
72 chmod 660 $LOGFILE
75 # Create the configuration file only if there wasn't one already.
76 if [ ! -f $TARGET/torrc ]; then
77 cp $TARGET/torrc.sample $TARGET/torrc
80 # Ensure symbolic links
81 cd /usr/bin
82 if [ -e /usr/bin/tor -a ! -L /usr/bin/tor ]; then
83 mv tor tor_old
85 if [ -e /usr/bin/tor-resolve -a ! -L /usr/bin/tor-resolve ]; then
86 mv tor-resolve tor-resolve_old
88 ln -sf $TARGET/tor .
89 ln -sf $TARGET/tor-resolve .
91 cd /usr/share/man/man1
92 MAN1=$TARGET/share/man/man1
93 #ln -sf $MAN1/*.1 .
95 if [ -d /Library/StartupItems/Privoxy ]; then
96 find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheel
99 # Copy Documentation
100 if [ -d $PACKAGE_PATH/Contents/Resources/documents ];then
101 cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documents
104 # Copy Uninstaller
105 if [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then
106 cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript
107 chmod 550 $TARGET/Tor_Uninstaller.applescript
110 if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
111 cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
112 chmod 550 $TARGET/uninstall_tor_bundle.sh
115 if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
116 cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
119 if [ -d /Library/StartupItems/Tor ]; then
120 rm -f /Library/StartupItems/Tor/Tor.loc
121 echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
124 if [ -f /Applications/Firefox.app/Contents/MacOS/firefox ]; then
125 if [ -f $TARGET/torbutton-$TORBUTTON_VERSION.xpi ]; then
126 # Open firefox with a prompt to install the torbutton xpi
127 su $USER /Applications/Firefox.app/Contents/MacOS/firefox $TARGET/torbutton-$TORBUTTON_VERSION.xpi