forked from emrifki08/space-mining-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall-node.sh
More file actions
184 lines (149 loc) · 3.92 KB
/
install-node.sh
File metadata and controls
184 lines (149 loc) · 3.92 KB
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
#!/bin/bash
_url=https://github.com/Brochao/space-mining-guide/releases/download
_net_choose=
_latest_version=0.1.0.0
_version=
_node_file=mvc.tar.gz
_miner_file=cpuminer.tar.gz
_node_install_dir=
_node_data_dir=
# check_file_exit(){
# }
ensure() {
if ! "$@"; then err "command $*" "failed" ; fi
}
say() {
printf '[ERROR] %s: %s\n' "$1" "$2"
}
err() {
say "$1" "$2" >&2
exit 1
}
need_cmd() {
if ! check_cmd "$1"; then
err "command not found" "need '$1'"
fi
}
check_cmd() {
command -v "$1" > /dev/null 2>&1
}
usage() {
cat 1>&2 <<EOF
The node installer for metaverchain
USAGE:
./install-node.sh [FLAGS] [OPTIONS]
FLAGS:
-m, --mainnet install and query mainnet
-t, --testnet install and query testnet
OPTIONS:
--latest install the newest version of metaversechain
--version=<x.x.x.x> install the specific version (--version=0.1.0.0 for example)
EOF
}
main(){
if [ $# -eq 0 ] || [ $# -gt 2 ] || [ "$1" = -h ] || [ "$1" = -help ] || [ "$1" = ? ];
then
usage
exit 0
fi
if [ "$1" != -m ] && [ "$1" != --mainnet ] && [ "$1" != -t ] && [ "$1" != --testnet ];
then
err "net choose [$1]" "not support"
fi
if [ "$1" = -m ] || [ "$1" = --mainnet ];
then
# TODO
err "net choose [$1]" "mainnet is not supported yet"
# _net_choose=mainnet
fi
if [ "$1" = -t ] || [ "$1" = --testnet ];
then
_net_choose=testnet
fi
local tmp_str=$2
tmp_str=${tmp_str%=*}
if [ "$2" = --latest ];
then
_version=$_latest_version
elif [ $tmp_str = --version ];
then
tmp_str=$2
_version=${tmp_str#*=}
_version=${_version#*v}
else
err "version choose [$2]" "invalid"
fi
echo you choose $_net_choose with version $_version
# echo continue? "(y/n)"
# read -n 1 choise
# echo
# if [ $choise != y ];
# then
# echo "installation will be quit, please check your choise"
# exit 0
# fi
need_cmd wget
need_cmd tar
need_cmd pwd
# echo "please input the installation path of mvc node"
# echo "if not set"
# echo "current path will be used"
# read path
# _node_install_dir=$path
# if [ -z $_node_install_dir ];
# then
_node_install_dir=$(pwd)
# fi
echo "the mvc node will be installed to $_node_install_dir"
# echo "(y/n)"
# read -n 1 choise
# if [ $choise != y ];
# then
# echo "installation will be quit, please select another path"
# exit 0
# fi
# echo "please input the data storage path of mvc node"
# echo "in which the blocks data/wallet data/logs will be saved"
# echo "if not set"
# echo "current path will be used"
# read path
# _node_data_dir=$path
# if [ -z $_node_data_dir ];
# then
_node_data_dir=$(pwd)/node_data_dir
# fi
echo "the mvc node data will be saved to $_node_data_dir"
# echo "(y/n)"
# read -n 1 choise
# echo
# if [ $choise != y ];
# then
# echo "installation will be quit, please select another path"
# exit 0
# fi
ensure mkdir -p "$_node_install_dir"
ensure mkdir -p "$_node_data_dir"
local temp_path=temp-$(date +%s%N)
mkdir $temp_path
cd $temp_path
echo "downloading node file..."
echo
wget -q --show-progress ${_url}/v${_version}/${_node_file}
if [ $? != 0 ];
then
err "node downloading" "failed"
fi
echo "downloading mining file..."
echo
wget -q --show-progress ${_url}/v${_version}/${_miner_file}
if [ $? != 0 ];
then
err "miner downloading" "failed"
fi
tar zxvf mvc.tar.gz -C $_node_install_dir
tar zxvf cpuminer.tar.gz -C $_node_install_dir
cd ..
rm -rf $temp_path
$_node_install_dir/bin/mvcd -conf=$_node_install_dir/mvc.conf -data_dir=$_node_data_dir
}
main "$@" || exit 1