aboutsummaryrefslogtreecommitdiff
path: root/contrib/osx/Tor
blob: 901759c42664dd6b22bc5dfe1711a376d434222c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh

TORLOC=/Library/StartupItems/Tor/Tor.loc

if [ -f $TORLOC ]; then
 TORDIR=`cat /Library/StartupItems/Tor/Tor.loc`
 if [ "x$TORDIR" = "x" -o ! -d $TORDIR -o ! -x $TORDIR/tor ]; then
   TORDIR=/Library/Tor
 fi
else
 TORDIR=/Library/Tor
fi
TORCONF=$TORDIR/torrc
TORDATA=$TORDIR/var/lib/tor
TORPID=/var/run/Tor.pid
TORUSER=_tor
TORGROUP=daemon
TORCMD=$TORDIR/tor
TORLOG=/var/log/tor.log

## Determine OSX Version
# map version to name
if [ -x /usr/bin/sw_vers ]; then
# This is poor, yet functional.  We don't care about the 3rd number in
# the OS version
  OSVER=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 | cut -d"." -f1,2`
      case "$OSVER" in
	"10.5") OS="leopard" ARCH="universal";;
	"10.4") OS="tiger" ARCH="universal";;
	"10.3") OS="panther" ARCH="ppc";;
	"10.2") OS="jaguar" ARCH="ppc";;
	"10.1") OS="puma" ARCH="ppc";;
	"10.0") OS="cheetah" ARCH="ppc";;
      esac
else
	OS="unknown"
fi

if [ $ARCH != "universal" ]; then
	export EVENT_NOKQUEUE=1
fi


##
# Tor Service
##

. /etc/rc.common

StartService ()
{

    if [ -f $TORCMD ]; then
        if pid=$(GetPID Tor); then
            return 0
        else
		ConsoleMessage "Starting Tor Service"
# Tentative
# Making sure it is not running (I know it is not a best approarch)
		killall tor 2>/dev/null
		$TORCMD -f "$TORCONF" --runasdaemon 1 --pidfile "$TORPID" --datadirectory "$TORDATA" --user "$TORUSER" --group "$TORGROUP" --log "notice file $TORLOG" &
	fi
    fi
}

StopService ()
{
    if pid=$(GetPID Tor); then
	ConsoleMessage "Stopping Tor Service"
	kill -TERM "${pid}"
# Just for sanity (sometimes necessary.)
	killall tor 2>/dev/null
    else
	ConsoleMessage "Tor Service not responding."
# Just for sanity (sometimes necessary.)
	killall tor 2>/dev/null
    fi
}

RestartService () { StopService; StartService; }

if [ "$#" = 0 ]; then
  echo "Syntax: tor {start|stop}"
  exit 1
fi 

RunService "$1"