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. 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
  58. # Copy Documentation
  59. if [ -d $PACKAGE_PATH/Contents/Resources/documents ];then
  60. cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documents
  61. fi
  62. # Copy Uninstaller
  63. if [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then
  64. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript
  65. chmod 755 $TARGET/Tor_Uninstaller.applescript
  66. fi
  67. if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
  68. cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
  69. chmod 755 $TARGET/uninstall_tor_bundle.sh
  70. fi
  71. if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
  72. cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
  73. fi