TorPostflight 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. LOGFILE=/var/log/tor.log
  13. # Check defaults for TARGET
  14. if [ "$TARGET" == "//Library/Tor" ]; then
  15. TARGET=/Library/Tor
  16. fi
  17. # Create user $TORUSER in group daemon. If it's already there, great.
  18. $ADDSYSUSER $TORUSER "Tor System user" $TORDIR
  19. # Create the tor directory, if it doesn't exist.
  20. if [ ! -d $TORDIR ]; then
  21. mkdir -p $TORDIR
  22. fi
  23. # Check its permissions.
  24. chown $TORUSER $TORDIR
  25. chgrp daemon $TORDIR
  26. chmod 700 $TORDIR
  27. if [ ! -f $LOGFILE ]; then
  28. touch $LOGFILE
  29. chown $TORUSER $LOGFILE
  30. chgrp daemon $LOGFILE
  31. chmod 660 $LOGFILE
  32. fi
  33. # Create the configuration file only if there wasn't one already.
  34. if [ ! -f $TARGET/torrc ]; then
  35. cp $TARGET/torrc.sample $TARGET/torrc
  36. fi
  37. # Ensure symbolic links
  38. cd /usr/bin
  39. if [ -e /usr/bin/tor -a ! -L /usr/bin/tor ]; then
  40. mv tor tor_old
  41. fi
  42. if [ -e /usr/bin/tor-resolve -a ! -L /usr/bin/tor-resolve ]; then
  43. mv tor-resolve tor-resolve_old
  44. fi
  45. ln -sf $TARGET/tor .
  46. ln -sf $TARGET/tor-resolve .
  47. cd /usr/share/man/man1
  48. MAN1=$TARGET/man/man1
  49. ln -sf $MAN1/*.1 .
  50. if [ -d /Library/StartupItems/Privoxy ]; then
  51. find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheel
  52. fi
  53. # Copy Documentation
  54. if [ -d $PACKAGE_PATH/Contents/Resources/documents ];then
  55. cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documents
  56. fi
  57. # Copy Uninstaller
  58. if [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then
  59. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript
  60. chmod 555 $TARGET/Tor_Uninstaller.applescript
  61. fi
  62. if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
  63. cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
  64. chmod 555 $TARGET/uninstall_tor_bundle.sh
  65. fi
  66. if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
  67. cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
  68. fi
  69. # If the pre-install script did it's thing, it should have saved the
  70. # config and server keys; put these back and clean up
  71. if [ -f /tmp/TorSavedMe.tar.gz ]; then
  72. tar zxf /tmp/TorSavedMe.tar.gz -C /
  73. rm /tmp/TorSavedMe.tar.gz
  74. fi
  75. if [ -d /Library/StartupItems/Tor ]; then
  76. rm -f /Library/StartupItems/Tor/Tor.loc
  77. echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
  78. fi