Tor 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/sh
  2. TORLOC=/Library/StartupItems/Tor/Tor.loc
  3. if [ -f $TORLOC ]; then
  4. TORDIR=`cat /Library/StartupItems/Tor/Tor.loc`
  5. if [ "x$TORDIR" = "x" -o ! -d $TORDIR -o ! -x $TORDIR/tor ]; then
  6. TORDIR=/Library/Tor
  7. fi
  8. else
  9. TORDIR=/Library/Tor
  10. fi
  11. TORCONF=$TORDIR/torrc
  12. TORDATA=$TORDIR/var/lib/tor
  13. TORPID=/var/run/Tor.pid
  14. TORUSER=_tor
  15. TORGROUP=daemon
  16. TORCMD=$TORDIR/tor
  17. TORLOG=/var/log/tor.log
  18. ## Determine OSX Version
  19. # map version to name
  20. if [ -x /usr/bin/sw_vers ]; then
  21. # This is poor, yet functional. We don't care about the 3rd number in
  22. # the OS version
  23. OSVER=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 | cut -d"." -f1,2`
  24. case "$OSVER" in
  25. "10.6") ARCH="universal";;
  26. "10.5") ARCH="universal";;
  27. "10.4") ARCH="universal";;
  28. "10.3") ARCH="ppc";;
  29. "10.2") ARCH="ppc";;
  30. "10.1") ARCH="ppc";;
  31. "10.0") ARCH="ppc";;
  32. esac
  33. else
  34. ARCH="unknown"
  35. fi
  36. if [ $ARCH != "universal" ]; then
  37. export EVENT_NOKQUEUE=1
  38. fi
  39. ##
  40. # Tor Service
  41. ##
  42. . /etc/rc.common
  43. StartService ()
  44. {
  45. if [ -f $TORCMD ]; then
  46. if pid=$(GetPID Tor); then
  47. return 0
  48. else
  49. ConsoleMessage "Starting Tor Service"
  50. # Tentative
  51. # Making sure it is not running (I know it is not a best approarch)
  52. killall tor 2>/dev/null
  53. $TORCMD -f "$TORCONF" --runasdaemon 1 --pidfile "$TORPID" --datadirectory "$TORDATA" --user "$TORUSER" --group "$TORGROUP" --log "notice file $TORLOG" &
  54. fi
  55. fi
  56. }
  57. StopService ()
  58. {
  59. if pid=$(GetPID Tor); then
  60. ConsoleMessage "Stopping Tor Service"
  61. kill -TERM "${pid}"
  62. # Just for sanity (sometimes necessary.)
  63. killall tor 2>/dev/null
  64. else
  65. ConsoleMessage "Tor Service not responding."
  66. # Just for sanity (sometimes necessary.)
  67. killall tor 2>/dev/null
  68. fi
  69. }
  70. RestartService () { StopService; StartService; }
  71. if [ "$#" = 0 ]; then
  72. echo "Syntax: tor {start|stop}"
  73. exit 1
  74. fi
  75. RunService "$1"