TorPostflight 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 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 [ ! -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/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/Tor_Uninstaller.app.tar.gz ]; then
  68. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.app.tar.gz $TARGET/Tor_Uninstaller.app.tar.gz
  69. cd $TARGET && tar zxf Tor_Uninstaller.app.tar.gz
  70. chmod -R 755 $TARGET/Tor_Uninstaller.app
  71. chown -R _tor:_tor Tor_Uninstaller.app
  72. rm $TARGET/Tor_Uninstaller.app.tar.gz
  73. fi
  74. if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
  75. cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
  76. chmod 755 $TARGET/uninstall_tor_bundle.sh
  77. fi
  78. if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
  79. cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
  80. fi
  81. # If the pre-install script did it's thing, it should have saved the
  82. # config and server keys; put these back and clean up
  83. if [ -f /tmp/TorSavedMe.tar.gz ]; then
  84. tar zxf /tmp/TorSavedMe.tar.gz -C /
  85. rm /tmp/TorSavedMe.tar.gz
  86. fi
  87. if [ -d /Library/StartupItems/Tor ]; then
  88. rm -f /Library/StartupItems/Tor/Tor.loc
  89. echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
  90. fi