TorPostflight 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. TORBUTTON_VERSION="1.1.8-alpha"
  14. # Check defaults for TARGET
  15. if [ "$TARGET" == "//Library/Tor" ]; then
  16. TARGET=/Library/Tor
  17. fi
  18. # Create user $TORUSER in group daemon. If it's already there, great.
  19. $ADDSYSUSER $TORUSER "Tor System user" $TORDIR
  20. # Create the tor directory, if it doesn't exist.
  21. if [ ! -d $TORDIR ]; then
  22. mkdir -p $TORDIR
  23. fi
  24. # Check its permissions.
  25. chown $TORUSER $TORDIR
  26. chgrp daemon $TORDIR
  27. chmod 700 $TORDIR
  28. if [ ! -f $LOGFILE ]; then
  29. touch $LOGFILE
  30. chown $TORUSER $LOGFILE
  31. chgrp daemon $LOGFILE
  32. chmod 660 $LOGFILE
  33. fi
  34. # Create the configuration file only if there wasn't one already.
  35. if [ ! -f $TARGET/torrc ]; then
  36. cp $TARGET/torrc.sample $TARGET/torrc
  37. fi
  38. # Ensure symbolic links
  39. cd /usr/bin
  40. if [ -e /usr/bin/tor -a ! -L /usr/bin/tor ]; then
  41. mv tor tor_old
  42. fi
  43. if [ -e /usr/bin/tor-resolve -a ! -L /usr/bin/tor-resolve ]; then
  44. mv tor-resolve tor-resolve_old
  45. fi
  46. ln -sf $TARGET/tor .
  47. ln -sf $TARGET/tor-resolve .
  48. cd /usr/share/man/man1
  49. MAN1=$TARGET/man/man1
  50. ln -sf $MAN1/*.1 .
  51. if [ -d /Library/StartupItems/Privoxy ]; then
  52. find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheel
  53. fi
  54. # Copy Documentation
  55. if [ -d $PACKAGE_PATH/Contents/Resources/documents ];then
  56. cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documents
  57. fi
  58. # Copy Uninstaller
  59. if [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then
  60. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript
  61. chmod 550 $TARGET/Tor_Uninstaller.applescript
  62. fi
  63. if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
  64. cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
  65. chmod 550 $TARGET/uninstall_tor_bundle.sh
  66. fi
  67. if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
  68. cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
  69. fi
  70. if [ -d /Library/StartupItems/Tor ]; then
  71. rm -f /Library/StartupItems/Tor/Tor.loc
  72. echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
  73. fi
  74. if [ -f /Applications/Firefox.app/Contents/MacOS/firefox ]; then
  75. if [ -f $TARGET/torbutton-$TORBUTTON_VERSION.xpi ]; then
  76. /Applications/Firefox.app/Contents/MacOS/firefox -install-global-extension $TARGET/torbutton-$TORBUTTON_VERSION.xpi
  77. # The following is a kludge to get around the fact that the installer
  78. # runs as root. This means the Torbutton extension will install with
  79. # root permissions; thereby making uninstalling Torbutton from inside
  80. # Firefox impossible. The user will be caught in an endless loop of
  81. # uninstall -> automatic re-installation of Torbutton. The OSX
  82. # installer doesn't tell you the owner of Firefox, therefore we have to
  83. # parse it.
  84. USR=`ls -alrt /Applications/Firefox.app/Contents/MacOS/extensions/ | tail -1 | awk '{print $3}'`
  85. GRP=`ls -alrt /Applications/Firefox.app/Contents/MacOS/extensions/ | tail -1 | awk '{print $4}'`
  86. chown -R $USR:$GRP /Applications/Firefox.app/Contents/MacOS/extensions/
  87. fi
  88. fi