TorPostflight 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.sample
  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 [ -d /Library/StartupItems/Tor ]; then
  70. rm -f /Library/StartupItems/Tor/Tor.loc
  71. echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
  72. fi