-
Notifications
You must be signed in to change notification settings - Fork 19
/
generate.sh
executable file
·78 lines (66 loc) · 1.54 KB
/
generate.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
#!/bin/bash
param=$1
filter=$2
generate() {
SRC="/go/src/github.com/CovenantSQL/GNTE"
export DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
CLEAN=$DIR/scripts/clean.sh
if [ -f $CLEAN ];then
$CLEAN
rm -rf $CLEAN
fi
docker pull golang:1.11-stretch
docker run --rm -v $DIR:$SRC golang $SRC/scripts/gobuild.sh $param
$DIR/scripts/launch.sh
}
get_containers() {
if [ -n $filter ]; then
containers="$(docker ps --format '{{.Names}}' --filter 'network=CovenantSQL_testnet' --filter name=$filter)"
else
containers="$(docker ps --format '{{.Names}}' --filter 'network=CovenantSQL_testnet')"
fi
echo $containers
}
stopone() {
containers=`get_containers`
for i in $containers; do
array=("${array[@]}" $i)
done
len=${#array[@]}
if [ 0 -eq $len ]; then
return
fi
num=$(date +%s)
((rand=num%len))
echo "Stopping ${array[$rand]}"
docker stop ${array[$rand]}
}
stopall() {
containers=`get_containers`
for i in $containers; do
echo "Stopping $i"
docker stop $i
done
}
startall() {
containers="$(docker ps --format '{{.Names}}' --filter 'network=CovenantSQL_testnet' --filter status=exited)"
for i in $containers; do
echo "Starting $i"
docker start $i
done
}
case $param in
"stopone")
stopone
;;
'stopall')
stopall
;;
'startall')
startall
;;
*)
echo "Generate GNTE and running"
generate
;;
esac