-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.sh
executable file
·392 lines (328 loc) · 11.4 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
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
#!/bin/bash
####################ORIGINAL#####################
# NANO Node Docker #
# https://github.com/lephleg/nano-node-docker #
#################################################
######################FORK#######################
# Modified by @nano2dev #
# https://github.com/fwd/nano-docker #
#################################################
# VERSION
version='1.1'
# OUTPUT VARS
red=`tput setaf 1`
green=`tput setaf 2`
yellow=`tput setaf 3`
bold=`tput bold`
reset=`tput sgr0`
# Initialize default values
displaySeed='false'
quiet='false'
fastSync='false'
monitor='false'
port=''
tag=''
# Iterate over the input arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-s)
displaySeed='true'
;;
-q)
quiet='true'
;;
-f)
fastSync='true'
;;
-m)
monitor='true'
;;
-p)
shift
port="$1"
;;
-t)
shift
tag="$1"
;;
-v)
shift
tag="$1"
;;
esac
shift
done
# PRINT INSTALLER DETAILS
if [[ $quiet = 'false' ]]; then
echo ""
echo "${green}================================${reset}"
echo "${green}${bold}1-CLICK NANO NODE${reset}"
echo "${green}================================${reset}"
echo "${green}${bold}github.com/fwd/nano-docker${reset}"
echo "${green}============================${reset}"
fi
sleep 1
# JQ used right below
if ! command -v jq &> /dev/null; then
if [ -n "$(uname -a | grep Ubuntu)" ]; then
echo "${CYAN}JQ:${NC}: Installing."
sudo apt install jq -y
else
echo "${CYAN}Error${NC}: Could not auto install 'jq'. Please install it manually, then run ./setup.sh again."
exit 1
fi
fi
if [[ -z $port ]]; then port='80'; fi
## Prone to get Rate limited by Github
## TODO fix this
latest=$(curl -s https://api.github.com/repos/nanocurrency/nano-node/releases/latest -s | jq .name -r)
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo ""
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo "Operating system not supported."
exit 1
# Mac OSX
elif [[ "$OSTYPE" == "cygwin" ]]; then
echo "Operating system not supported."
exit 1
# POSIX compatibility layer and Linux environment emulation for Windows
elif [[ "$OSTYPE" == "msys" ]]; then
echo "Operating system not supported."
exit 1
# Lightweight shell and GNU utilities compiled for Windows (part of MinGW)
elif [[ "$OSTYPE" == "win32" ]]; then
# I'm not sure this can happen.
echo "Operating system not supported."
exit 1
elif [[ "$OSTYPE" == "freebsd"* ]]; then
# ...
echo "Operating system not supported."
exit 1
else
# Unknown.
echo "Operating system not supported."
exit 1
fi
DEFAULT_COMPOSE=$(cat <<EOF
version: '3'
services:
nano-node:
image: nanocurrency/nano:latest
container_name: nano-node
hostname: nano-node
environment:
- TERM=xterm
restart: unless-stopped
ports:
- "7075:7075/udp"
- "7075:7075"
- "::1:7076:7076"
- "::1:7078:7078"
volumes:
- ./nano-node:/root
watchtower:
image: v2tec/watchtower
container_name: watchtower
restart: unless-stopped
command: watchtower nano-node nano-node-monitor
volumes:
- /var/run/docker.sock:/var/run/docker.sock
EOF
)
DOCKER_MONITOR_COMPOSE=$(cat <<EOF
nano-node-monitor:
image: nanotools/nanonodemonitor
container_name: nano-node-monitor
hostname: nano-node-monitor
restart: unless-stopped
volumes:
- ./nano-node-monitor:/opt/nanoNodeMonitor
ports:
- "${port}:80"
EOF
)
if [ $monitor == "true" ] || [ -f ./nano-node-monitor/config.php ]; then
FINAL_COMPOSE_FILE=$(cat <<EOF
${DEFAULT_COMPOSE}
${DOCKER_MONITOR_COMPOSE}
EOF
)
else
FINAL_COMPOSE_FILE=$(cat <<EOF
${DEFAULT_COMPOSE}
EOF
)
fi
cat > docker-compose.yml <<EOF
$FINAL_COMPOSE_FILE
EOF
# VERIFY TOOLS INSTALLATIONS
docker -v &> /dev/null
if [ $? -ne 0 ]; then
# Docs: https://docs.docker.com/engine/install/ubuntu
echo "Installing Docker..."
# Basics
sudo apt-get -y install curl p7zip-full
# PGP Key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Set up Docker Repo
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get -y install jq docker-ce docker-ce-cli containerd.io
fi
docker-compose --version &> /dev/null
if [ $? -ne 0 ]; then
echo "Installing Docker Compose..."
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
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
# FAST-SYNC DOWNLOAD LINK
# BIG THANKS TO @ThiagoSFS
ledgerDownloadLink=$(curl -s 'https://s3.us-east-2.amazonaws.com/repo.nano.org/snapshots/latest')
if [[ $quiet = 'false' ]]; then
printf "=> ${yellow}Downloading latest ledger files...${reset}\n"
wget -O todaysledger.7z ${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"
else
wget -O todaysledger.7z ${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 status...${reset}"
[[ $quiet = 'false' ]] && echo ""
# check if node mounted directory exists
if [ -d "./nano-node" ]; then
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
mv ./nano-node/* ./nano-node/RaiBlocks/ &> /dev/null
[[ $quiet = 'false' ]] && printf "${green}done.\n${reset}"
[[ $quiet = 'false' ]] && echo ""
fi
fi
fi
if [[ $tag ]]; then
sed -i -e "s/ image: nanocurrency\/nano:.*/ image: nanocurrency\/nano:$tag/g" docker-compose.yml
fi
if [[ $quiet = 'false' ]]; then
docker-compose up --remove-orphans -d
else
docker-compose up --remove-orphans -d &> /dev/null
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
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
nodeExec="docker exec -it nano-node /usr/bin/nano_node"
# WALLET SETUP
sed -i 's/enable_control = false/enable_control = true/g' ./nano-node/Nano/config-rpc.toml
existedWallet="$(${nodeExec} --wallet_list | grep 'Wallet ID' | awk '{ print $NF}')"
if [[ ! $existedWallet ]]; then
walletId=$(${nodeExec} --wallet_create | tr -d '\r')
sleep 1
address="$(${nodeExec} --account_create --wallet=$walletId | awk '{ print $NF}')"
sleep 1
[[ $quiet = 'false' ]] && printf "${green}done.${reset}\n\n"
else
address="$(${nodeExec} --wallet_list | grep 'nano_' | awk '{ print $NF}' | tr -d '\r')"
sleep 1
walletId=$(echo $existedWallet | tr -d '\r')
fi
sleep 1
if [[ $quiet = 'false' && $displaySeed = 'true' ]]; then
seed=$(${nodeExec} --wallet_decrypt_unsafe --wallet=$walletId | grep 'Seed' | awk '{ print $NF}' | tr -d '\r')
fi
if [ $monitor = 'true' ]; then
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
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
ipAddress=$(dig @resolver4.opendns.com myip.opendns.com +short -4)
if [[ $ipAddress =~ .*:.* ]]; then
ipAddress="[$ipAddress]"
fi
sed -i -e "s/\/\/ \$nanoNodeName.*;/\$nanoNodeName = 'nano-docker-$ipAddress';/g" ./nano-node-monitor/config.php
sed -i -e "s/\/\/ \$welcomeMsg.*;/\$welcomeMsg = 'Welcome! This node was setup using <a href=\"https:\/\/github.com\/fwd\/nano-docker\" target=\"_blank\">Nano Docker<\/a>!';/g" ./nano-node-monitor/config.php
sed -i -e "s/\/\/ \$blockExplorer.*;/\$blockExplorer = 'meltingice';/g" ./nano-node-monitor/config.php
sed -i -e 's/\r//g' ./nano-node-monitor/config.php
fi
if [[ "$quiet" = "false" ]]; then
echo "=========================================="
echo " ${green}Welcome to the Nano Blockchain${reset} "
echo "=========================================="
if [[ $monitor == 'false' ]]; then
echo " http://$(hostname -I | cut -d' ' -f3):7676 or [::1]:7076 "
# echo "=========================================="
else
echo "=========================================="
echo " http://$(dig @resolver4.opendns.com myip.opendns.com +short -4):$port or [::1]:$port "
# echo "=========================================="
fi
if [[ $displaySeed = 'true' ]]; then
echo "=================${yellow}SECRET${reset}==================="
echo "${green}PUBLIC:${reset} $address"
echo "${red}SECRET:${reset} $seed"
echo "==============KEEP THIS SAFE=============="
else
echo "=================SECRET==================="
echo "Use './setup.sh -s' to get private key. "
echo "=========================================="
fi
if [[ $displaySeed = 'false' ]]; then
cat <<EOF
${yellow}Node CLI:${reset}
$ nano-node --help
Note: You might need to: source ~/.bash_aliases
${yellow}Node RPC:${reset}
$ curl -g -d '{ "action": "telemetry" }' '[::1]:7076'
${green}Documentation:${reset} https://docs.nano.org/commands/rpc-protocol
EOF
fi
fi
if [ -f ~/.bash_aliases ]; then
alias=$(cat ~/.bash_aliases | grep 'nano-node');
if [[ ! $alias ]]; then
echo "alias nano-node='${nodeExec}'" >> ~/.bash_aliases;
fi
else
echo "alias nano-node='${nodeExec}'" >> ~/.bash_aliases;
fi
exit 1