-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathsetup_device.sh
executable file
·1127 lines (952 loc) · 35.1 KB
/
setup_device.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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
###
### Setup MyNode (all devices)
### Run with "sudo"
###
set -x
set -e
if [ "$#" != "1" ]; then
echo "Usage: $0 <ip address | online>"
exit 1
fi
SERVER_IP=$1
# Determine Device
IS_ARMBIAN=0
IS_ROCK64=0
IS_ROCKPRO64=0
IS_RASPI=0
IS_RASPI3=0
IS_RASPI4=0
IS_RASPI5=0
IS_ROCKPI4=0
IS_X86=0
IS_ARM64=0
IS_32_BIT=0
IS_64_BIT=0
IS_UNKNOWN=0
DEVICE_TYPE="unknown"
MODEL=$(cat /proc/device-tree/model) || IS_UNKNOWN=1
DEBIAN_VERSION=$(lsb_release -c -s) || DEBIAN_VERSION="unknown"
uname -a | grep amd64 && IS_X86=1 && IS_64_BIT=1 && IS_UNKNOWN=0 || true
if [[ $MODEL == *"Rock64"* ]]; then
IS_ARMBIAN=1
IS_ROCK64=1
IS_64_BIT=1
elif [[ $MODEL == *"RockPro64"* ]]; then
IS_ARMBIAN=1
IS_ROCKPRO64=1
IS_64_BIT=1
elif [[ $MODEL == *"Raspberry Pi 3"* ]]; then
IS_RASPI=1
IS_RASPI3=1
IS_32_BIT=1
elif [[ $MODEL == *"Raspberry Pi 4"* ]]; then
IS_RASPI=1
IS_RASPI4=1
IS_32_BIT=1
UNAME=$(uname -a)
if [[ $UNAME == *"aarch64"* ]]; then
IS_ARM64=1
IS_32_BIT=0
IS_64_BIT=1
fi
elif [[ $MODEL == *"Raspberry Pi 5"* ]]; then
IS_RASPI=1
IS_RASPI5=1
IS_ARM64=1
IS_64_BIT=1
elif [[ $MODEL == *"ROCK Pi 4"* ]]; then
IS_ARMBIAN=1
IS_ROCKPI4=1
IS_64_BIT=1
fi
if [ $IS_UNKNOWN = 1 ]; then
echo "UNKNOWN DEVICE TYPE"
exit 1
fi
# Set kernel settings
sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1
sysctl -w net.ipv6.conf.lo.disable_ipv6=1
# Set DNS for install (old)
#echo "" > /etc/resolv.conf
#echo "nameserver 1.1.1.1" >> /etc/resolv.conf
#echo "nameserver 9.9.9.9" >> /etc/resolv.conf
#echo "nameserver 8.8.8.8" >> /etc/resolv.conf
# Set DNS for install (new)
echo "" >> /etc/dhcp/dhclient.conf
echo "append domain-name-servers 1.1.1.1, 208.67.222.222, 8.8.8.8;" >> /etc/dhcp/dhclient.conf
dhclient -r
# Test DNS resolution issues (may have only seen issues on bad device)
#ping -c 2 raspberrypi.org
#ping -c 2 raspbian.raspberrypi.org
#ping -c 2 pythonhosted.org
#ping -c 2 python.org
#ping -c 2 piwheels.org
# Make sure FS is expanded
if [ $IS_ARMBIAN = 1 ] ; then
/usr/lib/armbian/armbian-resize-filesystem start
fi
if [ $IS_X86 = 1 ]; then
apt-get -y install gdisk parted
X86_ROOT_PARTITION="$(mount | grep ' / ' | cut -d ' ' -f1)"
X86_DEVICE="$(lsblk -no pkname $X86_ROOT_PARTITION)"
X86_DEVICE_PATH="/dev/$X86_DEVICE"
case "$X86_DEVICE" in
sd* | hd* | vd*)
# SATA
X86_PARTITION_NUMBER=$(cat /proc/partitions | grep -c "${X86_DEVICE}[0-9]")
;;
nvme*)
# NVMe
X86_PARTITION_NUMBER=$(cat /proc/partitions | grep -c "${X86_DEVICE}p[0-9]")
;;
esac
X86_FDISK_TYPE=$(fdisk -l "$X86_DEVICE_PATH" | grep "Disklabel")
echo "Root Partition: $X86_ROOT_PARTITION"
echo "Root Device: $X86_DEVICE"
echo "Root Dev Path: $X86_DEVICE_PATH"
echo "Root Partition #: $X86_PARTITION_NUMBER"
if [[ "$X86_FDISK_TYPE" = *"Disklabel type: gpt"* ]]; then
if [ "$X86_PARTITION_NUMBER" = "2" ]; then
sgdisk -e $X86_DEVICE_PATH
sgdisk -d $X86_PARTITION_NUMBER $X86_DEVICE_PATH
sgdisk -N $X86_PARTITION_NUMBER $X86_DEVICE_PATH
partprobe $X86_DEVICE_PATH
resize2fs $X86_ROOT_PARTITION
else
echo "Not resizing - Expected 2 partitions, found $X86_PARTITION_NUMBER"
fi
else
echo "Not resizing - Expected GPT partition"
echo "$X86_FDISK"
fi
fi
# Download rootfs
rm -rf /tmp/rootfs.tar.gz
rm -rf /tmp/upgrade/
mkdir -p /tmp/upgrade
TARBALL=""
if [ $IS_ROCK64 = 1 ]; then
TARBALL="mynode_rootfs_rock64.tar.gz"
elif [ $IS_ROCKPRO64 = 1 ]; then
TARBALL="mynode_rootfs_rockpro64.tar.gz"
elif [ $IS_RASPI3 = 1 ]; then
TARBALL="mynode_rootfs_raspi3.tar.gz"
elif [ $IS_RASPI4 = 1 ]; then
TARBALL="mynode_rootfs_raspi4.tar.gz"
elif [ $IS_RASPI5 = 1 ]; then
TARBALL="mynode_rootfs_raspi5.tar.gz"
elif [ $IS_ROCKPI4 = 1 ]; then
TARBALL="mynode_rootfs_rockpi4.tar.gz"
elif [ $IS_X86 = 1 ]; then
TARBALL="mynode_rootfs_debian.tar.gz"
fi
if [ "$SERVER_IP" == "online" ]; then
TARBALL="${TARBALL/"mynode_rootfs_"/"mynode_release_latest_"}"
wget https://mynodebtc.com/device/upgrade_images/${TARBALL} -O /tmp/rootfs.tar.gz
else
wget http://${SERVER_IP}:8000/${TARBALL} -O /tmp/rootfs.tar.gz
fi
# Extract rootfs (so we can reference temporary files)
tar -xvf /tmp/rootfs.tar.gz -C /tmp/upgrade/
TMP_INSTALL_PATH="/tmp/upgrade/out/rootfs_*"
# Setup some dependencies
mkdir -p /usr/share/mynode/
cp -f /tmp/upgrade/out/rootfs_*/usr/share/mynode/mynode_device_info.sh /usr/share/mynode/mynode_device_info.sh
cp -f /tmp/upgrade/out/rootfs_*/usr/share/mynode/mynode_config.sh /usr/share/mynode/mynode_config.sh
cp -f /tmp/upgrade/out/rootfs_*/usr/share/mynode/mynode_functions.sh /usr/share/mynode/mynode_functions.sh
cp -f /tmp/upgrade/out/rootfs_*/usr/bin/mynode-get-device-serial /usr/bin/mynode-get-device-serial
# Source file containing app versions
source /tmp/upgrade/out/rootfs_*/usr/share/mynode/mynode_app_versions.sh
# Update SD card
mkdir -p /etc/torrc.d
# Set admin password to bolt
useradd -p $(openssl passwd -1 bolt) -m -s /bin/bash admin || true
# Initialize Users
/bin/bash $TMP_INSTALL_PATH/usr/bin/mynode_initialize_users.sh
# Setup bitcoin user folders
mkdir -p /home/bitcoin/.mynode/
chown bitcoin:bitcoin /home/bitcoin
chown -R bitcoin:bitcoin /home/bitcoin/.mynode/
# Update host info
echo "mynode" > /etc/hostname
sed -i 's/rock64/mynode/g' /etc/hosts
sed -i 's/rockpi4-b/mynode/g' /etc/hosts
# Update sources
apt-get -y update --allow-releaseinfo-change
# Add sources
apt-get -y install apt-transport-https curl gnupg ca-certificates
# Tor (arm32 support was dropped)
if [ $IS_64_BIT = 1 ]; then
grep -qxF "deb https://deb.torproject.org/torproject.org ${DEBIAN_VERSION} main" /etc/apt/sources.list || echo "deb https://deb.torproject.org/torproject.org ${DEBIAN_VERSION} main" >> /etc/apt/sources.list
grep -qxF "deb-src https://deb.torproject.org/torproject.org ${DEBIAN_VERSION} main" /etc/apt/sources.list || echo "deb-src https://deb.torproject.org/torproject.org ${DEBIAN_VERSION} main" >> /etc/apt/sources.list
fi
if [ "$DEBIAN_VERSION" = "buster" ]; then
# Migrate old buster backports to archive
sed -i 's|deb.debian.org/debian buster-backports|archive.debian.org/debian buster-backports|g' /etc/apt/sources.list
# Add backports repo
grep -qxF "deb http://archive.debian.org/debian buster-backports main" /etc/apt/sources.list || echo "deb http://archive.debian.org/debian buster-backports main" >> /etc/apt/sources.list
fi
# Add I2P Repo
/bin/bash $TMP_INSTALL_PATH/usr/share/mynode/scripts/add_i2p_repo.sh
# Import Keys
curl https://keybase.io/roasbeef/pgp_keys.asc | gpg --import
curl https://keybase.io/bitconner/pgp_keys.asc | gpg --import
curl https://keybase.io/guggero/pgp_keys.asc | gpg --import # Pool
curl https://raw.githubusercontent.com/JoinMarket-Org/joinmarket-clientserver/master/pubkeys/AdamGibson.asc | gpg --import
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 01EA5486DE18A882D4C2684590C8019E36C2E964
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys E777299FC265DD04793070EB944D35F9AC3DB76A # Bitcoin - Michael Ford (fanquake)
curl https://keybase.io/suheb/pgp_keys.asc | gpg --import
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys DE23E73BFA8A0AD5587D2FCDE80D2F3F311FD87E # Loop (abosworth)
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 9FC6B0BFD597A94DBF09708280E5375C094198D8 # Loop (bhandras)
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 26984CB69EB8C4A26196F7A4D7D916376026F177 # Lightning Terminal
gpg --keyserver hkps://keyserver.ubuntu.com --recv-keys 187F6ADD93AE3B0CF335AA6AB984570980684DCC # Lightning Terminal
wget -q https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc -O- | apt-key add - # Tor
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 648ACFD622F3D138 # Debian Backports
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys 0E98404D386FA1D9 # Debian Backports
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 74A941BA219EC810 # Tor
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 66F6C87B98EBCFE2 # I2P (R4SAS)
# Update OS
apt -y update # Needed to accept new repos
apt-get -y update
# Freeze any packages we don't want to update
if [ $IS_X86 = 1 ]; then
apt-mark hold grub*
fi
#apt-mark hold redis-server
# Upgrade packages
apt-get -y upgrade
# Install other tools (run section multiple times to make sure success)
export DEBIAN_FRONTEND=noninteractive
apt-get -y install apt-transport-https lsb-release
apt-get -y install htop git curl bash-completion jq dphys-swapfile lsof libzmq3-dev
apt-get -y install build-essential python3-dev python3-pip python3-grpcio
apt-get -y install transmission-cli fail2ban ufw tclsh redis-server
apt-get -y install clang hitch zlib1g-dev libffi-dev file toilet ncdu
apt-get -y install toilet-fonts avahi-daemon figlet libsecp256k1-dev
apt-get -y install inotify-tools libssl-dev tor tmux screen fonts-dejavu
apt-get -y install pv sysstat network-manager rsync parted unzip pkg-config
apt-get -y install libfreetype6-dev libpng-dev libatlas-base-dev libgmp-dev libltdl-dev
apt-get -y install libffi-dev libssl-dev python3-bottle automake libtool libltdl7
apt -y -qq install apt-transport-https ca-certificates
apt-get -y install libevent-dev ncurses-dev
apt-get -y install zlib1g-dev libudev-dev libusb-1.0-0-dev python3-venv gunicorn
apt-get -y install sqlite3 libsqlite3-dev torsocks python3-requests libsystemd-dev
apt-get -y install libjpeg-dev zlib1g-dev psmisc hexyl libbz2-dev liblzma-dev netcat-openbsd
apt-get -y install hdparm iotop nut obfs4proxy libpq-dev socat btrfs-progs i2pd apparmor pass
apt-get -y install gdisk xxd
# Install Java
apt-get -y install default-jre
# Install packages dependent on Debian release
if [ "$DEBIAN_VERSION" == "bullseye" ]; then
apt-get -y install wireguard
elif [ "$DEBIAN_VERSION" == "bookworm" ]; then
apt-get -y install wireguard
elif [ "$DEBIAN_VERSION" == "buster" ]; then
apt-get -y -t buster-backports install wireguard
else
echo "========================================="
echo "== UNKNOWN DEBIAN VERSION: $DEBIAN_VERSION"
echo "== SOME APPS MAY NOT WORK PROPERLY"
echo "========================================="
fi
# Install Openbox GUI
if [ $IS_X86 = 1 ]; then
apt-get -y install xorg chromium openbox lightdm
fi
# Install device specific packages
if [ $IS_X86 = 1 ]; then
apt-get -y install cloud-init
apt-get -y install intel-microcode || true
fi
if [ $IS_ARMBIAN = 1 ] ; then
apt-get -y install systemd-timesyncd
timedatectl set-ntp true
fi
# Make sure some software is removed
apt-get -y purge ntp # (conflicts with systemd-timedatectl)
apt-get -y purge chrony # (conflicts with systemd-timedatectl)
# Install other things without recommendation
apt-get -y install --no-install-recommends expect
# Install nginx
mkdir -p /var/log/nginx
apt-get -y install nginx || true
apt-get -y install libnginx-mod-stream || true
# Install may fail, so we need to edit the default config file and reconfigure
rm -f /etc/nginx/modules-enabled/50-mod-* || true
echo "" > /etc/nginx/sites-available/default
dpkg --configure -a
# Cleanup apt-get cache to save some space
apt-get clean
# Update users
usermod -a -G debian-tor bitcoin
# Make admin a member of bitcoin
adduser admin bitcoin
adduser joinmarket bitcoin
grep "joinmarket" /etc/sudoers || (echo 'joinmarket ALL=(ALL) NOPASSWD:ALL' | EDITOR='tee -a' visudo)
# Install Go
GO_ARCH="unknown"
if [ "$DEVICE_ARCH" == "armv7l" ]; then
GO_ARCH="armv6l"
elif [ "$DEVICE_ARCH" == "aarch64" ]; then
GO_ARCH="arm64"
elif [ "$DEVICE_ARCH" == "x86_64" ]; then
GO_ARCH="amd64"
fi
GO_UPGRADE_URL=https://go.dev/dl/go$GO_VERSION.linux-$GO_ARCH.tar.gz
CURRENT=""
if [ -f $GO_VERSION_FILE ]; then
CURRENT=$(cat $GO_VERSION_FILE)
fi
if [ "$CURRENT" != "$GO_VERSION" ]; then
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $GO_UPGRADE_URL -O go.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go.tar.gz
# Mark current version
echo $GO_VERSION > $GO_VERSION_FILE
fi
echo "export GOBIN=/usr/local/go/bin; PATH=\$PATH:/usr/local/go/bin" > /etc/profile.d/go.sh
grep -qxF '. /etc/profile.d/go.sh' /root/.bashrc || echo '. /etc/profile.d/go.sh' >> /root/.bashrc
# Install Rust (only needed on 32-bit RPi for building some python wheels)
if [ ! -f $HOME/.cargo/env ]; then
wget https://sh.rustup.rs -O /tmp/setup_rust.sh
/bin/bash /tmp/setup_rust.sh -y --default-toolchain none
sync
fi
if [ -f $HOME/.cargo/env ]; then
# Remove old toolchains
source $HOME/.cargo/env
TOOLCHAINS=$(rustup toolchain list)
for toolchain in $TOOLCHAINS; do
if [[ "$toolchain" == *"linux"* ]] && [[ "$toolchain" != *"${RUST_VERSION}"* ]]; then
rustup toolchain remove $toolchain || true
fi
done
# Manage rust toolchains
if [ $IS_RASPI = 1 ] && [ $IS_ARM64 = 0 ]; then
# Install and use desired version
rustup install $RUST_VERSION
rustup default $RUST_VERSION
rustc --version
fi
fi
# Install Python3 (latest)
CURRENT_PYTHON3_VERSION=$(python3 --version)
if [[ "$CURRENT_PYTHON3_VERSION" != *"Python ${PYTHON_VERSION}"* ]]; then
mkdir -p /opt/download
cd /opt/download
rm -rf Python-*
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz -O python.tar.xz
tar xf python.tar.xz
cd Python-*
./configure
make -j4
make install
cd ~
else
echo "Python up to date"
fi
# Add to python path
[ -d /usr/local/lib/python2.7/dist-packages ] && echo "/var/pynode" > /usr/local/lib/python2.7/dist-packages/pynode.pth
[ -d /usr/local/lib/python3.7/site-packages ] && echo "/var/pynode" > /usr/local/lib/python3.7/site-packages/pynode.pth
[ -d /usr/local/lib/python3.8/site-packages ] && echo "/var/pynode" > /usr/local/lib/python3.8/site-packages/pynode.pth
# Install Python3 specific tools
pip3 install --upgrade pip wheel setuptools
pip3 install -r $TMP_INSTALL_PATH/usr/share/mynode/mynode_pip3_requirements.txt --no-cache-dir || \
pip3 install -r $TMP_INSTALL_PATH/usr/share/mynode/mynode_pip3_requirements.txt --no-cache-dir --use-deprecated=html5lib
# For RP4 32-bit, install specific grpcio version known to build (uses proper glibc for wheel)
if [ $IS_32_BIT = 1 ]; then
pip3 install grpcio==$PYTHON_ARM32_GRPCIO_VERSION grpcio-tools==$PYTHON_ARM32_GRPCIO_VERSION
fi
# Install node
if [ ! -f /tmp/installed_node ]; then
curl -sL https://deb.nodesource.com/setup_$NODE_JS_VERSION | bash -
apt-get install -y nodejs
touch /tmp/installed_node
fi
# Install docker
mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --batch --yes --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null
apt-get update --allow-releaseinfo-change
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin || true
# Use systemd for managing docker
rm -f /etc/init.d/docker
rm -f /etc/systemd/system/multi-user.target.wants/docker.service
systemctl -f enable docker.service
groupadd docker || true
usermod -aG docker admin
usermod -aG docker bitcoin
usermod -aG docker root
# Install node packages
npm install -g pug-cli browserify uglify-js babel-cli
npm install -g npm@$NODE_NPM_VERSION
npm install -g yarn
# Install Log2Ram
if [ $IS_RASPI = 1 ] || [ $IS_X86 = 1 ]; then
if [ ! -f /usr/local/bin/log2ram ]; then
cd /tmp
rm -rf log2ram* || true
wget https://github.com/azlux/log2ram/archive/v1.2.2.tar.gz -O log2ram.tar.gz
tar -xvf log2ram.tar.gz
mv log2ram-* log2ram
cd log2ram
chmod +x install.sh
service log2ram stop || true
./install.sh || true
cd ~
fi
fi
# Remove existing MOTD login info
rm -rf /etc/motd
rm -rf /etc/update-motd.d/*
#########################################################
# Install Bitcoin
ARCH="UNKNOWN"
if [ $IS_RASPI = 1 ]; then
ARCH="arm-linux-gnueabihf"
if [ $IS_ARM64 = 1 ]; then
ARCH="aarch64-linux-gnu"
fi
elif [ $IS_ROCK64 = 1 ] || [ $IS_ROCKPRO64 = 1 ] || [ $IS_ROCKPI4 = 1 ]; then
ARCH="aarch64-linux-gnu"
elif [ $IS_X86 = 1 ]; then
ARCH="x86_64-linux-gnu"
else
echo "Unknown Bitcoin Version"
exit 1
fi
BTC_UPGRADE_URL=https://bitcoincore.org/bin/bitcoin-core-$BTC_VERSION/bitcoin-$BTC_VERSION-$ARCH.tar.gz
BTC_UPGRADE_SHA256SUM_URL=https://bitcoincore.org/bin/bitcoin-core-$BTC_VERSION/SHA256SUMS
BTC_UPGRADE_SHA256SUM_ASC_URL=https://bitcoincore.org/bin/bitcoin-core-$BTC_VERSION/SHA256SUMS.asc
BTC_CLI_COMPLETION_URL=https://raw.githubusercontent.com/bitcoin/bitcoin/v$BTC_VERSION/contrib/completions/bash/bitcoin-cli.bash
CURRENT=""
if [ -f $BTC_VERSION_FILE ]; then
CURRENT=$(cat $BTC_VERSION_FILE)
fi
if [ "$CURRENT" != "$BTC_VERSION" ]; then
# Download and install Bitcoin
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $BTC_UPGRADE_URL
wget $BTC_UPGRADE_SHA256SUM_URL -O SHA256SUMS
wget $BTC_UPGRADE_SHA256SUM_ASC_URL -O SHA256SUMS.asc
sha256sum --ignore-missing --check SHA256SUMS
gpg --verify SHA256SUMS.asc SHA256SUMS |& grep "gpg: Good signature"
# Install Bitcoin
tar -xvf bitcoin-$BTC_VERSION-$ARCH.tar.gz
mv bitcoin-$BTC_VERSION bitcoin
install -m 0755 -o root -g root -t /usr/local/bin bitcoin/bin/*
if [ ! -L /home/bitcoin/.bitcoin ]; then
sudo -u bitcoin ln -s /mnt/hdd/mynode/bitcoin /home/bitcoin/.bitcoin
fi
if [ ! -L /home/bitcoin/.lnd ]; then
sudo -u bitcoin ln -s /mnt/hdd/mynode/lnd /home/bitcoin/.lnd
fi
mkdir -p /home/admin/.bitcoin
echo $BTC_VERSION > $BTC_VERSION_FILE
# Install bash-completion for bitcoin-cli
wget $BTC_CLI_COMPLETION_URL -O bitcoin-cli.bash
sudo cp bitcoin-cli.bash /etc/bash_completion.d/bitcoin-cli
fi
cd ~
# Install Lightning
LND_ARCH="lnd-linux-armv7"
if [ $IS_X86 = 1 ]; then
LND_ARCH="lnd-linux-amd64"
fi
if [ $IS_ARM64 = 1 ] || [ $IS_ROCK64 = 1 ] || [ $IS_ROCKPRO64 = 1 ] || [ $IS_ROCKPI4 = 1 ]; then
LND_ARCH="lnd-linux-arm64"
fi
LND_UPGRADE_URL=https://github.com/lightningnetwork/lnd/releases/download/$LND_VERSION/$LND_ARCH-$LND_VERSION.tar.gz
LNCLI_COMPLETION_URL=https://raw.githubusercontent.com/lightningnetwork/lnd/$LND_VERSION/contrib/lncli.bash-completion
CURRENT=""
if [ -f $LND_VERSION_FILE ]; then
CURRENT=$(cat $LND_VERSION_FILE)
fi
if [ "$CURRENT" != "$LND_VERSION" ]; then
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $LND_UPGRADE_URL
wget $LND_UPGRADE_MANIFEST_URL -O manifest.txt
wget $LND_UPGRADE_MANIFEST_ROASBEEF_SIG_URL -O manifest_roasbeef.txt.sig || true
wget $LND_UPGRADE_MANIFEST_GUGGERO_SIG_URL -O manifest_guggero.txt.sig || true
gpg --verify manifest_roasbeef.txt.sig manifest.txt || \
gpg --verify manifest_guggero.txt.sig manifest.txt
tar -xzf lnd-*.tar.gz
mv $LND_ARCH-$LND_VERSION lnd
install -m 0755 -o root -g root -t /usr/local/bin lnd/*
ln -s /bin/ip /usr/bin/ip || true
echo $LND_VERSION > $LND_VERSION_FILE
# Download bash-completion file for lncli
wget $LNCLI_COMPLETION_URL
sudo cp lncli.bash-completion /etc/bash_completion.d/lncli
fi
cd ~
# Install Loop
echo "Installing loop..."
LOOP_ARCH="loop-linux-armv7"
if [ $IS_X86 = 1 ]; then
LOOP_ARCH="loop-linux-amd64"
fi
if [ $IS_ARM64 = 1 ]; then
LOOP_ARCH="loop-linux-arm64"
fi
LOOP_UPGRADE_URL=https://github.com/lightninglabs/loop/releases/download/$LOOP_VERSION/$LOOP_ARCH-$LOOP_VERSION.tar.gz
CURRENT=""
if [ -f $LOOP_VERSION_FILE ]; then
CURRENT=$(cat $LOOP_VERSION_FILE)
fi
if [ "$CURRENT" != "$LOOP_VERSION" ]; then
# Download and install Loop
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $LOOP_UPGRADE_URL
wget $LOOP_UPGRADE_MANIFEST_URL -O manifest.txt
wget $LOOP_UPGRADE_MANIFEST_SIG_URL -O manifest.txt.sig
gpg --verify manifest.txt.sig manifest.txt
if [ $? == 0 ]; then
# Install Loop
tar -xzf loop-*.tar.gz
mv $LOOP_ARCH-$LOOP_VERSION loop
install -m 0755 -o root -g root -t /usr/local/bin loop/*
# Mark current version
echo $LOOP_VERSION > $LOOP_VERSION_FILE
else
echo "ERROR UPGRADING LND - GPG FAILED"
fi
fi
# Install Pool
echo "Installing pool..."
POOL_ARCH="pool-linux-armv7"
if [ $IS_X86 = 1 ]; then
POOL_ARCH="pool-linux-amd64"
fi
if [ $IS_ARM64 = 1 ]; then
POOL_ARCH="pool-linux-arm64"
fi
POOL_UPGRADE_URL=https://github.com/lightninglabs/pool/releases/download/$POOL_VERSION/$POOL_ARCH-$POOL_VERSION.tar.gz
CURRENT=""
if [ -f $POOL_VERSION_FILE ]; then
CURRENT=$(cat $POOL_VERSION_FILE)
fi
if [ "$CURRENT" != "$POOL_VERSION" ]; then
# Download and install pool
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $POOL_UPGRADE_URL
wget $POOL_UPGRADE_MANIFEST_URL -O manifest.txt
wget $POOL_UPGRADE_MANIFEST_SIG_URL -O manifest.txt.sig
gpg --verify manifest.txt.sig manifest.txt
if [ $? == 0 ]; then
# Install Pool
tar -xzf pool-*.tar.gz
mv $POOL_ARCH-$POOL_VERSION pool
install -m 0755 -o root -g root -t /usr/local/bin pool/*
# Mark current version
echo $POOL_VERSION > $POOL_VERSION_FILE
else
echo "ERROR UPGRADING POOL - GPG FAILED"
fi
fi
# Install Lightning Terminal
echo "Installing lit..."
LIT_ARCH="lightning-terminal-linux-armv7"
if [ $IS_X86 = 1 ]; then
LIT_ARCH="lightning-terminal-linux-amd64"
fi
if [ $IS_ARM64 = 1 ]; then
LIT_ARCH="lightning-terminal-linux-arm64"
fi
LIT_UPGRADE_URL=https://github.com/lightninglabs/lightning-terminal/releases/download/$LIT_VERSION/$LIT_ARCH-$LIT_VERSION.tar.gz
CURRENT=""
if [ -f $LIT_VERSION_FILE ]; then
CURRENT=$(cat $LIT_VERSION_FILE)
fi
if [ "$CURRENT" != "$LIT_VERSION" ]; then
# Download and install lit
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $LIT_UPGRADE_URL
wget $LIT_UPGRADE_MANIFEST_URL -O manifest.txt
wget $LIT_UPGRADE_MANIFEST_SIG_URL -O manifest.txt.sig
gpg --verify manifest.txt.sig manifest.txt
if [ $? == 0 ]; then
# Install lit
tar -xzf lightning-terminal-*.tar.gz
mv $LIT_ARCH-$LIT_VERSION lightning-terminal
install -m 0755 -o root -g root -t /usr/local/bin lightning-terminal/lit*
# Mark current version
echo $LIT_VERSION > $LIT_VERSION_FILE
else
echo "ERROR UPGRADING LIT - GPG FAILED"
fi
fi
cd ~
# Upgrade Lightning Chantools
echo "Upgrading chantools..."
CHANTOOLS_ARCH="chantools-linux-armv7"
if [ $IS_X86 = 1 ]; then
CHANTOOLS_ARCH="chantools-linux-amd64"
fi
if [ $IS_ARM64 = 1 ]; then
CHANTOOLS_ARCH="chantools-linux-arm64"
fi
CHANTOOLS_UPGRADE_URL=https://github.com/lightninglabs/chantools/releases/download/$CHANTOOLS_VERSION/$CHANTOOLS_ARCH-$CHANTOOLS_VERSION.tar.gz
CURRENT=""
if [ -f $CHANTOOLS_VERSION_FILE ]; then
CURRENT=$(cat $CHANTOOLS_VERSION_FILE)
fi
if [ "$CURRENT" != "$CHANTOOLS_VERSION" ]; then
# Download and install lit
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $CHANTOOLS_UPGRADE_URL
wget $CHANTOOLS_UPGRADE_MANIFEST_URL -O manifest.txt
wget $CHANTOOLS_UPGRADE_MANIFEST_SIG_URL -O manifest.txt.sig
gpg --verify manifest.txt.sig manifest.txt
if [ $? == 0 ]; then
# Install lit
tar -xzf chantools-*.tar.gz
mv $CHANTOOLS_ARCH-$CHANTOOLS_VERSION chantools
install -m 0755 -o root -g root -t /usr/local/bin chantools/chantools
# Mark current version
echo $CHANTOOLS_VERSION > $CHANTOOLS_VERSION_FILE
else
echo "ERROR UPGRADING CHANTOOLS - GPG FAILED"
fi
fi
cd ~
# Setup "install" location for some apps
mkdir -p /opt/mynode
chown -R bitcoin:bitcoin /opt/mynode
# Install LND Hub
# Skip - no longer default app
# Install Caravan
# Skip - no longer default app
# Install cors proxy (my fork)
CORSPROXY_UPGRADE_URL=https://github.com/tehelsper/CORS-Proxy/archive/$CORSPROXY_VERSION.tar.gz
CURRENT=""
if [ -f $CORSPROXY_VERSION_FILE ]; then
CURRENT=$(cat $CORSPROXY_VERSION_FILE)
fi
if [ "$CURRENT" != "$CORSPROXY_VERSION" ]; then
cd /opt/mynode
rm -rf corsproxy
rm -f corsproxy.tar.gz
wget $CORSPROXY_UPGRADE_URL -O corsproxy.tar.gz
tar -xzf corsproxy.tar.gz
rm -f corsproxy.tar.gz
mv CORS-* corsproxy
cd corsproxy
npm install
echo $CORSPROXY_VERSION > $CORSPROXY_VERSION_FILE
fi
cd ~
# Install Electrs (just mark version, now included in overlay)
echo $ELECTRS_VERSION > $ELECTRS_VERSION_FILE
# Install recent version of secp256k1
echo "Installing secp256k1..."
SECP256K1_UPGRADE_URL=https://github.com/bitcoin-core/secp256k1/archive/$SECP256K1_VERSION.tar.gz
CURRENT=""
if [ -f $SECP256K1_VERSION_FILE ]; then
CURRENT=$(cat $SECP256K1_VERSION_FILE)
fi
if [ "$CURRENT" != "$SECP256K1_VERSION" ]; then
rm -rf /tmp/secp256k1
cd /tmp/
git clone https://github.com/bitcoin-core/secp256k1.git
cd secp256k1
./autogen.sh
./configure --enable-module-recovery --disable-jni --enable-experimental --enable-module-ecdh --enable-benchmark=no
make
make install
cp -f include/* /usr/include/
echo $SECP256K1_VERSION > $SECP256K1_VERSION_FILE
fi
echo "Installing JoinInBox..."
if [ $IS_RASPI = 1 ] || [ $IS_X86 = 1 ]; then
JOININBOX_UPGRADE_URL=https://github.com/openoms/joininbox/archive/$JOININBOX_VERSION.tar.gz
CURRENT=""
if [ -f $JOININBOX_VERSION_FILE ]; then
CURRENT=$(cat $JOININBOX_VERSION_FILE)
fi
if [ "$CURRENT" != "$JOININBOX_VERSION" ]; then
# Download and build JoinInBox
cd /home/joinmarket
# Delete all non-hidden files
rm -rf *
rm -rf joininbox-*
sudo -u joinmarket wget $JOININBOX_UPGRADE_URL -O joininbox.tar.gz
sudo -u joinmarket tar -xvf joininbox.tar.gz
sudo -u joinmarket rm joininbox.tar.gz
mv joininbox-* joininbox
chmod -R +x ./joininbox/
sudo -u joinmarket cp -rf ./joininbox/scripts/* .
# Use Python3.7 on RP4 32-bit
JM_ENV_VARS=""
if [ $IS_32_BIT = 1 ]; then
JM_ENV_VARS="export JM_PYTHON=python3.7; "
fi
# Install
sudo -u joinmarket bash -c "cd /home/joinmarket/; ${JM_ENV_VARS} ./install.joinmarket.sh --install install" || true
sudo -u joinmarket bash -c "cd /home/joinmarket/; ${JM_ENV_VARS} ./install.joinmarket-api.sh on" || true
# Cleanup apt-get cache to save some space
apt-get clean
# Enable obwatcher at the end of setup_device.sh
echo $JOININBOX_VERSION > $JOININBOX_VERSION_FILE
fi
fi
# Install RTL
RTL_UPGRADE_URL=https://github.com/Ride-The-Lightning/RTL/archive/$RTL_VERSION.tar.gz
RTL_UPGRADE_ASC_URL=https://github.com/Ride-The-Lightning/RTL/releases/download/$RTL_VERSION/$RTL_VERSION.tar.gz.asc
CURRENT=""
if [ -f $RTL_VERSION_FILE ]; then
CURRENT=$(cat $RTL_VERSION_FILE)
fi
if [ "$CURRENT" != "$RTL_VERSION" ]; then
cd /opt/mynode
rm -rf RTL
sudo -u bitcoin wget $RTL_UPGRADE_URL -O RTL.tar.gz
#sudo -u bitcoin wget $RTL_UPGRADE_ASC_URL -O RTL.tar.gz.asc
#gpg --verify RTL.tar.gz.asc RTL.tar.gz
sudo -u bitcoin tar -xvf RTL.tar.gz
sudo -u bitcoin rm RTL.tar.gz
sudo -u bitcoin mv RTL-* RTL
cd RTL
sudo -u bitcoin NG_CLI_ANALYTICS=false npm install --only=production --legacy-peer-deps
echo $RTL_VERSION > $RTL_VERSION_FILE
fi
# Install BTC RPC Explorer
BTCRPCEXPLORER_UPGRADE_URL=https://github.com/janoside/btc-rpc-explorer/archive/$BTCRPCEXPLORER_VERSION.tar.gz
CURRENT=""
if [ -f $BTCRPCEXPLORER_VERSION_FILE ]; then
CURRENT=$(cat $BTCRPCEXPLORER_VERSION_FILE)
fi
if [ "$CURRENT" != "$BTCRPCEXPLORER_VERSION" ]; then
cd /opt/mynode
rm -rf btc-rpc-explorer
sudo -u bitcoin wget $BTCRPCEXPLORER_UPGRADE_URL -O btc-rpc-explorer.tar.gz
sudo -u bitcoin tar -xvf btc-rpc-explorer.tar.gz
sudo -u bitcoin rm btc-rpc-explorer.tar.gz
sudo -u bitcoin mv btc-rpc-* btc-rpc-explorer
cd btc-rpc-explorer
sudo -u bitcoin npm install --only=production
echo $BTCRPCEXPLORER_VERSION > $BTCRPCEXPLORER_VERSION_FILE
fi
# Upgrade Specter Desktop
CURRENT=""
if [ -f $SPECTER_VERSION_FILE ]; then
CURRENT=$(cat $SPECTER_VERSION_FILE)
fi
if [ "$CURRENT" != "$SPECTER_VERSION" ]; then
cd /opt/mynode
rm -rf specter
mkdir -p specter
chown -R bitcoin:bitcoin specter
cd specter
# Make venv
if [ ! -d env ]; then
sudo -u bitcoin python3 -m venv env
fi
source env/bin/activate
pip3 install ecdsa===0.13.3
pip3 install cryptoadvance.specter===$SPECTER_VERSION --upgrade
deactivate
echo $SPECTER_VERSION > $SPECTER_VERSION_FILE
fi
# Upgrade Thunderhub
THUNDERHUB_UPGRADE_URL=https://github.com/apotdevin/thunderhub/archive/$THUNDERHUB_VERSION.tar.gz
CURRENT=""
if [ -f $THUNDERHUB_VERSION_FILE ]; then
CURRENT=$(cat $THUNDERHUB_VERSION_FILE)
fi
if [ "$CURRENT" != "$THUNDERHUB_VERSION" ]; then
cd /opt/mynode
rm -rf thunderhub
sudo -u bitcoin wget $THUNDERHUB_UPGRADE_URL -O thunderhub.tar.gz
sudo -u bitcoin tar -xvf thunderhub.tar.gz
sudo -u bitcoin rm thunderhub.tar.gz
sudo -u bitcoin mv thunderhub-* thunderhub
cd thunderhub
# Patch versions
#sed -i 's/\^5.3.5/5.3.3/g' package.json || true # Fixes segfault with 5.3.5 on x86
sudo -u bitcoin npm install # --only=production # (can't build with only production)
sudo -u bitcoin npm run build
sudo -u bitcoin npx next telemetry disable
# Setup symlink to service files
rm -f /opt/mynode/thunderhub/.env.local
sudo ln -s /mnt/hdd/mynode/thunderhub/.env.local /opt/mynode/thunderhub/.env.local
echo $THUNDERHUB_VERSION > $THUNDERHUB_VERSION_FILE
fi
# Install LND Connect
LNDCONNECTARCH="lndconnect-linux-armv7"
if [ $IS_X86 = 1 ]; then
LNDCONNECTARCH="lndconnect-linux-amd64"
fi
LNDCONNECT_UPGRADE_URL=https://github.com/LN-Zap/lndconnect/releases/download/v0.2.0/$LNDCONNECTARCH-$LNDCONNECT_VERSION.tar.gz
CURRENT=""
if [ -f $LNDCONNECT_VERSION_FILE ]; then
CURRENT=$(cat $LNDCONNECT_VERSION_FILE)
fi
if [ "$CURRENT" != "$LNDCONNECT_VERSION" ]; then
rm -rf /opt/download
mkdir -p /opt/download
cd /opt/download
wget $LNDCONNECT_UPGRADE_URL -O lndconnect.tar.gz
tar -xvf lndconnect.tar.gz
rm lndconnect.tar.gz
mv lndconnect-* lndconnect
install -m 0755 -o root -g root -t /usr/local/bin lndconnect/*
echo $LNDCONNECT_VERSION > $LNDCONNECT_VERSION_FILE
fi
# Install ngrok for debugging
if [ ! -f /usr/bin/ngrok ]; then
cd /tmp
NGROK_URL=https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-arm.zip
if [ $IS_X86 = 1 ]; then
NGROK_URL=https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-386.zip
fi
wget $NGROK_URL
unzip ngrok-*.zip
cp ngrok /usr/bin/
fi
# Make sure "Remote Access" apps are marked installed
touch /home/bitcoin/.mynode/install_tor
touch /home/bitcoin/.mynode/install_premium_plus
touch /home/bitcoin/.mynode/install_vpn
# Mark docker images for install (on SD so install occurs after drive attach)
touch /home/bitcoin/.mynode/install_mempool
touch /home/bitcoin/.mynode/install_btcpayserver
# SKIPPING LNBITS - OPTIONAL ALL
# SKIPPING CKBUNKER - OPTIONAL APP
# SKIPPING SPHINX - OPTIONAL APP
# SKIPPING BOS - OPTIONAL APP
# SKIPPING PYBLOCK - OPTIONAL APP
# SKIPPING WARDEN - OPTIONAL APP
# Make sure we are using legacy iptables
update-alternatives --set iptables /usr/sbin/iptables-legacy || true
update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy || true
#########################################################
# Install files (downloaded and extracted earlier)
rsync -r -K /tmp/upgrade/out/rootfs_*/* /
sync
sleep 1