-
Notifications
You must be signed in to change notification settings - Fork 23
/
overall.sh
executable file
·102 lines (78 loc) · 2.36 KB
/
overall.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
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
PREFIX=/tmp/crypt
torshutdown()
{
PREFIX=$PREFIX; kill -s SIGINT `cat $PREFIX/working/tor/tor.pid`
}
torstartup()
{
#-f: Use this configuration file
PREFIX=$PREFIX; $PREFIX/tor/src/or/tor -f $PREFIX/conf/torrc
check_resolv
}
check_resolv()
{
res=`cat /etc/resolv.conf`
if [ "$res" != "nameserver 127.0.0.1" ]
then
mv /etc/resolv.conf /etc/resolv.conf.reticlemove
echo "nameserver 127.0.0.1" > /etc/resolv.conf
fi
}
shutdown()
{
torshutdown
kill `cat $PREFIX/working/client/client.pid`
PREFIX=$PREFIX; nginx -p $PREFIX/working/nginx/ -c $PREFIX/conf/nginx.conf -s quit
PREFIX=$PREFIX; /usr/local/bin/couchdb -d -n -a $PREFIX/conf/couchdb.ini -p $PREFIX/working/couchdb/couch.pid
mv /etc/resolv.conf.reticlemove /etc/resolv.conf
sudo iptables -t nat -D OUTPUT -p tcp -d 10.192.0.0/10 -j REDIRECT --to-ports 9040
return $?
}
control_c()
# run if user hits control-c
{
echo -en "\n*** Exiting ***\n"
shutdown
rm $PREFIX/working/overall.pid
exit 0
}
startup()
{
# First: Make the directories, if necessary
mkdir -p $PREFIX/working/couchdb
mkdir -p $PREFIX/working/client
mkdir -p $PREFIX/working/nginx
mkdir -p $PREFIX/working/tor
#-b: Run in background
#-n: Reset configuration chain (to get rid of /etc)
#-a: Use this configuration file
#-p: Use this PID file
#-d: Shutdown the system
#-o: Use this STDOUT file
#-e: Use this STDERR file
PREFIX=$PREFIX; /usr/local/bin/couchdb -b -n -a $PREFIX/conf/couchdb.ini \
-p $PREFIX/working/couchdb/couch.pid \
-o $PREFIX/working/couchdb/couch.stdout \
-e $PREFIX/working/couchdb/couch.stderr
#-p: Set prefix (to make relative paths work in configuration file)
#-c: Set configuration file
#-s: Send signal (e.g., quit)
PREFIX=$PREFIX; nginx -p $PREFIX/working/nginx/ -c $PREFIX/conf/nginx.conf
torstartup
sudo iptables -t nat -A OUTPUT -p tcp -d 10.192.0.0/10 -j REDIRECT --to-ports 9040
$PREFIX/client.rb &
}
reset()
{
#Only Tor needs to be reset in case of a connection interruption.
torshutdown
torstartup
}
# trap keyboard interrupt (control-c)
trap control_c SIGINT
trap reset SIGUSR1
echo $BASHPID > $PREFIX/working/overall.pid
startup
# main() loop
while true; do sleep 120; check_resolv; done