forked from brunneis/tor-relay-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·74 lines (65 loc) · 2.29 KB
/
entrypoint.sh
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
#!/bin/bash
# Tor relay entrypoint
# Copyright (C) 2017 Rodrigo Martínez <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
if [ "$(whoami)" == "root" ]; then
userdel tor
useradd -s /bin/bash -u $HOST_UID tor \
&& echo -e "export NICKNAME='${NICKNAME:-NotProvided}'\n\
export CONTACT_INFO='${CONTACT_INFO:-NotProvided}'\n\
export OR_PORT='${OR_PORT:-9001}'\n\
export DIR_PORT='${DIR_PORT:-9030}'\n\
export CONTROL_PORT='${CONTROL_PORT:-9051}'\n\
export BANDWIDTH_RATE='${BANDWIDTH_RATE:-1 MBits}'\n\
export BANDWIDTH_BURST='${BANDWIDTH_BURST:-2 MBits}'\n\
export MAX_MEM='${MAX_MEM:-512 MB}'" > /home/tor/env.sh \
&& chown -R tor:tor /home/tor \
&& su -c "/entrypoint.sh $1" - tor
exit
fi
CONF_FILE=/home/tor/torrc
source ~/env.sh
echo -e "SocksPort 0\n\
DataDirectory /home/tor/data\n\
DisableDebuggerAttachment 0\n\
ORPort $OR_PORT\n\
ControlPort $CONTROL_PORT\n\
Nickname $NICKNAME\n\
ContactInfo $CONTACT_INFO\n\
RelayBandwidthRate $BANDWIDTH_RATE\n\
RelayBandwidthBurst $BANDWIDTH_BURST\n\
MaxMemInQueues $MAX_MEM" > $CONF_FILE
if [ "$1" == "middle" ]; then
echo -e "ExitRelay 0\n\
ExitPolicy reject *:*\n\
DirPort $DIR_PORT" >> $CONF_FILE
fi
if [ "$1" == "bridge" ]; then
echo -e "ExitRelay 0\n\
ExitPolicy reject *:*\n\
BridgeRelay 1" >> $CONF_FILE
fi
if [ "$1" == "exit" ]; then
echo -e "DirPort $DIR_PORT\n\
ExitPolicy reject 0.0.0.0/8:*\n\
ExitPolicy reject 10.0.0.0/8:*\n\
ExitPolicy reject 44.128.0.0/16:*\n\
ExitPolicy reject 127.0.0.0/8:*\n\
ExitPolicy reject 192.168.0.0/16:*\n\
ExitPolicy reject 169.254.0.0/15:*\n\
ExitPolicy reject 172.16.0.0/12:*\n\
ExitPolicy reject 62.141.55.117:*\n\
ExitPolicy reject 62.141.54.117:*\n\
ExitPolicy accept *:*" >> $CONF_FILE
fi
exec /usr/local/bin/tor -f ~/torrc