-
Notifications
You must be signed in to change notification settings - Fork 13
/
installkronos.sh
560 lines (384 loc) · 17.9 KB
/
installkronos.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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
#!/bin/bash
VERSION='v2.0.8-Beta'
TEMP=/tmp/answer$$
whiptail --title "Kronos ${VERSION} for Denarius" --menu "Installer for Kronos Secondary Layer :" 20 0 0 1 "Install Kronos w/ Denarius Config" 2 "Install Kronos w/ Denarius Config & Chaindata" 3 "Update & Upgrade Kronos ${VERSION}" 2>$TEMP
choice=`cat $TEMP`
case $choice in
1) echo 1 "Installer for Kronos"
#COLORS
BLUE='\033[0;34m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# License Kronos Installer
#
#The MIT License (MIT)
#
#Copyright (c) 2020 MetaSpartan
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#FUNCTIONS
#
# Show a progress bar for $1 seconds
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Example: progress_bar 60
#
progress_bar()
{
local DURATION=$1
local INT=0.25 # refresh interval
local TIME=0
local CURLEN=0
local SECS=0
local FRACTION=0
local FB=2588 # full block
trap "echo -e $(tput cnorm); trap - SIGINT; return" SIGINT
echo -ne "$(tput civis)\r$(tput el)│" # clean line
local START=$( date +%s%N )
while [ $SECS -lt $DURATION ]; do
local COLS=$( tput cols )
# main bar
local L=$( bc -l <<< "( ( $COLS - 5 ) * $TIME ) / ($DURATION-$INT)" | awk '{ printf "%f", $0 }' )
local N=$( bc -l <<< $L | awk '{ printf "%d", $0 }' )
[ $FRACTION -ne 0 ] && echo -ne "$( tput cub 1 )" # erase partial block
if [ $N -gt $CURLEN ]; then
for i in $( seq 1 $(( N - CURLEN )) ); do
echo -ne \\u$FB
done
CURLEN=$N
fi
# partial block adjustment
FRACTION=$( bc -l <<< "( $L - $N ) * 8" | awk '{ printf "%.0f", $0 }' )
if [ $FRACTION -ne 0 ]; then
local PB=$( printf %x $(( 0x258F - FRACTION + 1 )) )
echo -ne \\u$PB
fi
# percentage progress
local PROGRESS=$( bc -l <<< "( 100 * $TIME ) / ($DURATION-$INT)" | awk '{ printf "%.0f", $0 }' )
echo -ne "$( tput sc )" # save pos
echo -ne "\r$( tput cuf $(( COLS - 6 )) )" # move cur
echo -ne "│ $PROGRESS%"
echo -ne "$( tput rc )" # restore pos
TIME=$( bc -l <<< "$TIME + $INT" | awk '{ printf "%f", $0 }' )
SECS=$( bc -l <<< $TIME | awk '{ printf "%d", $0 }' )
# take into account loop execution time
local END=$( date +%s%N )
local DELTA=$( bc -l <<< "$INT - ( $END - $START )/1000000000" \
| awk '{ if ( $0 > 0 ) printf "%f", $0; else print "0" }' )
sleep $DELTA
START=$( date +%s%N )
done
echo $(tput cnorm)
trap - SIGINT
}
# printf " ${GREEN}_ ____ ${NC}${RED} _ ${NC}\n"
# printf " "${GREEN}"__| | _ ${NC}${RED}(_) ${NC}\n"
# printf " ${GREEN}/ _ | |_) | |${NC}\n"
# printf " ${GREEN}| (_| | __/| |${NC}\n"
# printf " ${GREEN}\__._|_| |_|${NC}\n"
# printf "3333333333333333333333333333333333333333333333333\n"
# printf "333333ddd${GREEN}--------${NC}dd33333333333dd${GREEN}--------${NC}ddd333333\n"
# printf "3333${GREEN}-................${NC}d33333d${GREEN}................-${NC}3333\n"
# printf "3333${GREEN}-.................-${NC}333d${GREEN}..................${NC}3333\n"
# printf "3333d${GREEN}..................${NC}d33${GREEN}..................-${NC}3333\n"
# printf "33333${GREEN}-..........---....${NC}333${GREEN}....---..........-${NC}33333\n"
# printf "333333${GREEN}-............-${NC}d-33333dd${GREEN}-............-${NC}333333\n"
# printf "33333333${GREEN}-..........-${NC}333333333${GREEN}-..........-${NC}33333333\n"
# printf "3333333333${GREEN}---...--${NC}d33333333333d${GREEN}--....--${NC}3333333333\n"
# printf "333333333333333333dddd---d--dd3333333333333333333\n"
# printf "33333333333333d-------d--d--------333333333333333\n"
# printf "333333333333--------........---------333333333333\n"
# printf "3333333333----d-..--${RED}d3333333dd${NC}--.-d----3333333333\n"
# printf "33333333d--dd-.-${RED}d333333333333333d${NC}-..d---d33333333\n"
# printf "3333333d--d-.-${RED}33d${NC}--..--------${RED}d33333${NC}-.-d--d3333333\n"
# printf "333333d--d-.-${RED}33333${NC}-..${RED}d3333d${NC}-...-${RED}3333d${NC}.-d--d333333\n"
# printf "333333----.-${RED}333333${NC}-..${RED}d3333333${NC}-..-${RED}3333${NC}-.----333333\n"
# printf "333333--3-.${RED}3333333${NC}-..${RED}d33333333${NC}...${RED}d3333${NC}.-3--333333\n"
# printf "33333d--3..${RED}3333333${NC}-..${RED}d33333333${NC}...${RED}d3333${NC}..3--333333\n"
# printf "333333--d-.${RED}d333333${NC}-..${RED}d33333333${NC}...${RED}3333d${NC}.-d--333333\n"
# printf "333333---d.-${RED}333333${NC}-..${RED}d333333d${NC}...${RED}d3333${NC}-.d---333333\n"
# printf "3333333--d-.-${RED}33333${NC}-..-${RED}dddd${NC}-...-${RED}33333${NC}-.-d--3333333\n"
# printf "3333333d--dd..${RED}d3d${NC}----------${RED}d333333d${NC}..d---33333333\n"
# printf "333333333---d-.--${RED}333333333333333${NC}--.-d---333333333\n"
# printf "3333333333d---d--..--${RED}ddddddd${NC}---.--d---d3333333333\n"
# printf "3333333333333-----------------------d333333333333\n"
# printf "333333333333333dd----------------3333333333333333\n"
# printf "333333333333333333333ddddddd333333333333333333333\n"
# printf "3333333333333333333333333333333333333333333333333\n\n"
printf " _ _______ _______ _ _______ _______ \n"
printf "| \ /\( ____ )( ___ )( ( /|( ___ )( ____ \\n"
printf "| \ / /| ( )|| ( ) || \ ( || ( ) || ( \/\n"
printf "| (_/ / | (____)|| | | || \ | || | | || (_____ \n"
printf "| _ ( | __)| | | || (\ \) || | | |(_____ )\n"
printf "| ( \ \ | (\ ( | | | || | \ || | | | ) |\n"
printf "| / \ \| ) \ \__| (___) || ) \ || (___) |/\____) |\n"
printf "|_/ \/|/ \__/(_______)|/ )_)(_______)\_______)\n"
printf "Version ${VERSION}\n\n"
progress_bar 3
printf "${GREEN}Installing Kronos, Denarius, and related dependancies${NC}\n"
lsof /var/lib/dpkg/lock >/dev/null 2>&1
[ $? = 0 ] && echo "dpkg is currently locked, cannot install Kronos...Please ensure you are not running software updates"
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y git unzip build-essential libssl-dev autogen automake curl wget jq snap snapd pwgen
sudo apt-get remove -y nodejs npm
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
mkdir -p ~/Kronos/DATA/storage
mkdir -p ~/Kronos/DATA/kronosleveldb
printf "${GREEN}Dependancies Installed Successfully!${NC}\n"
printf "${GREEN}Successfully Installed Node Version 12.x from NodeSource!${NC}\n"
printf "${GREEN}Snap installing Denarius...${NC}\n"
sudo snap install denarius
denarius.daemon stop
printf "${GREEN}This will take 30 seconds...${NC}\n"
progress_bar 30
#Generate random rpcuser and rpcpass for injection
PWUD1=$(pwgen 13 1)
PWPD2=$(pwgen 33 1)
PWPD3=$(pwgen 50 1)
echo "Generated random username and password..."
#Update denarius.conf to match env credentials
touch ~/snap/denarius/common/.denarius/denarius.conf
sed -i "s/.*rpcuser=.*/rpcuser="${PWUD1}"/" ~/snap/denarius/common/.denarius/denarius.conf
sed -i "s/.*rpcpassword=.*/rpcpassword="${PWPD2}"/" ~/snap/denarius/common/.denarius/denarius.conf
if [ ! -f ~/snap/denarius/common/.denarius/walletnotify.sh ]; then
touch ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a #!/bin/sh' ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a curl http://127.0.0.1:3000/walletnotify -d "txid=$@"' ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a walletnotify=curl http://127.0.0.1:3000/walletnotify -d "txid=%s"' ~/snap/denarius/common/.denarius/denarius.conf
fi
echo "Injected newly generated username and password..."
echo "Starting Denarius"
denarius.daemon
progress_bar 20
echo "Installing Kronos from Github"
if [ -d "kronos" ]; then
sudo rm -rf kronos
fi
git clone https://github.com/metaspartan/kronos
cd kronos
echo "Installing Kronos Node Modules..."
sudo su
npm install
cd node_modules/node-pty-prebuilt-multiarch
node-gyp configure
node-gyp build
cd ..
cd ..
echo "Successfully Installed Kronos Node Modules"
echo "Updating Enviroment..."
nohup npm run headless &
echo "Kronos and Denarius are successfully installed! Kronos is now running on port 3000, open your browser to this devices local LAN IP, e.g. 192.168.x.x:3000"
;;
2) echo 2 "Installer for Kronos with fast chain sync"
#COLORS
BLUE='\033[0;34m'
CYAN='\033[0;36m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# License Kronos Installer
#
# This script is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this script; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place, Suite 330,
# Boston, MA 02111-1307 USA
#FUNCTIONS
# Show a progress bar for $1 seconds
#
# Copyleft 2017 by Ignacio Nunez Hernanz <nacho _a_t_ ownyourbits _d_o_t_ com>
# GPL licensed (see end of file) * Use at your own risk!
#
# Example: progress_bar 60
#
progress_bar()
{
local DURATION=$1
local INT=0.25 # refresh interval
local TIME=0
local CURLEN=0
local SECS=0
local FRACTION=0
local FB=2588 # full block
trap "echo -e $(tput cnorm); trap - SIGINT; return" SIGINT
echo -ne "$(tput civis)\r$(tput el)│" # clean line
local START=$( date +%s%N )
while [ $SECS -lt $DURATION ]; do
local COLS=$( tput cols )
# main bar
local L=$( bc -l <<< "( ( $COLS - 5 ) * $TIME ) / ($DURATION-$INT)" | awk '{ printf "%f", $0 }' )
local N=$( bc -l <<< $L | awk '{ printf "%d", $0 }' )
[ $FRACTION -ne 0 ] && echo -ne "$( tput cub 1 )" # erase partial block
if [ $N -gt $CURLEN ]; then
for i in $( seq 1 $(( N - CURLEN )) ); do
echo -ne \\u$FB
done
CURLEN=$N
fi
# partial block adjustment
FRACTION=$( bc -l <<< "( $L - $N ) * 8" | awk '{ printf "%.0f", $0 }' )
if [ $FRACTION -ne 0 ]; then
local PB=$( printf %x $(( 0x258F - FRACTION + 1 )) )
echo -ne \\u$PB
fi
# percentage progress
local PROGRESS=$( bc -l <<< "( 100 * $TIME ) / ($DURATION-$INT)" | awk '{ printf "%.0f", $0 }' )
echo -ne "$( tput sc )" # save pos
echo -ne "\r$( tput cuf $(( COLS - 6 )) )" # move cur
echo -ne "│ $PROGRESS%"
echo -ne "$( tput rc )" # restore pos
TIME=$( bc -l <<< "$TIME + $INT" | awk '{ printf "%f", $0 }' )
SECS=$( bc -l <<< $TIME | awk '{ printf "%d", $0 }' )
# take into account loop execution time
local END=$( date +%s%N )
local DELTA=$( bc -l <<< "$INT - ( $END - $START )/1000000000" \
| awk '{ if ( $0 > 0 ) printf "%f", $0; else print "0" }' )
sleep $DELTA
START=$( date +%s%N )
done
echo $(tput cnorm)
trap - SIGINT
}
printf " _ _______ _______ _ _______ _______ \n"
printf "| \ /\( ____ )( ___ )( ( /|( ___ )( ____ \\n"
printf "| \ / /| ( )|| ( ) || \ ( || ( ) || ( \/\n"
printf "| (_/ / | (____)|| | | || \ | || | | || (_____ \n"
printf "| _ ( | __)| | | || (\ \) || | | |(_____ )\n"
printf "| ( \ \ | (\ ( | | | || | \ || | | | ) |\n"
printf "| / \ \| ) \ \__| (___) || ) \ || (___) |/\____) |\n"
printf "|_/ \/|/ \__/(_______)|/ )_)(_______)\_______)\n"
printf "Version ${VERSION}\n\n"
progress_bar 3
printf "${GREEN}Installing Kronos, Denarius, and related dependancies${NC}\n"
lsof /var/lib/dpkg/lock >/dev/null 2>&1
[ $? = 0 ] && echo "dpkg is currently locked, cannot install Kronos...Please ensure you are not running software updates"
sudo apt-get update -y && sudo apt-get upgrade -y
sudo apt-get install -y git unzip build-essential libssl-dev autogen automake curl wget jq snap snapd pwgen
sudo apt-get remove -y nodejs npm
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y
mkdir -p ~/Kronos/DATA/storage
mkdir -p ~/Kronos/DATA/kronosleveldb
printf "${GREEN}Dependancies Installed Successfully!${NC}\n"
printf "${GREEN}Successfully Installed Node Version 12.x from NodeSource!${NC}\n"
printf "${GREEN}Snap installing Denarius...${NC}\n"
sudo snap install denarius
denarius.daemon stop
printf "${GREEN}This will take 30 seconds...${NC}\n"
progress_bar 30
#Generate random rpcuser and rpcpass for injection
PWUD1=$(pwgen 13 1)
PWPD2=$(pwgen 33 1)
PWPD3=$(pwgen 50 1)
echo "Generated random username and password..."
#Update denarius.conf to match env credentials
mkdir -p ~/snap/denarius/common/.denarius/
echo "Downloading and unzipping Denarius chaindata..."
architecture=""
case $(uname -m) in
i386) architecture="386" ;;
i686) architecture="386" ;;
x86_64) architecture="amd64" ;;
aarch64) architecture="aarch64" ;;
arm*) dpkg --print-architecture | grep -q "arm64" && architecture="arm64" || architecture="arm" ;;
esac
echo ${architecture}
if [ ${architecture} == "arm" ] || [ ${architecture} == "arm64" ]|| [ ${architecture} == "aarch64" ]; then
cd ~/snap/denarius/common/.denarius
wget https://denarii.cloud/pichaindata.zip
unzip pichaindata.zip
else
cd ~/snap/denarius/common/.denarius
wget https://denarii.cloud/chaindata.zip
unzip chaindata.zip
fi
cd ~
touch ~/snap/denarius/common/.denarius/denarius.conf
sed -i "s/.*rpcuser=.*/rpcuser="${PWUD1}"/" ~/snap/denarius/common/.denarius/denarius.conf
sed -i "s/.*rpcpassword=.*/rpcpassword="${PWPD2}"/" ~/snap/denarius/common/.denarius/denarius.conf
if [ ! -f ~/snap/denarius/common/.denarius/walletnotify.sh ]; then
touch ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a #!/bin/sh' ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a curl http://127.0.0.1:3000/walletnotify -d "txid=$@"' ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a walletnotify=curl http://127.0.0.1:3000/walletnotify -d "txid=%s"' ~/snap/denarius/common/.denarius/denarius.conf
fi
echo "Injected newly generated username and password..."
echo "Starting Denarius"
denarius.daemon
progress_bar 20
echo "Installing Kronos from Github"
if [ -d "kronos" ]; then
sudo rm -rf kronos
fi
git clone https://github.com/metaspartan/kronos
cd kronos
echo "Installing Kronos Node Modules..."
sudo su
npm install
cd node_modules/node-pty-prebuilt-multiarch
node-gyp configure
node-gyp build
cd ..
cd ..
echo "Successfully Installed Kronos Node Modules"
echo "Updating Enviroment..."
nohup npm run headless &
echo "Kronos and Denarius are successfully installed! Kronos is now running on port 3000, open your browser to this devices local LAN IP, e.g. 192.168.x.x:3000"
;;
3) echo 3 "Update Kronos ${VERSION} for Denarius"
echo "Updating in progress...This is a work in progress"
printf " _ _______ _______ _ _______ _______ \n"
printf "| \ /\( ____ )( ___ )( ( /|( ___ )( ____ \\n"
printf "| \ / /| ( )|| ( ) || \ ( || ( ) || ( \/\n"
printf "| (_/ / | (____)|| | | || \ | || | | || (_____ \n"
printf "| _ ( | __)| | | || (\ \) || | | |(_____ )\n"
printf "| ( \ \ | (\ ( | | | || | \ || | | | ) |\n"
printf "| / \ \| ) \ \__| (___) || ) \ || (___) |/\____) |\n"
printf "|_/ \/|/ \__/(_______)|/ )_)(_______)\_______)\n"
printf "Updating to Kronos Version ${VERSION}\n\n"
echo "Ensuring you have NVM and v12 NodeJS/NPM"
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
npm install -g npm node-gyp electron electron-forge electron-rebuild
if [ ! -f ~/snap/denarius/common/.denarius/walletnotify.sh ]; then
touch ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a #!/bin/sh' ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a curl http://127.0.0.1:3000/walletnotify -d "txid=$@"' ~/snap/denarius/common/.denarius/walletnotify.sh
sed -i '$a walletnotify=curl http://127.0.0.1:3000/walletnotify -d "txid=%s"' ~/snap/denarius/common/.denarius/denarius.conf
fi
cd kronos
git checkout .
git pull
NODEPID=$(pidof node)
echo "Killing PID of Kronos for update ${NODEPID}"
sudo kill -9 ${NODEPID}
sudo su
npm install
npm update
cd node_modules/node-pty-prebuilt-multiarch
node-gyp configure
node-gyp build
cd ..
cd ..
nohup npm run headless &
echo "Successfully Updated Kronos to ${VERSION}, You may now login from your web browser."
;;
esac
echo Selected $choice