-
Notifications
You must be signed in to change notification settings - Fork 5
/
install.sh
474 lines (370 loc) · 13.8 KB
/
install.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
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
#!/bin/bash
BINARY_URL="https://github.com/mvc-labs/mvc-mining-instruction/releases/download"
NODE_FILE="mvc.tar.gz"
MINER_FILE="cpuminer.tar.gz"
# SHELL_NAME="install.sh"
WORKINGSPACE_DIR=""
NODE_DATA_DIR="node_data_dir"
NET_CHOOSE=
INIT_PARAMS=
VERSION_CHOOSE=
VERSION_LATEST="v0.2.0.0"
TEMP_DIR=
RPC_USERNAME=""
RPC_PASSWORD=""
dependencies_array=("build-essential" "libtool" "autotools-dev" "automake" "pkg-config" "libssl-dev" "libevent-dev" "bsdmainutils" "libboost-system-dev" "libboost-filesystem-dev" "libboost-chrono-dev" "libboost-program-options-dev" "libboost-test-dev" "libboost-thread-dev" "libdb-dev" "libdb++-dev" "libczmq-dev")
version_history=("v0.2.0.0" "v0.1.4.0" "v0.1.3.1" "v0.1.3.0" "v0.1.2.0")
ensure() {
if ! "$@"; then err "command $*" "failed" ; fi
}
say() {
printf '[%s] %s: %s\n' "$1" "$2" "$3"
}
err() {
say "ERROR" "$1" "$2" >&2
exit 1
}
warn() {
say "WARNING" "$1" "$2" >&2
}
check_dir() {
WORKINGSPACE_DIR=$(cd $(dirname $0); pwd)
echo -e "Are you sure you want to install the mvc node to : \033[1;40;34m$WORKINGSPACE_DIR \033[0m \\n[y / n]"
read -r dir_checked
case $dir_checked in
[yY][eE][sS]|[yY])
echo -e "You choose \"yes\". \nThe mvc node will be installed to : $WORKINGSPACE_DIR"
;;
[nN][oO]|[nN])
# echo -e "You choose \"no\". Run \n\033[1;40;34mmv $WORKINGSPACE_DIR/$SHELL_NAME [your working directory]\033[0m \nand rerun this script!"
echo -e "You choose \"no\"."
echo Installation quit!
exit 0
;;
*)
echo "Invalid input..."
exit 1
;;
esac
}
check_cmd() {
command -v "$1" > /dev/null 2>&1
}
install_curl(){
echo "Installing curl..."
sudo apt install curl 2>/dev/null > log/install_curl.log
if ! check_cmd curl; then
err "install failed: " "curl"
fi
}
install_gum(){
echo "Installing gum..."
ensure sudo mkdir -p /etc/apt/keyrings
if [ ! -f "/etc/apt/keyrings/charm.gpg" ]; then
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
fi
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list >/dev/null
sudo apt update 2>/dev/null > log/apt_update.log
sudo apt install gum 2>/dev/null > log/install_gum.log
if ! check_cmd gum; then
err "install failed: " "gum"
fi
}
install_wget(){
echo "Installing wget..."
sudo apt install wget 2>/dev/null > log/install_wget.log
if ! check_cmd curl; then
err "install failed: " "wget"
fi
}
install_tools(){
echo "Checking for missing tools..."
# install curl
if ! check_cmd curl; then
install_curl
fi
# install gum
if ! check_cmd gum; then
install_gum
fi
# install wget
if ! check_cmd wget gum; then
install_wget
fi
echo "Tools checked!"
}
pager_dependencies(){
for((i=0;i<${#dependencies_array[@]};i++))
do
echo -e "${dependencies_array[$i]}\n"
done
}
show_dependencies(){
pager_dependencies | gum pager
}
install_dependency(){
for((i=0;i<${#dependencies_array[@]};i++))
do
sudo gum spin --show-output --spinner globe --title "Installing ${dependencies_array[$i]}..." --title.foreground 99 -- sh -c "sudo apt-get install ${dependencies_array[$i]} > log/install_${dependencies_array[$i]}.log;sleep 1;echo '\033[32m✓\033[0m · ${dependencies_array[$i]}'"
done
echo -e "\033[32mAll dependencies installed!\033[0m"
}
install_dependencies() {
echo "Install dependencies..."
continue_install=$(gum choose "continue" "show dependencies" "quit")
case $continue_install in
"continue")
install_dependency
;;
"show dependencies")
show_dependencies
install_dependencies
;;
"quit")
echo "Installation quit!"
exit 0
;;
*)
esac
}
pager_version(){
echo "latest"
for((i=0;i<${#version_history[@]};i++))
do
echo -e "${version_history[$i]}"
done
}
node_version_choose(){
VERSION_CHOOSE=$(pager_version | gum filter --placeholder "Select version or innput to filter, default = latest")
if [ -z $VERSION_CHOOSE ]; then
gum confirm "Invalid version, choose again?" --affirmative "Okay" --negative "Quit"
if [ $? == 1 ];then
echo "Installation quit!"
exit 0
fi
node_version_choose
fi
if [ "$VERSION_CHOOSE" == "latest" ]; then
VERSION_CHOOSE=$VERSION_LATEST
fi
}
node_net_choose() {
echo "Please select the net you want to install!"
NET_CHOOSE=$(gum choose Mainnet Testnet)
case $NET_CHOOSE in
"Mainnet")
# gum confirm "Mainnet is coming soon! Do you want to try Testnet?" --affirmative "Okay" --negative "Cancel"
# if [ $? == 1 ];then
# echo "Installation quit!"
# exit 0
# fi
NET_CHOOSE="0"
INIT_PARAMS="MTM2NTAwMDAwMDAwMDAwMDoyNTAwMDAwMDAwOjE0NzAwMDpmYmI0Zjk3MTYyZTAyZDNiZTJjODYwYzdmNGRmNWQ4NjAwMzBiMDdmOjEw"
;;
"Testnet")
NET_CHOOSE="1"
INIT_PARAMS="NDIwMDAwMDAwMDAwMDAwOjUwMDAwMDAwMDA6MTQ3MDAwOjVlMTUxNDMwNTE2M2RiYTQ4YmM1NTAwYWRhMDg1Yzc4N2U3ZTBkYmU6MTA="
;;
*)
esac
}
confirm_install(){
gum confirm --default=false --affirmative "Think again" --negative "Confirm" --timeout=5s "Confirm to install!"
if [ $? == 0 ]; then
echo "Installation quit!"
exit 0
fi
}
create_dirs(){
TEMP_DIR=temp-$(date +%s%N)
echo "Creating node_data_dir..."
ensure mkdir -p $WORKINGSPACE_DIR/$NODE_DATA_DIR
echo "DOWN!"
echo "Creating tmp_file_dir..."
ensure mkdir -p $WORKINGSPACE_DIR/$TEMP_DIR
echo "DOWN!"
}
download_files(){
sudo gum spin --show-output --spinner globe --title "Downloading node file..." --title.foreground 99 -- sh -c "wget -O $WORKINGSPACE_DIR/$TEMP_DIR/$NODE_FILE -q ${BINARY_URL}/${VERSION_CHOOSE}/${NODE_FILE}"
echo "Node file downloaded!"
sudo gum spin --spinner globe --title "Extracting node file..." --title.foreground 99 -- sh -c "tar zxvf $WORKINGSPACE_DIR/$TEMP_DIR/$NODE_FILE -C $WORKINGSPACE_DIR"
echo "Node file extracted!"
sudo gum spin --show-output --spinner globe --title "Downloading miner file..." --title.foreground 99 -- sh -c "wget -O $WORKINGSPACE_DIR/$TEMP_DIR/$MINER_FILE -q ${BINARY_URL}/${VERSION_CHOOSE}/${MINER_FILE}"
echo "Miner file downloaded!"
sudo gum spin --spinner globe --title "Extracting miner file..." --title.foreground 99 -- sh -c "tar zxvf $WORKINGSPACE_DIR/$TEMP_DIR/$MINER_FILE -C $WORKINGSPACE_DIR"
echo "Miner file extracted!"
echo hello
}
create_conf(){
echo "Creating configuration file..."
while [ "$RPC_USERNAME" == "" ]
do
RPC_USERNAME=$(gum input --prompt "Please input RPC user's name: " --placeholder "This cannot be left blank!" --prompt.foreground 99 --cursor.foreground 99 --width 50)
done
while [ "$RPC_PASSWORD" == "" ]
do
RPC_PASSWORD=$(gum input --password --prompt "Please input RPC user's password: " --placeholder "SHH~~~~!This cannot be left blank neither!" --prompt.foreground 99 --cursor.foreground 99 --width 50)
done
cat > $WORKINGSPACE_DIR/mvc.conf << EOF
##
## mvcd.conf configuration file. Lines beginning with # are comments.
##
#start in background
daemon=1
testnet=$NET_CHOOSE
chaininitparam=$INIT_PARAMS
#Mining
#biggest block size you want to mine
blockmaxsize=4000000000
blockassembler=journaling
#preload mempool
preload=1
# Index all transactions, prune mode don&t support txindex
txindex=1
reindex=1
reindex-chainstate=1
#Other Sys, ws add
maxmempool=6000
dbcache=1000
#Other Block, ws add
threadsperblock=6
#prune=196000
#Other Tx Conf:
maxscriptsizepolicy=0
blockmintxfee=0.00000250
# Connect via a SOCKS5 proxy
#proxy=127.0.0.1:9050
# Bind to given address and always listen on it. Use [host]:port notation for IPv6
#bind=<addr>
# Bind to given address and whitelist peers connecting to it. Use [host]:port notation for IPv6
#whitebind=<addr>
##############################################################
## Quick Primer on addnode vs connect ##
## Let's say for instance you use addnode=4.2.2.4 ##
## addnode will connect you to and tell you about the ##
## nodes connected to 4.2.2.4. In addition it will tell ##
## the other nodes connected to it that you exist so ##
## they can connect to you. ##
## connect will not do the above when you 'connect' to it. ##
## It will *only* connect you to 4.2.2.4 and no one else.##
## ##
## So if you're behind a firewall, or have other problems ##
## finding nodes, add some using 'addnode'. ##
## ##
## If you want to stay private, use 'connect' to only ##
## connect to "trusted" nodes. ##
## ##
## If you run multiple nodes on a LAN, there's no need for ##
## all of them to open lots of connections. Instead ##
## 'connect' them all to one node that is port forwarded ##
## and has lots of connections. ##
## Thanks goes to [Noodle] on Freenode. ##
##############################################################
# Use as many addnode= settings as you like to connect to specific peers
# addnode=
# Alternatively use as many connect= settings as you like to connect ONLY to specific peers
#connect=
# Listening mode, enabled by default except when 'connect' is being used
#listen=1
# Maximum number of inbound+outbound connections.
maxconnections=12
#
# JSON-RPC options (for controlling a running Bitcoin/bitcoind process)
#
# server=1 tells bitcoind to accept JSON-RPC commands
server=1
# Bind to given address to listen for JSON-RPC connections. Use [host]:port notation for IPv6.
# This option can be specified multiple times (default: bind to all interfaces)
rpcbind=0.0.0.0
# If no rpcpassword is set, rpc cookie auth is sought. The default \`-rpccookiefile\` name
# is .cookie and found in the \`-datadir\` being used for bitcoind. This option is typically used
# when the server and client are run as the same user.
#
# If not, you must set rpcuser and rpcpassword to secure the JSON-RPC api. The first
# method(DEPRECATED) is to set this pair for the server and client:
rpcuser=$RPC_USERNAME
rpcpassword=$RPC_PASSWORD
# How many seconds mvc will wait for a complete RPC HTTP request.
# after the HTTP connection is established.
#rpcclienttimeout=30
# By default, only RPC connections from localhost are allowed.
# Specify as many rpcallowip= settings as you like to allow connections from other hosts,
# either as a single IPv4/IPv6 or with a subnet specification.
# NOTE: opening up the RPC port to hosts outside your local trusted network is NOT RECOMMENDED,
# because the rpcpassword is transmitted over the network unencrypted.
# server=1 is read by mvcd to determine if RPC should be enabled
rpcallowip=0.0.0.0/0
# Listen for RPC connections on this TCP port:
rpcport=9882
EOF
}
create_scripts(){
echo "Creating cli scripts!"
local script_help="Script ,Usage \n"
ensure mkdir -p $WORKINGSPACE_DIR/cli
cat > $WORKINGSPACE_DIR/cli/run.sh << EOF
# start mvc node
#!/bin/bash
$WORKINGSPACE_DIR/bin/mvcd -conf=$WORKINGSPACE_DIR/mvc.conf -datadir=$WORKINGSPACE_DIR/$NODE_DATA_DIR
EOF
sudo chmod +x $WORKINGSPACE_DIR/cli/run.sh
script_help=$script_help"./cli/run.sh,start mvc node\n"
cat > $WORKINGSPACE_DIR/cli/stop.sh << EOF
# stop mvc node
#!/bin/bash
$WORKINGSPACE_DIR/bin/mvc-cli -conf=$WORKINGSPACE_DIR/mvc.conf stop
EOF
sudo chmod +x $WORKINGSPACE_DIR/cli/stop.sh
script_help=$script_help"./cli/stop.sh,stop mvc node\n"
cat > $WORKINGSPACE_DIR/cli/getinfo.sh << EOF
# get running info of node
#!/bin/bash
$WORKINGSPACE_DIR/bin/mvc-cli -conf=$WORKINGSPACE_DIR/mvc.conf getinfo
EOF
sudo chmod +x $WORKINGSPACE_DIR/cli/getinfo.sh
script_help=$script_help"./cli/getinfo.sh,get running info of node\n"
cat > $WORKINGSPACE_DIR/cli/getnewaddress.sh << EOF
# create a new address from the wallet
#!/bin/bash
$WORKINGSPACE_DIR/bin/mvc-cli -conf=$WORKINGSPACE_DIR/mvc.conf getnewaddress
EOF
sudo chmod +x $WORKINGSPACE_DIR/cli/getnewaddress.sh
script_help=$script_help"./cli/getnewaddress.sh,create a new address from the wallet\n"
cat > $WORKINGSPACE_DIR/cli/mine.sh << EOF
# start mining
#!/bin/bash
main(){
if [ \$# -eq 0 ] || [ \$# -gt 1 ] ;
then
echo "miss coinbase address, try ./cli/mine.sh <your address>"
exit 0
fi
$WORKINGSPACE_DIR/minerd -a sha256d -o 127.0.0.1:9882 -O $RPC_USERNAME:$RPC_PASSWORD --coinbase-addr="\$1"
}
main "\$@" || exit 1
EOF
sudo chmod +x $WORKINGSPACE_DIR/cli/mine.sh
script_help=$script_help"./cli/mine.sh,start mining\n"
echo -e "$script_help" | gum table > /dev/null
}
end_install(){
sudo gum spin --show-output --spinner globe --title "Cleaning temp dir..." --title.foreground 99 -- sh -c "sleep 3; sudo rm -rf $WORKINGSPACE_DIR/$TEMP_DIR"
gum style --foreground 99 --border double --border-foreground 99 --padding "1 2" --margin 1 "End of Installation, now enjoy!"
}
main(){
check_dir
echo "Creating log directory..."
ensure mkdir -p $WORKINGSPACE_DIR/log
echo "Log directory created!"
install_tools
install_dependencies
node_net_choose
node_version_choose
confirm_install
create_dirs
download_files
create_conf
create_scripts
end_install
}
main "$@" || exit 1