TorPostflight 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #!/bin/sh
  2. # ====================================================================
  3. # TorPostFlight is distributed under this license
  4. #
  5. # Copyright (c) 2006 Andrew Lewman
  6. # Copyright (c) 2008 The Tor Project
  7. #
  8. # Redistribution and use in source and binary forms, with or without
  9. # modification, are permitted provided that the following conditions are
  10. # met:
  11. #
  12. # * Redistributions of source code must retain the above copyright
  13. # notice, this list of conditions and the following disclaimer.
  14. #
  15. # * Redistributions in binary form must reproduce the above
  16. # copyright notice, this list of conditions and the following disclaimer
  17. # in the documentation and/or other materials provided with the
  18. # distribution.
  19. #
  20. # * Neither the names of the copyright owners nor the names of its
  21. # contributors may be used to endorse or promote products derived from
  22. # this software without specific prior written permission.
  23. #
  24. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  27. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  28. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  31. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  32. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  33. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. # ======================================================================
  36. # TorPostflight gets invoked after any install or upgrade.
  37. ADDSYSUSER=$RECEIPT_PATH/addsysuser
  38. if [ ! -x "$ADDSYSUSER" ]; then
  39. echo "Could not find addsysuser script."
  40. exit 1
  41. fi
  42. TORUSER=_tor
  43. TORGROUP=daemon
  44. TARGET=$2/Library/Tor
  45. TORDIR=$TARGET/var/lib/tor
  46. LOGFILE=/var/log/tor.log
  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. # Put the geoip database into the datadir
  72. if [ ! -f $TORDIR/geoip ]; then
  73. cp $PACKAGE_PATH/Contents/Resources/geoip $TORDIR/geoip
  74. fi
  75. # Ensure symbolic links
  76. cd /usr/bin
  77. if [ -e /usr/bin/tor -a ! -L /usr/bin/tor ]; then
  78. mv tor tor_old
  79. fi
  80. if [ -e /usr/bin/tor-resolve -a ! -L /usr/bin/tor-resolve ]; then
  81. mv tor-resolve tor-resolve_old
  82. fi
  83. ln -sf $TARGET/tor .
  84. ln -sf $TARGET/tor-resolve .
  85. cd /usr/share/man/man1
  86. MAN1=$TARGET/share/man/man1
  87. #ln -sf $MAN1/*.1 .
  88. # Copy Documentation
  89. if [ -d $PACKAGE_PATH/Contents/Resources/documents ];then
  90. cp -r $PACKAGE_PATH/Contents/Resources/documents $TARGET/documents
  91. fi
  92. # Copy Uninstaller
  93. if [ -f $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript ]; then
  94. cp $PACKAGE_PATH/Contents/Resources/Tor_Uninstaller.applescript $TARGET/Tor_Uninstaller.applescript
  95. chmod 550 $TARGET/Tor_Uninstaller.applescript
  96. fi
  97. if [ -f $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh ]; then
  98. cp $PACKAGE_PATH/Contents/Resources/uninstall_tor_bundle.sh $TARGET/uninstall_tor_bundle.sh
  99. chmod 550 $TARGET/uninstall_tor_bundle.sh
  100. fi
  101. if [ -f $PACKAGE_PATH/Contents/Resources/package_list.txt ]; then
  102. cp $PACKAGE_PATH/Contents/Resources/package_list.txt $TARGET/package_list.txt
  103. fi
  104. if [ -d /Library/StartupItems/Tor ]; then
  105. rm -f /Library/StartupItems/Tor/Tor.loc
  106. echo "$TARGET" > /Library/StartupItems/Tor/Tor.loc
  107. fi