~privacy-squad/+junk/tor-middle-relay-snap

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
#!/bin/sh

set -eu

mkdir --parents --mode=0755 "$SNAP_DATA/control"

# Expect a new release at least every 8 months. If this package is older, then
# refuse to run.
if test $(date +%s -d "8 months ago") -gt $(date +%s -d "2018-05-13"); then
	echo "This snap is too old to be allowed to run. Old software could damage the integrity of the Tor network. Please refresh."
	exit 1
fi

set -- \
	-f "$SNAP_DATA/configuration" --allow-missing-torrc \
	--defaults-torrc "$SNAP/torrc-defaults" \
	--PortForwardingHelper "$SNAP/bin/tor-fw-helper" \
	--DataDirectory "$SNAP_DATA/data" \
	--Nickname "UbuntuCore$SNAP_REVISION" \
	--PidFile "$SNAP_DATA/pid" \
	--ControlPort auto --ControlPortWriteToFile "$SNAP_DATA/control/port" --ControlPortFileGroupReadable 1 \
	--CookieAuthentication 1 --CookieAuthFile "$SNAP_DATA/control/cookieauth" --CookieAuthFileGroupReadable 1


if ! test -f "$SNAP_DATA/data/fingerprint"; then
	"$SNAP/bin/tor" "$@" --list-fingerprint
	# This generates a key if it doesn't exist, so the upcoming test works.
fi

set -- "$@" --hush

if grep --line-regexp '.*[0123]' "$SNAP_DATA/data/fingerprint" >/dev/null 2>/dev/null; then
	set -- "$@" --ServerTransportPlugin "obfs4 exec $SNAP/bin/obfs4proxy" --BridgeRelay 1
fi


if test "${SNAP_REVISION#x}" != "${SNAP_REVISION}" || test "$SNAP_REVISION" -gt 10000; then
	set -- "$@" --PublishServerDescriptor 0
fi


cat "$SNAP_DATA/data/fingerprint" |
	while read name fp; do
		echo "$SNAP_NAME statistics will be https://atlas.torproject.org/#details/${fp}"
	done

ulimit -d 500""000
ulimit -m 500""000

exec "$SNAP/bin/tor" "$@"