-
Notifications
You must be signed in to change notification settings - Fork 22
/
setup.sh
executable file
·271 lines (215 loc) · 9.55 KB
/
setup.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
#!/bin/bash
# VERSION
version='v4.5'
# FAST-SYNC DOWNLOAD LINK
ledgerDownloadLink='https://s3.us-east-2.amazonaws.com/repo.nano.org/snapshots/latest'
# OUTPUT VARS
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
bold=`tput bold`
reset=`tput sgr0`
# FLAGS & ARGUMENTS
quiet='false'
displaySeed='false'
fastSync='false'
domain=''
email=''
tag=''
while getopts 'sqfd:e:t:' flag; do
case "${flag}" in
s) displaySeed='true' ;;
d) domain="${OPTARG}" ;;
e) email="${OPTARG}" ;;
q) quiet='true' ;;
f) fastSync='true' ;;
t) tag="${OPTARG}" ;;
*) exit 1 ;;
esac
done
echo $@ > settings
# PRINT INSTALLER DETAILS
[[ $quiet = 'false' ]] && echo "${green} -----------------------${reset}"
[[ $quiet = 'false' ]] && echo "${green}${bold} NANO Node Docker ${version}${reset}"
[[ $quiet = 'false' ]] && echo "${green} -----------------------${reset}"
[[ $quiet = 'false' ]] && echo ""
# VERIFY TOOLS INSTALLATIONS
docker -v &> /dev/null
if [ $? -ne 0 ]; then
echo "${red}Docker is not installed. Please follow the install instructions for your system at https://docs.docker.com/install/.${reset}";
exit 2
fi
docker compose version &> /dev/null
if [ $? -ne 0 ]; then
echo "${red}Docker Compose is not installed. Please follow the install instructions for your system at https://docs.docker.com/compose/install/.${reset}"
exit 2
fi
if [[ $tag == '' ]]; then
echo "${yellow}Nano node image tag is now required. Please set the -t argument explicitly to the version you are willing to install (https://hub.docker.com/r/nanocurrency/nano/tags).${reset}"
exit 2
fi
if [[ $fastSync = 'true' ]]; then
wget --version &> /dev/null
if [ $? -ne 0 ]; then
echo "${red}wget is not installed and is required for fast-syncing.${reset}";
exit 2
fi
7z &> /dev/null
if [ $? -ne 0 ]; then
echo "${red}7-Zip is not installed and is required for fast-syncing.${reset}";
exit 2
fi
fi
# FAST-SYNCING
if [[ $fastSync = 'true' ]]; then
if [[ $quiet = 'false' ]]; then
printf "=> ${yellow}Downloading latest ledger files for fast-syncing...${reset}\n"
wget -O todaysledger.7z -i ${ledgerDownloadLink} -q --show-progress
printf "=> ${yellow}Unzipping and placing the files (takes a while)...${reset} "
7z x todaysledger.7z -o./nano-node/Nano -y &> /dev/null
rm todaysledger.7z
printf "${green}done.${reset}\n"
echo ""
else
wget -O todaysledger.7z -i ${ledgerDownloadLink} -q
docker-compose stop nano-node &> /dev/null
7z x todaysledger.7z -o./nano-node/Nano -y &> /dev/null
rm todaysledger.7z
fi
fi
# DETERMINE IF THIS IS AN INITIAL INSTALL
[[ $quiet = 'false' ]] && echo "=> ${yellow}Checking initial status...${reset}"
[[ $quiet = 'false' ]] && echo ""
# check if node mounted directory exists
if [ -d "./nano-node" ]; then
# check if mounted directory follows the new /root structure
if [ ! -d "./nano-node/RaiBlocks" ]; then
if [ ! -d "./nano-node/Nano" ]; then
[[ $quiet = 'false' ]] && printf "${reset}Unsupported directory structure detected. Migrating files... "
mkdir ./nano-node/RaiBlocks
# move everything into subdirectory and suppress the error about itself
mv ./nano-node/* ./nano-node/RaiBlocks/ &> /dev/null
[[ $quiet = 'false' ]] && printf "${green}done.\n${reset}"
[[ $quiet = 'false' ]] && echo ""
fi
fi
fi
# SPIN UP THE APPROPRIATE STACK
[[ $quiet = 'false' ]] && echo "=> ${yellow}Pulling images and spinning up containers...${reset}"
[[ $quiet = 'false' ]] && echo ""
docker network create nano-node-network &> /dev/null
if [[ $domain ]]; then
if [[ $tag ]]; then
sed -i -e "s/ image: nanocurrency\/nano:.*/ image: nanocurrency\/nano:$tag/g" compose.letsencrypt.yaml
fi
sed -i -e "s/ - VIRTUAL_HOST=.*/ - VIRTUAL_HOST=$domain/g" compose.letsencrypt.yaml
sed -i -e "s/ - LETSENCRYPT_HOST=.*/ - LETSENCRYPT_HOST=$domain/g" compose.letsencrypt.yaml
sed -i -e "s/ - DEFAULT_HOST=.*/ - DEFAULT_HOST=$domain/g" compose.letsencrypt.yaml
if [[ $email ]]; then
sed -i -e "s/ - LETSENCRYPT_EMAIL=.*/ - LETSENCRYPT_EMAIL=$email/g" compose.letsencrypt.yaml
fi
if [[ $quiet = 'false' ]]; then
docker compose -f compose.letsencrypt.yaml up -d
else
docker compose -f compose.letsencrypt.yaml up -d &> /dev/null
fi
else
if [[ $tag ]]; then
sed -i -e "s/ image: nanocurrency\/nano:.*/ image: nanocurrency\/nano:$tag/g" compose.yaml
fi
if [[ $quiet = 'false' ]]; then
docker compose up -d
else
docker compose up -d &> /dev/null
fi
fi
if [ $? -ne 0 ]; then
echo "${red}It seems errors were encountered while spinning up the containers. Scroll up for more info on how to fix them.${reset}"
exit 2
fi
# CHECK NODE INITIALIZATION
[[ $quiet = 'false' ]] && echo ""
[[ $quiet = 'false' ]] && printf "=> ${yellow}Waiting for NANO node to fully initialize... "
isRpcLive="$(curl -s -d '{"action": "version"}' [::1]:7076 | grep "rpc_version")"
while [ ! -n "$isRpcLive" ];
do
sleep 1s
isRpcLive="$(curl -s -d '{"action": "version"}' [::1]:7076 | grep "rpc_version")"
done
[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n\n"
# DETERMINE NODE VERSION
nodeExec="docker exec -it nano-node /usr/bin/nano_node"
# SET BASH ALIASES FOR NODE CLI
if [ -f ~/.bash_aliases ]; then
alias=$(cat ~/.bash_aliases | grep 'nano-node');
if [[ ! $alias ]]; then
echo "alias nano-node='${nodeExec}'" >> ~/.bash_aliases;
source ~/.bashrc;
fi
else
echo "alias nano-node='${nodeExec}'" >> ~/.bash_aliases;
source ~/.bashrc;
fi
# WALLET SETUP
existedWallet="$(${nodeExec} --wallet_list | grep 'Wallet ID' | awk '{ print $NF}')"
if [[ ! $existedWallet ]]; then
[[ $quiet = 'false' ]] && printf "=> ${yellow}No wallet found. Generating a new one... ${reset}"
walletId=$(${nodeExec} --wallet_create | tr -d '\r')
address="$(${nodeExec} --account_create --wallet=$walletId | awk '{ print $NF}')"
[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n\n"
else
[[ $quiet = 'false' ]] && echo "=> ${yellow}Existing wallet found.${reset}"
[[ $quiet = 'false' ]] && echo ''
address="$(${nodeExec} --wallet_list | grep 'nano_' | awk '{ print $NF}' | tr -d '\r')"
walletId=$(echo $existedWallet | tr -d '\r')
fi
if [[ $quiet = 'false' && $displaySeed = 'true' ]]; then
seed=$(${nodeExec} --wallet_decrypt_unsafe --wallet=$walletId | grep 'Seed' | awk '{ print $NF}' | tr -d '\r')
fi
# UPDATE MONITOR CONFIGS
if [ ! -f ./nano-node-monitor/config.php ]; then
[[ $quiet = 'false' ]] && echo "=> ${yellow}No existing NANO Node Monitor config file found. Fetching a fresh copy...${reset}"
if [[ $quiet = 'false' ]]; then
docker-compose restart nano-node-monitor
else
docker-compose restart nano-node-monitor > /dev/null
fi
fi
[[ $quiet = 'false' ]] && printf "=> ${yellow}Configuring NANO Node Monitor... ${reset}"
sed -i -e "s/\/\/ \$nanoNodeRPCIP.*;/\$nanoNodeRPCIP/g" ./nano-node-monitor/config.php
sed -i -e "s/\$nanoNodeRPCIP.*/\$nanoNodeRPCIP = 'nano-node';/g" ./nano-node-monitor/config.php
sed -i -e "s/\/\/ \$nanoNodeAccount.*;/\$nanoNodeAccount/g" ./nano-node-monitor/config.php
sed -i -e "s/\$nanoNodeAccount.*/\$nanoNodeAccount = '$address';/g" ./nano-node-monitor/config.php
if [[ $domain ]]; then
sed -i -e "s/\/\/ \$nanoNodeName.*;/\$nanoNodeName = '$domain';/g" ./nano-node-monitor/config.php
else
ipAddress=$(curl -s v4.ifconfig.co | awk '{ print $NF}' | tr -d '\r')
# in case of an ipv6 address, add square brackets
if [[ $ipAddress =~ .*:.* ]]; then
ipAddress="[$ipAddress]"
fi
sed -i -e "s/\/\/ \$nanoNodeName.*;/\$nanoNodeName = 'nano-node-docker-$ipAddress';/g" ./nano-node-monitor/config.php
fi
sed -i -e "s/\/\/ \$welcomeMsg.*;/\$welcomeMsg = 'Welcome! This node was setup using <a href=\"https:\/\/github.com\/lephleg\/nano-node-docker\" target=\"_blank\">NANO Node Docker<\/a>!';/g" ./nano-node-monitor/config.php
sed -i -e "s/\/\/ \$blockExplorer.*;/\$blockExplorer = 'meltingice';/g" ./nano-node-monitor/config.php
# remove any carriage returns may have been included by sed replacements
sed -i -e 's/\r//g' ./nano-node-monitor/config.php
[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n\n"
if [[ $quiet = 'false' ]]; then
echo "${yellow} |=========================================================================================| ${reset}"
echo "${yellow} | ${green}${bold}Congratulations! NANO Node Docker has been setup successfully! ${yellow}| ${reset}"
echo "${yellow} |=========================================================================================| ${reset}"
echo "${yellow} | Node account address: ${green}$address${yellow} | ${reset}"
if [[ $displaySeed = 'true' ]]; then
echo "${yellow} | Node wallet seed: ${red}$seed${yellow} | ${reset}"
fi
echo "${yellow} |=========================================================================================| ${reset}"
echo ""
if [[ $domain ]]; then
echo "${yellow} Open a browser and navigate to ${green}https://$domain${yellow} to check your monitor."
else
echo "${yellow} Open a browser and navigate to ${green}http://$ipAddress${yellow} to check your monitor."
fi
echo "${yellow} You can further configure and personalize your monitor by editing the config file located in ${green}nano-node-monitor/config.php${yellow}.${reset}"
echo ""
fi