Tor 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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.5") OS="leopard" ARCH="universal";;
  26. "10.4") OS="tiger" ARCH="universal";;
  27. "10.3") OS="panther" ARCH="ppc";;
  28. "10.2") OS="jaguar" ARCH="ppc";;
  29. "10.1") OS="puma" ARCH="ppc";;
  30. "10.0") OS="cheetah" ARCH="ppc";;
  31. esac
  32. else
  33. OS="unknown"
  34. fi
  35. if [ $ARCH != "universal" ]; then
  36. export EVENT_NOKQUEUE=1
  37. fi
  38. ##
  39. # Tor Service
  40. ##
  41. . /etc/rc.common
  42. StartService ()
  43. {
  44. if [ -f $TORCMD ]; then
  45. if pid=$(GetPID Tor); then
  46. return 0
  47. else
  48. ConsoleMessage "Starting Tor Service"
  49. # Tentative
  50. # Making sure it is not running (I know it is not a best approarch)
  51. killall tor 2>/dev/null
  52. $TORCMD -f "$TORCONF" --runasdaemon 1 --pidfile "$TORPID" --datadirectory "$TORDATA" --user "$TORUSER" --group "$TORGROUP" --log "notice file $TORLOG" &
  53. fi
  54. fi
  55. }
  56. StopService ()
  57. {
  58. if pid=$(GetPID Tor); then
  59. ConsoleMessage "Stopping Tor Service"
  60. kill -TERM "${pid}"
  61. # Just for sanity (sometimes necessary.)
  62. killall tor 2>/dev/null
  63. else
  64. ConsoleMessage "Tor Service not responding."
  65. # Just for sanity (sometimes necessary.)
  66. killall tor 2>/dev/null
  67. fi
  68. }
  69. RestartService () { StopService; StartService; }
  70. if [ "$#" = 0 ]; then
  71. echo "Syntax: tor {start|stop}"
  72. exit 1
  73. fi
  74. RunService "$1"