-
Notifications
You must be signed in to change notification settings - Fork 3
/
configureNetwork.sh
executable file
·203 lines (157 loc) · 4.76 KB
/
configureNetwork.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
#!/bin/bash
netFolder=$2
nParticipants=$3
bold=$(tput bold)
normal=$(tput sgr0)
# api token for algod and kmd service (used by the evaluator)
apiToken="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
# Algod relay
algodRelayDocker='{
"Version": 14,
"GossipFanout": 2,
"NetAddress": ":4444",
"EndpointAddress": "0.0.0.0:4001",
"DNSBootstrapID": "",
"EnableProfiler": true
}'
# Algod participant
algodPartDocker='{
"Version": 14,
"GossipFanout": 2,
"IncomingConnectionsLimit": 0,
"DNSBootstrapID": "",
"EndpointAddress": "0.0.0.0:4001",
"EnableProfiler": true
}'
# kmd relay
kmdDocker='{
"address": "0.0.0.0:4002", `
"allowed_origins": [
"*"
]
}'
function configureDocker {
echo '>> 🚢 Configuring network for docker-compose...'
cd $netFolder
echo ">> 🧹 Cleaning this net: ${PWD}"
echo ""
sleep 1
configurePartDocker
configureRelayDocker
createDockerCompose
}
function configurePartDocker {
echo "🛳 Configuring participants nodes for docker-compose..."
# generate all algod/kmd configs for all nodes
for i in `seq 1 $nParticipants`;
do
nodeFolder="Node-${i}"
cd $nodeFolder
# create algod token
touch algod.token
echo $apiToken >> algod.token
touch config.json
echo $algodPartDocker >> config.json
echo ">>✅ Created algod config for ${bold}${nodeFolder}${normal} in: ${PWD}..."
# check if folder exists
if [ ! -d "kmd-v0.5" ]; then
mkdir kmd-v0.5
fi
cd kmd-v0.5
# create kmd token
touch kmd.token
echo $apiToken >> kmd.token
touch kmd_config.json
echo $kmdDocker >> kmd_config.json
echo ">>✅ Created kmd config for ${bold}${nodeFolder}${normal} in: ${PWD}..."
cd ..
cp ../../docker_config/part/start.sh start.sh
cd ..
echo " "
done
}
function configureRelayDocker {
echo ">>🛳 Configuring relay node for docker-compose..."
cd 'Relay-Node'
# create algod token
touch algod.token
echo $apiToken >> algod.token
touch config.json
echo $algodRelayDocker >> config.json
echo ">>✅ Created algod config for ${bold}Relay-Node${normal} in: ${PWD}..."
if [ ! -d "kmd-v0.5" ]; then
mkdir kmd-v0.5
fi
cd kmd-v0.5
# create kmd token
touch kmd.token
echo $apiToken >> kmd.token
touch kmd_config.json
echo $kmdDocker >> kmd_config.json
echo ">>✅ Created kmd config for ${bold}Relay-Node${normal} in: ${PWD}..."
cd ..
cp ../../docker_config/relay/start.sh start.sh
}
function createDockerCompose {
cd ../..
echo ">> Creating docker-compose.yml file..."
python3 dockerYamlGenerator.py $nParticipants $netFolder
echo ">> Done!"
}
function clean {
echo ">>🧹 Cleaning configuration files..."
cd $netFolder
echo ">>🧹 Cleaning this net: ${PWD}"
sleep 1
echo ""
rm -rf nodes.json
for i in `seq 1 $nParticipants`;
do
nodeFolder="Node-${i}"
# check if node exists
if [[ -d $nodeFolder ]]; then
cd $nodeFolder
echo ">>🗑 Removing algod config for ${bold}${nodeFolder}${normal} in: ${PWD}..."
rm -rf config.json
echo ">>🗑 Removing algod.token for ${bold}${nodeFolder}${normal} in: ${PWD}..."
rm -rf algod.token
if [ -d "kmd-v0.5" ]; then
cd 'kmd-v0.5'
echo ">>🗑 Removing kmd.token for ${bold}${nodeFolder}${normal} in: ${PWD}..."
rm -rf kmd.token
if [[ -f "kmd_config.json" ]]; then
echo ">>🗑 Removing kmd config for ${bold}${nodeFolder}${normal} in: ${PWD}..."
rm -rf kmd_config.json
fi
cd ..
fi
cd ..
fi
echo ""
done
if [[ -d "Relay-Node" ]]; then
cd 'Relay-Node'
echo ">>🗑 Removing algod config for ${bold}Relay-Node${normal} in: ${PWD}..."
rm -rf config.json
rm -rf algod.token
if [ -d "kmd-v0.5" ]; then
cd 'kmd-v0.5'
echo ">>🗑 Removing kmd.token for ${bold}${nodeFolder}${normal} in: ${PWD}..."
rm -rf kmd.token
if [[ -f "kmd_config.json" ]]; then
echo ">>🗑 Removing kmd config for ${bold}Relay-Node${normal} in: ${PWD}..."
rm -rf kmd_config.json
fi
cd ..
fi
fi
}
if [[ $1 = "docker" ]]; then
configureDocker
exit
fi
if [[ $1 = "clean" ]]; then
clean
exit
fi
# sh configureNetwork.sh clean testNet 3