fix compile complaints (and a bug)
[tor.git] / contrib / osx / TorPostflight
blob0dd905110ae09bbe9f713d83126d357ee6652753
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 rm -f /Library/StartupItems/Tor/Tor.loc
63 echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
66 if [ -d /Library/StartupItems/Privoxy ]; then
67 find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheel