OSX 10.4.1 really really really wants startup items to be owned by wheel:root.
[tor.git] / contrib / osx / TorPostflight
blob36cc2a999f07a2a0feb34fd8cefff2d4badfb1c2
1 #!/bin/sh
3 # TorPostflight gets invoked after any install or upgrade.
5 ADDSYSUSER=$RECEIPT_PATH/addsysuser
6 if [ ! -x "$ADDSYSUSER" ]; then
7 echo "Could not find addsysuser script."
8 exit 1
9 fi
11 TORUSER=_tor
12 TORGROUP=daemon
13 TARGET=$2/Library/Tor
14 TORDIR=$TARGET/var/lib/tor
15 LOGDIR=$TARGET/var/log/tor
17 # Create user $TORUSER in group daemon. If it's already there, great.
18 $ADDSYSUSER $TORUSER "Tor System user" $TORDIR
20 # Create the tor directory, if it doesn't exist.
21 if [ ! -d $TORDIR ]; then
22 mkdir -p $TORDIR
24 if [ ! -d $LOGDIR ]; then
25 mkdir -p $LOGDIR
27 # Check its permissions.
28 chown $TORUSER $TORDIR
29 chgrp daemon $TORDIR
30 chmod 700 $TORDIR
31 chown $TORUSER $LOGDIR
32 chgrp daemon $LOGDIR
33 chmod 700 $LOGDIR
35 # Create the configuration file only if there wan't one already.
36 if [ ! -f $TARGET/torrc ]; then
37 cp $TARGET/torrc.sample $TARGET/torrc
40 # Ensure symbolic links
41 cd /usr/bin
42 if [ -e /usr/bin/tor -a ! -L /usr/bin/tor ]; then
43 mv tor tor_old
45 if [ -e /usr/bin/tor-resolve -a ! -L /usr/bin/tor-resolve ]; then
46 mv tor-resolve tor-resolve_old
48 ln -sf $TARGET/tor .
49 ln -sf $TARGET/tor_resolve .
51 cd /usr/share/man/man1
52 MAN1=$TARGET/man/man1
53 ln -sf $MAN1/*.1 .
55 if [ ! -e /var/log/tor -o -L /var/log/tor ]; then
56 cd /var/log
57 rm -f tor
58 ln -sf $LOGDIR tor
61 if [ ! -d /Library/StartupItems/Tor ]; then
62 mkdir -p /Library/StartupItems/Tor
64 rm -f /Library/StartupItems/Tor/Tor.loc
65 echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
67 if [ -d /Library/StartupItems/Privoxy ]; then
68 find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheel