TorPostflight 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #!/bin/sh
  2. # ====================================================================
  3. # TorPostFlight is distributed under this license
  4. #
  5. # Copyright (c) 2006 Andrew Lewman
  6. #
  7. # Redistribution and use in source and binary forms, with or without
  8. # modification, are permitted provided that the following conditions are
  9. # met:
  10. #
  11. # * Redistributions of source code must retain the above copyright
  12. # notice, this list of conditions and the following disclaimer.
  13. #
  14. # * Redistributions in binary form must reproduce the above
  15. # copyright notice, this list of conditions and the following disclaimer
  16. # in the documentation and/or other materials provided with the
  17. # distribution.
  18. #
  19. # * Neither the names of the copyright owners nor the names of its
  20. # contributors may be used to endorse or promote products derived from
  21. # this software without specific prior written permission.
  22. #
  23. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  29. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  30. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. # ======================================================================
  35. # TorPostflight gets invoked after any install or upgrade.
  36. ADDSYSUSER=$RECEIPT_PATH/addsysuser
  37. if [ ! -x "$ADDSYSUSER" ]; then
  38. echo "Could not find addsysuser script."
  39. exit 1
  40. fi
  41. TORUSER=_tor
  42. TORGROUP=daemon
  43. TARGET=$2/Library/Tor
  44. TORDIR=$TARGET/var/lib/tor
  45. LOGFILE=/var/log/tor.log
  46. TORBUTTON_VERSION="1.1.11-alpha"
  47. # Check defaults for TARGET
  48. if [ "$TARGET" == "//Library/Tor" ]; then
  49. TARGET=/Library/Tor
  50. fi
  51. # Create user $TORUSER in group daemon. If it's already there, great.
  52. $ADDSYSUSER $TORUSER "Tor System user" $TORDIR
  53. # Create the tor directory, if it doesn't exist.
  54. if [ ! -d $TORDIR ]; then
  55. mkdir -p $TORDIR
  56. fi
  57. # Check its permissions.
  58. chown $TORUSER $TORDIR
  59. chgrp daemon $TORDIR
  60. chmod 700 $TORDIR
  61. if [ ! -f $LOGFILE ]; then
  62. touch $LOGFILE
  63. chown $TORUSER $LOGFILE
  64. chgrp daemon $LOGFILE
  65. chmod 660 $LOGFILE
  66. fi
  67. # Create the configuration file only if there wasn't one already.
  68. if [ ! -f $TARGET/torrc ]; then
  69. cp $TARGET/torrc.sample $TARGET/torrc
  70. fi
  71. # Ensure symbolic links
  72. cd /usr/bin
  73. if [ -e /usr/bin/tor -a ! -L /usr/bin/tor ]; then
  74. mv tor tor_old
  75. fi
  76. if [ -e /usr/bin/tor-resolve -a ! -L /usr/bin/tor-resolve ]; then
  77. mv tor-resolve tor-resolve_old
  78. fi
  79. ln -sf $TARGET/tor .
  80. ln -sf $TARGET/tor-resolve .
  81. cd /usr/share/man/man1
  82. MAN1=$TARGET/share/man/man1
  83. #ln -sf $MAN1/*.1 .
  84. if [ -d /Library/StartupItems/Privoxy ]; then
  85. find /Library/StartupItems/Privoxy -print0 | xargs -0 chown root:wheel
  86. fi
  87. # Copy Documentation
  88. if [ -d $PACKAGE_PATH/Contents/Resources/documents ];then
  89. cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documents
  90. fi
  91. # Copy Uninstaller
  92. if [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then
  93. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript
  94. chmod 550 $TARGET/Tor_Uninstaller.applescript
  95. fi
  96. if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
  97. cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
  98. chmod 550 $TARGET/uninstall_tor_bundle.sh
  99. fi
  100. if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
  101. cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
  102. fi
  103. if [ -d /Library/StartupItems/Tor ]; then
  104. rm -f /Library/StartupItems/Tor/Tor.loc
  105. echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
  106. fi
  107. if [ -f /Applications/Firefox.app/Contents/MacOS/firefox ]; then
  108. if [ -f $TARGET/torbutton-$TORBUTTON_VERSION.xpi ]; then
  109. /Applications/Firefox.app/Contents/MacOS/firefox -install-global-extension $TARGET/torbutton-$TORBUTTON_VERSION.xpi
  110. # The following is a kludge to get around the fact that the installer
  111. # runs as root. This means the Torbutton extension will install with
  112. # root permissions; thereby making uninstalling Torbutton from inside
  113. # Firefox impossible. The user will be caught in an endless loop of
  114. # uninstall -> automatic re-installation of Torbutton. The OSX
  115. # installer doesn't tell you the owner of Firefox, therefore we have to
  116. # parse it.
  117. USR=`ls -alrt /Applications/Firefox.app/Contents/MacOS/extensions/ | tail -1 | awk '{print $3}'`
  118. GRP=`ls -alrt /Applications/Firefox.app/Contents/MacOS/extensions/ | tail -1 | awk '{print $4}'`
  119. chown -R $USR:$GRP /Applications/Firefox.app/Contents/MacOS/extensions/
  120. fi
  121. fi