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. LOGDIR=$TARGET/var/log/tor
  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. if [ ! -d $LOGDIR ]; then
  24. mkdir -p $LOGDIR
  25. fi
  26. # Check its permissions.
  27. chown $TORUSER $TORDIR
  28. chgrp daemon $TORDIR
  29. chmod 700 $TORDIR
  30. chown $TORUSER $LOGDIR
  31. chgrp daemon $LOGDIR
  32. chmod 700 $LOGDIR
  33. # Create the configuration file only if there wan'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 [ ! -e /var/log/tor -o -L /var/log/tor ]; then
  51. cd /var/log
  52. rm -f tor
  53. ln -sf $LOGDIR tor
  54. fi
  55. if [ -d /Library/StartupItems/Tor ]; then
  56. rm -f /Library/StartupItems/Tor/Tor.loc
  57. echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
  58. fi
  59. if [ -d /Library/StartupItems/Privoxy ]; then
  60. find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheel
  61. fi
  62. # Copy Documentation
  63. if [ -d $PACKAGE_PATH/Contents/Resources/documents ];then
  64. cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documents
  65. fi
  66. # Copy Uninstaller
  67. if [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then
  68. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript
  69. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller_bin.app $TARGET/Tor_Uninstaller_bin.app
  70. chmod 755 $TARGET/Tor_Uninstaller.applescript
  71. chmod 755 $TARGET/Tor_Uninstaller_bin.app
  72. fi
  73. if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
  74. cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
  75. chmod 755 $TARGET/uninstall_tor_bundle.sh
  76. fi
  77. if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
  78. cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
  79. fi