TorPostflight 1.5 KB

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