-
Notifications
You must be signed in to change notification settings - Fork 59
/
tools.sh
executable file
·380 lines (296 loc) · 7.95 KB
/
tools.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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
#!/usr/bin/env bash
set -o errexit
set -o verbose
set -o xtrace
set -o nounset
# download, compile and install python: https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz
# download, decompress node:
# sudo apt install build-essential cmake libboost-all-dev libz3-dev libcupti-dev
BASE_DIR=${PWD}
AGENT_DIR=${BASE_DIR}/agent
AGENT_SRC_DIR=${AGENT_DIR}/src
INSTALL_DIR=${BASE_DIR}/local
PYTHON2_DIR=${INSTALL_DIR}/python2
PYTHON2_BIN_DIR=${INSTALL_DIR}/python2/bin
PYTHON2=${PYTHON2_DIR}/bin/python2
PYTHON3_DIR=${INSTALL_DIR}/python3
PYTHON3=${PYTHON3_DIR}/bin/python3
PIP3=${PYTHON3_DIR}/bin/pip3
VENV=${INSTALL_DIR}/venv
VENV_BIN_DIR=${VENV}/bin
VPYTHON3=${VENV}/bin/python3
NODE_DIR=${INSTALL_DIR}/node
NODE=${NODE_DIR}/bin/node
NPM=${NODE_DIR}/bin/npm
NODE_MODULES=${AGENT_DIR}/node_modules
VENDOR=${AGENT_SRC_DIR}/sn_agent_ui/static/vendor
RUBY_DIR=${INSTALL_DIR}/ruby
RUBY=${RUBY_DIR}/bin/ruby
GEM=${RUBY_DIR}/bin/gem
SCSS=${RUBY_DIR}/bin/scss
REDIS_DIR=${INSTALL_DIR}/redis
REDIS=${REDIS_DIR}/bin/redis-server
GETH=${INSTALL_DIR}/geth/geth
SOLC=${INSTALL_DIR}/solidity-src/build/solc/solc
function ensure_root {
# Make sure only root can run our script
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
}
function system_prep {
ensure_root
apt install build-essential cmake libboost-all-dev libz3-dev libcupti-dev zlib1g-dev g++ libssl-dev
}
function install_docker {
ensure_root
#https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/
apt-get remove docker docker-engine docker.io
apt-get update
apt-get install apt-transport-https ca-certificates curl software-properties-common linux-image-extra-$(uname -r) linux-image-extra-virtual
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
apt-key fingerprint 0EBFCD88
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
apt-get update
apt-get install docker-ce
}
function ensure_install_dir {
mkdir -p ${INSTALL_DIR}
}
function install_python2 {
ensure_install_dir
cd ${INSTALL_DIR}
src=python2-src.tgz
if [ ! -f ${src} ]; then
curl -o ${src} "https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgz"
fi
out_dir=python2-src
if [ ! -d ${out_dir} ]; then
mkdir ${out_dir}
tar xfzv ${src} --directory ${out_dir} --strip-components=1
fi
if [ ! -f ${PYTHON2} ]; then
cd ${out_dir}
./configure --prefix=${PYTHON2_DIR}
make
# make test
make install
cd ..
fi
cd ..
}
function install_python3 {
ensure_install_dir
cd ${INSTALL_DIR}
src=python3-src.tgz
if [ ! -f ${src} ]; then
curl -o ${src} "https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tgz"
fi
out_dir=python3-src
if [ ! -d ${out_dir} ]; then
mkdir ${out_dir}
tar xfzv ${src} --directory ${out_dir} --strip-components=1
fi
if [ ! -f ${PYTHON3} ]; then
cd ${out_dir}
./configure --prefix=${PYTHON3_DIR}
make
make test
make install
cd ..
fi
cd ..
}
function install_node {
ensure_install_dir
cd ${INSTALL_DIR}
src=node-src.tgz
if [ ! -f ${src} ]; then
curl -o ${src} "https://nodejs.org/dist/v6.11.2/node-v6.11.2.tar.gz"
fi
out_dir=node-src
if [ ! -d ${out_dir} ]; then
mkdir ${out_dir}
tar xfzv ${src} --directory ${out_dir} --strip-components=1
fi
if [ ! -f ${NODE} ]; then
cd ${out_dir}
export PATH=${PYTHON2_BIN_DIR}:$PATH
${PYTHON2} configure --prefix=${NODE_DIR}
make -j4
make install
cd ..
fi
cd ..
}
function install_solidity {
ensure_install_dir
cd ${INSTALL_DIR}
src=solidity-src.tgz
if [ ! -f ${src} ]; then
curl -L -o ${src} "https://github.com/ethereum/solidity/releases/download/v0.4.16/solidity_0.4.16.tar.gz"
fi
out_dir=solidity-src
if [ ! -d ${out_dir} ]; then
mkdir ${out_dir}
tar xfzv ${src} --directory ${out_dir} --strip-components=1
fi
if [ ! -f ${SOLC} ]; then
cd ${out_dir}
mkdir -p build
cd build
cmake ..
make
cd ..
fi
cd ..
}
function install_ruby {
ensure_install_dir
cd ${INSTALL_DIR}
src=ruby-src.tgz
if [ ! -f ${src} ]; then
curl -o ${src} "https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.1.tar.gz"
fi
out_dir=ruby-src
if [ ! -d ${out_dir} ]; then
mkdir ${out_dir}
tar xfzv ${src} --directory ${out_dir} --strip-components=1
fi
if [ ! -f ${RUBY} ]; then
cd ${out_dir}
./configure --prefix=${RUBY_DIR}
make
make install
cd ..
fi
cd ..
}
function install_redis {
ensure_install_dir
cd ${INSTALL_DIR}
src=redis-src.tgz
if [ ! -f ${src} ]; then
curl -o ${src} "http://download.redis.io/releases/redis-4.0.1.tar.gz"
fi
out_dir=redis-src
if [ ! -d ${out_dir} ]; then
mkdir ${out_dir}
tar xfzv ${src} --directory ${out_dir} --strip-components=1
fi
if [ ! -f ${REDIS} ]; then
cd ${out_dir}
make
make test
make PREFIX=${REDIS_DIR} install
cd ..
fi
cd ..
}
function install_geth {
ensure_install_dir
cd ${INSTALL_DIR}
src=geth.tgz
if [ ! -f ${src} ]; then
curl -o ${src} "https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.6.7-ab5646c5.tar.gz"
fi
out_dir=geth
if [ ! -d ${out_dir} ]; then
mkdir ${out_dir}
tar xfzv ${src} --directory ${out_dir} --strip-components=1
fi
cd ..
}
function install_gems {
if [ ! -f ${SCSS} ]; then
${GEM} install sass
fi
}
function install_pip {
${PYTHON3} -m venv ${VENV}
echo $PWD
${VENV}/bin/pip3 install -r ${AGENT_DIR}/requirements.txt
}
function remove_install_dir {
rm -Rf ${INSTALL_DIR}
}
function npm_run {
cd ${AGENT_SRC_DIR}
PATH=${NODE_DIR}/bin:$PATH ${NPM} install
cd ..
}
function copy_vendor {
# Seems weird that we have to do this, I would prefer to use them in-place and have some sort of collector put them where they need to be after a compression - Webpack?
rm -Rf ${VENDOR}
mkdir ${VENDOR}
cp -R ${NODE_MODULES}/bootstrap/dist ${VENDOR}/bootstrap
cp -R ${NODE_MODULES}/jquery/dist ${VENDOR}/jquery
cp -R ${NODE_MODULES}/vue/dist ${VENDOR}/vue
cp -R ${NODE_MODULES}/metismenu/dist ${VENDOR}/metismenu
cp -R ${NODE_MODULES}/font-awesome ${VENDOR}/font-awesome
cp -R ${NODE_MODULES}/highcharts ${VENDOR}/highcharts
}
function create_docs {
${VENV_BIN_DIR}/sphinx-build -b dirhtml "${AGENT_DIR}/docs/" "${AGENT_DIR}/docs/_build"
# make html
# make coverage
cd ..
}
function run_tests {
cd ${AGENT_DIR}
${VENV}/bin/tox
}
case "$1" in
clean)
remove_install_dir
;;
system-prep)
system_prep
;;
prep)
install_python2
install_python3
install_node
install_ruby
install_redis
install_geth
install_gems
install_pip
install_solidity
npm_run
copy_vendor
;;
install_docker)
install_docker
;;
run)
source ${AGENT_DIR}/activate.settings.sh
PYTHONPATH=${AGENT_SRC_DIR} ${VENV_BIN_DIR}/adev runserver --verbose ${AGENT_SRC_DIR}/sn_agent
;;
run-geth)
source ${AGENT_DIR}/activate.settings.sh
${GETH} --rpcapi admin,debug,personal,txpool,eth,web3,shh --rpc --shh --datadir "/mnt/singnet-data/geth-data" --syncmode "full"
;;
run-redis)
source ${AGENT_DIR}/activate.settings.sh
${REDIS}
;;
reset)
source ${AGENT_DIR}/activate.settings.sh
PYTHONPATH=${AGENT_SRC_DIR} ${VPYTHON3} sn_agent/utils.py
;;
cookie)
cd ${AGENT_SRC_DIR}
PYTHONPATH=${AGENT_SRC_DIR} ${VPYTHON3} sn_agent/session.py
;;
docs)
create_docs
;;
test)
run_tests
;;
*) echo 'No operation specified'
exit 0;
;;
esac