forked from wwwiretap/Tor-Cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ioerror.sh
91 lines (81 loc) · 2.25 KB
/
ioerror.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash
# This is the code to run on an Ubuntu machine to prep it as a relay, bridge or
# private bridge
#
USER="`whoami`";
DISTRO="`lsb_release -c|cut -f2`";
SOURCES="/etc/apt/sources.list";
CONFIG="$1";
CONFIG_FILE="/etc/tor/torrc";
RESERVATION="`curl -m 5 http://169.254.169.254/latest/meta-data/reservation-id | sed 's/-//'`";
if [ "$USER" != "root" ]; then
echo "root required; re-run with sudo";
exit 1;
fi
case "$CONFIG" in
"bridge" ) echo "selecting $CONFIG config...";;
"privatebridge" ) echo "selecting $CONFIG config...";;
"middlerelay" ) echo "selecting $CONFIG config...";;
* )
echo "You did not select a proper configuration: $CONFIG";
echo "Please try the following examples: ";
echo "$0 bridge";
echo "$0 privatebridge";
echo "$0 middlerelay";
exit 2;
;;
esac
echo "Adding Tor's repo for $DISTRO...";
cat << EOF >> $SOURCES
deb http://deb.torproject.org/torproject.org $DISTRO main
deb http://deb.torproject.org/torproject.org experimental-$DISTRO main
EOF
echo "Installing Tor's gpg key...";
gpg --keyserver keys.gnupg.net --recv 886DDD89
gpg --export A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89 | apt-key add -
echo "Installing Tor...";
apt-get -y update
apt-get -y install tor tor-geoipdb
echo "Configuring Tor...";
cp /etc/tor/torrc /etc/tor/torrc.bkp
if [ $CONFIG == "bridge" ]; then
echo "Configuring Tor as a $CONFIG";
cat << EOF > $CONFIG_FILE
# Auto generated public Tor $CONFIG config file
Nickname ec2$CONFIG$RESERVATION
SocksPort 0
ORPort 443
BridgeRelay 1
Exitpolicy reject *:*
EOF
fi
if [ $CONFIG == "private-bridge" ]; then
echo "Configuring Tor as a $CONFIG";
cat << EOF > $CONFIG_FILE
# Auto generated public Tor $CONFIG config file
Nickname ec2$CONFIG$RESERVATION
SocksPort 0
ORPort 443
BridgeRelay 1
PublishServerDescriptor 0
Exitpolicy reject *:*
EOF
fi
if [ $CONFIG == "middle-relay" ]; then
echo "Configuring Tor as a $CONFIG";
cat << EOF > $CONFIG_FILE
# Auto generated public Tor $CONFIG config file
Nickname ec2$CONFIG$RESERVATION
SocksPort 0
ORPort 443
DirPort 80
Exitpolicy reject *:*
EOF
fi
# XXX TODO
# Generally, we'll want to rm /var/lib/tor/* and remove all state from the system
echo "Restarting Tor...";
/etc/init.d/tor restart
sudo update-rc.d tor enable
echo "echo 'Tor Cloud Starting...'" > /etc/ioerror.sh
sudo reboot