forked from pwn4/dandruffapples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
local.sh
executable file
·210 lines (175 loc) · 6.87 KB
/
local.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/bash
#This script will parse the clockserver's config file to start the Antix system based on the arguments passed to it
#Usage: local.sh [argument1] [argument2] ...
#ARGUMENTS:
#-shortcut: will start with the following arguments: -all -sleepTime 0.2 -gnomeTerminal -debug -run
#-all: run the clockserver, worldviewer, controller, regionserver(s), client(s)
#-clockserver: run the clockserver
#-controller: run the controller
#-worldviewer: run the worldviewer
#-regionserver: run the regionserver(s)
#-client: run the client(s)
#-clientviewer: works ONLY if -client has been passed somewhere prior to it. Will start the client(s) with the -viewer option
#-debug: launch all the server in gdb
#-run: works ONLY if -debug has been passed somewhere prior to it. Will tell gdb to auto-run all the servers
#-gnomeTerminal: if passed then all the servers will be open using the "gnome-terminal" ( default: xterm )
#-sleepTime: time in seconds to wait before launching a new server ( default: 0 )
#-callgrind: launch the servers in vallgrind with the callgrind tool
#-memcheck: launch the servers in vallgrind with the memcheck tool
#EXAMPLES:
#./local.sh -clockserver -worldivewer -regionserver
#will launch only the clockserver, worldviewer and the regionserver(s) in xterm
#./local.sh -clockserver -gnomeTerminal
#will launch only the clockserver in gnome-terminal
#./local.sh -client -debug
#will launch only the client(s) in xterm, in gdb, but will not auto-run
#./local.sh -shortcut
#will launch the clockserver, worldviewer, controller, regionserver(s), client(s) in the gnometerminal, in gdb with the auto-run feature enabled and at an interval of 0.2 seconds
#WARNING: this script MUST be run from your root antix directory
clear
directory=`dirname $0`
clockConfig="$directory/clockserver/config"
#default sleep time is one second
sleepTime=2
#default terminal is xterm
terminal="xterm -T"
#figure out what flags need to be set from the arguments passed
while [ "$1" != "" ]; do
echo "Found \"${1,,}\" argument"
if [ "${1,,}" == "-shortcut" ]; then
clockserver=true
regionserver=true
controller=true
client=true
debug=true
run=true
sleepTime=0.5
elif [ "${1,,}" == "-all" ]; then
clockserver=true
regionserver=true
controller=true
client=true
elif [ "${1,,}" == "-clockserver" ]; then
clockserver=true
elif [ "${1,,}" == "-worldviewer" ]; then
worldviewer=true
elif [ "${1,,}" == "-regionserver" ]; then
regionserver=true
elif [ "${1,,}" == "-controller" ]; then
controller=true
elif [ "${1,,}" == "-client" ]; then
client=true
elif [ "${1,,}" == "-debug" ]; then
debug=true
elif [ "${1,,}" == "-run" ]; then
if [ $debug ]; then
run=true
else
echo "Cannot specify the \"-run\" argument without a preceding \"-debug\" argument"
fi
elif [ "${1,,}" == "-clientviewer" ]; then
if [ $client ]; then
clientViewer="-viewer"
else
echo "Cannot specify the \"-clientViewer\" argument without a preceding \"-client\" argument"
fi
elif [ "${1,,}" == "-gnometerminal" ]; then
gnomeTerminal=true
elif [ "${1,,}" == "-callgrind" ]; then
callgrind=true
elif [ "${1,,}" == "-memcheck" ]; then
memcheck=true
elif [ "${1,,}" == "-sleeptime" ]; then
shift
sleepTime=$1
else
echo "${1,,} is not a valid argument. Please read the documentation in this script"
fi
shift
done
if [ $debug ]; then
cmd="gdb -quiet --args "
if [ $run ]; then
cmd="gdb -quiet -ex run --args "
fi
fi
if [ $callgrind ]; then
cmd="valgrind --tool=callgrind --callgrind-out-file=/tmp/antix_callgrind_logs/callgrind.out."
mkdir /tmp/antix_callgrind_logs/
fi
if [ $memcheck ]; then
cmd="valgrind --tool=memcheck --leak-check=full --log-file=/tmp/antix_memcheck_logs/"
mkdir /tmp/antix_memcheck_logs/
fi
if [ $gnomeTerminal ]; then
terminal="gnome-terminal -t"
fi
while read inputline
do
field="$(echo $inputline | cut -d' ' -f1)"
if [ "$field" == "SERVERROWS" ]; then
serverRows="$(echo $inputline | cut -d' ' -f2)"
elif [ "$field" == "SERVERCOLS" ]; then
serverColumns="$(echo $inputline | cut -d' ' -f2)"
elif [ "$field" == "TEAMS" ]; then
teams="$(echo $inputline | cut -d' ' -f2)"
fi
done < $clockConfig
if [ $clockserver ]; then
killall clockserver
killall controller
killall worldviewer
killall regionserver
killall client
if [ $memcheck ] || [ $callgrind ]; then
cmdArgs="clockserver.%p "
fi
echo -e "Starting the clock server with command:\n$terminal \"Clockserver\" -e \"$cmd$cmdArgs$directory/clockserver/clockserver -c $directory/clockserver/config\" & \n"
$terminal "Clockserver" -e "$cmd$cmdArgs$directory/clockserver/clockserver -c $directory/clockserver/config" &
sleep $sleepTime
fi
if [ $controller ]; then
if [ $memcheck ] || [ $callgrind ]; then
cmdArgs="controller.%p "
fi
echo -e "Starting the controller with command:\n$terminal \"Controller\" -e \"$cmd$cmdArgs$directory/controller/controller -c $directory/controller/config\" & \n"
$terminal "Controller" -e "$cmd$cmdArgs$directory/controller/controller -c $directory/controller/config" &
sleep $sleepTime
fi
if [ $worldviewer ]; then
if [ $memcheck ] || [ $callgrind ]; then
cmdArgs="worldviewer.%p "
fi
echo -e "Starting the world viewer with command:\n$terminal \"World Viewer\" -e \"$cmd$cmdArgs$directory/worldviewer/worldviewer -c $directory/worldviewer/config\" & \n"
$terminal "World Viewer" -e "$cmd$cmdArgs$directory/worldviewer/worldviewer -c $directory/worldviewer/config" &
sleep $sleepTime
fi
if [ $regionserver ]; then
config="$directory/regionserver/config"
regionServers=`expr $serverRows \* $serverColumns`
for((i=1; i<=$regionServers; i++ ));do
if [ $memcheck ] || [ $callgrind ]; then
cmdArgs="regionserver$i.%p "
fi
if [ $i -eq 1 ]; then
echo -e "Starting the region server $i with command:\n$terminal \"Region Server: #$i\" -e \"$cmd$cmdArgs$directory/regionserver/regionserver -c $config\" & \n"
$terminal "Region Server #$i" -e "$cmd$cmdArgs$directory/regionserver/regionserver -c $config" &
sleep $sleepTime
else
echo -e "Starting the region server $i with command:\n$terminal \"Region Server: #$i\" -e \"$cmd$cmdArgs$directory/regionserver/regionserver -c $config$i\" & \n"
$terminal "Region Server #$i" -e "$cmd$cmdArgs$directory/regionserver/regionserver -c $config$i" &
sleep $sleepTime
fi
done
fi
if [ $client ]; then
for((i=0; i<$teams; i++ ));do
if [ $memcheck ] || [ $callgrind ]; then
cmdArgs="client$i.%p "
fi
echo -e "Starting the client with command:\n$terminal \"Client controlling team #$i\" -e \"$cmd$cmdArgs$directory/client/client -c $directory/client/config -t $i $clientViewer\" & \n"
$terminal "Client controlling team #$i" -e "$cmd$cmdArgs$directory/client/client -c $directory/client/config -t $i $clientViewer" &
sleep $sleepTime
done
fi
exit 0