-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.sh
executable file
·161 lines (140 loc) · 3.59 KB
/
start.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
#! /bin/bash
#signature
signature='
$$\ $$\ $$\ $$\ $$$$$$\ $$$$$$\
$$ | $$ |$$$\ $$ |$$ __$$\ $$ __$$\
$$ |$$ / $$$$\ $$ |\__/ $$ |$$ / \__|
$$$$$ / $$ $$\$$ | $$$$$$ |$$ |
$$ $$< $$ \$$$$ |$$ ____/ $$ |
$$ |\$$\ $$ |\$$$ |$$ | $$ | $$\
$$ | \$$\ $$ | \$$ |$$$$$$$$\ \$$$$$$ |
\__| \__|\__| \__|\________| \______/
----------------------------------------
'
# input discription
# n : number of games running simultaneously
# global_tag (optional): Game results will be saved on results/global_tag
# ssp (optional) : servers start port - first server will be run on
# this port and the number will be increased for next server and so on
# spd (optional) : servers port difference - the port number will be
# increased by sdp from each server to the next
#global variables
declare -i n
declare -i ssp
declare -i spd
teamsDIR=""
resultDIR=""
DIR=`dirname $0`
declare -i lineOfResults
declare -i lineOfGames=`wc -l $DIR/data/Games.txt | awk '{ print $1 }'`
declare -i firstLines
#methods
initialize() {
read -t 10 -p "enter path of teams directory: " teamsDIR
if [[ $teamsDIR = "" ]] ; then
echo "$DIR/teams"
fi
read -t 10 -p "enter path of results directory: " resultDIR
if [[ $resultDIR = "" ]] ; then
echo "$DIR/results"
fi
read -t 5 -p "enter number of games running simultaneously: " n
if [ $n -eq 0 ] ; then
n=1
echo "n=1"
fi
read -t 5 -p "enter servers start port: " ssp
if [[ $ssp -eq 0 ]]; then
ssp=6000
echo "ssp=6000"
fi
read -t 5 -p "enter servers port difference: " spd
if [[ $spd -eq 0 ]]; then
spd=10
echo "spd=10"
fi
}
writePathToFile() {
if [[ $resultDIR = "" ]] ; then
resultDIR=$DIR/results
fi
if [[ $teamsDIR = "" ]] ; then
teamsDIR=$DIR/teams
fi
firstChar=${resultDIR:0:1}
if [[ $firstChar = "." ]] ; then
resultDIR=${resultDIR:1}
resultDIR=`pwd`$resultDIR
fi
echo $teamsDIR > $DIR/data/path.txt
echo $resultDIR >> $DIR/data/path.txt
}
runOnPorts() {
declare -i i
for (( i= 0; i<n; i++)) ; do
$DIR/LocalSubScripts/runOnPort.sh $port $n $i &
port=$port+$spd
done
}
findLineOfResults() {
if [ -e $resultDIR/Results.txt ] ; then
lineOfResults=`wc -l $resultDIR/Results.txt | awk '{ print $1 }'`
else
lineOfResults=0
fi
}
bar() {
local items=$1
local total=$2
local size=$3
per=$(($items*$size/$total % $size))
left=$(($size-$per))
chars=$(local s=$(printf "%${per}s"); echo "${s// /=}")
echo -ne "[$chars>";
printf "%${left}s"
echo -ne ']\r'
}
clearbar() {
local size=$1
printf " %s${size} "
echo -ne "\r"
}
progressBar() {
declare -i preLine=-1
findLineOfResults
firstLines=$lineOfResults
lineOfResults=0
bar 0 100 50
lineOfGames=`wc -l $DIR/data/Games.txt | awk '{ print $1 }'`
while ! [ $lineOfGames -eq $lineOfResults ] ; do
findLineOfResults
lineOfResults=$lineOfResults-$firstLines
lineOfGames=`wc -l $DIR/data/Games.txt | awk '{ print $1 }'`
declare -i percent=$lineOfResults
percent=$percent*100
percent=$percent/$lineOfGames
if ! [ $lineOfResults -eq $preLine ] ; then
echo -n $percent %
bar $percent 100 50
fi
preLine=$lineOfResults
done
echo "[=======================================================>"
echo "Done!"
}
#main method
main() {
echo "$signature"
sed -i -r '/^\s*$/d' $DIR/data/Games.txt
initialize
writePathToFile
# $$ -> the process number of the current shell
echo "start" $$ > $DIR/proc.txt
# running runOnPort script for each set of games (n times)
declare -i port=$ssp
runOnPorts
progressBar
rm $DIR/proc.txt
}
#
main