sudo ufw allow 50002/tcp comment 'allow Fulcrum SSL'
sudo ufw allow 50001/tcp comment 'allow Fulcrum TCP'
sudo ufw reload
LATEST_VERSION=$(wget -qO- https://api.github.com/repos/cculianu/Fulcrum/releases/latest | grep -oP '"tag_name": "v\K(.*)(?=")')
echo $LATEST_VERSION
cd /tmp
wget https://github.com/cculianu/Fulcrum/releases/download/v$LATEST_VERSION/Fulcrum-$LATEST_VERSION-x86_64-linux.tar.gz
wget https://github.com/cculianu/Fulcrum/releases/download/v$LATEST_VERSION/Fulcrum-$LATEST_VERSION-shasums.txt.asc
wget https://github.com/cculianu/Fulcrum/releases/download/v$LATEST_VERSION/Fulcrum-$LATEST_VERSION-shasums.txt
curl https://raw.githubusercontent.com/Electron-Cash/keys-n-hashes/master/pubkeys/calinkey.txt | gpg --import
gpg --verify Fulcrum-$LATEST_VERSION-shasums.txt.asc
sha256sum --check Fulcrum-$LATEST_VERSION-shasums.txt
tar -xvf Fulcrum-$LATEST_VERSION-x86_64-linux.tar.gz
sudo install -m 0755 -o root -g root -t /usr/local/bin Fulcrum-$LATEST_VERSION-x86_64-linux/Fulcrum Fulcrum-$LATEST_VERSION-x86_64-linux/FulcrumAdmin
sudo mkdir -p /data/fulcrum/fulcrum_db
cd /data/fulcrum
sudo openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem -subj "/C=/ST=/L=/O=/OU=/CN="
sudo chown -R fulcrum:fulcrum /data/fulcrum/
sudo ln -s /data/fulcrum /home/fulcrum/.fulcrum
sudo chown -R fulcrum:fulcrum /home/fulcrum/.fulcrum


##############################
sudo cp /etc/tor/torrc /etc/tor/torrc.bak
sudo cat << EOF | sudo tee -a /etc/tor/torrc
############### This section is just for location-hidden services ###
# Hidden Service Fulcrum SSL
HiddenServiceDir /var/lib/tor/hidden_service_fulcrum_ssl/
HiddenServiceVersion 3
HiddenServicePort 50002 127.0.0.1:50002
  
# Hidden Service Fulcrum TCP
HiddenServiceDir /var/lib/tor/hidden_service_fulcrum_tcp/
HiddenServiceVersion 3
HiddenServicePort 50001 127.0.0.1:50001
EOF

sudo systemctl reload tor

#####################

sudo cat << EOF | sudo tee /data/fulcrum/fulcrum.conf
# RaspiBolt: fulcrum configuration 
# /data/fulcrum/fulcrum.conf
  
# Bitcoin Core settings
bitcoind = 127.0.0.1:8332
rpccookie = /data/bitcoin/.cookie
  
# Fulcrum server settings
datadir = /data/fulcrum/fulcrum_db
cert = /data/fulcrum/cert.pem
key = /data/fulcrum/key.pem
ssl = 0.0.0.0:50002
tcp = 0.0.0.0:50001
peering = false
  
# RPi optimizations
bitcoind_timeout = 600
bitcoind_clients = 1
worker_threads = 1
db_mem = 1024.0
  
# 4GB RAM (default)
#db_max_open_files = 200
#fast-sync = 1024
  
# 8GB RAM (comment the last two lines and uncomment the next)
db_max_open_files = 400
fast-sync = 2048
EOF

#######################################


sudo cat << EOF | sudo tee /etc/systemd/system/fulcrum.service
# RaspiBolt: systemd unit for Fulcrum
# /etc/systemd/system/fulcrum.service
  
[Unit]
Description=Fulcrum
PartOf=bitcoind.service
After=bitcoind.service
StartLimitBurst=2
StartLimitIntervalSec=20
  
[Service]
ExecStart=/usr/local/bin/Fulcrum /data/fulcrum/fulcrum.conf
KillSignal=SIGINT
User=fulcrum
Type=exec
TimeoutStopSec=300
RestartSec=30
Restart=on-failure
  
[Install]
WantedBy=multi-user.target
EOF

#


cd

sudo chown -R fulcrum:fulcrum /data/fulcrum/
sudo chown -R fulcrum:fulcrum /home/fulcrum/.fulcrum

sudo chmod +x /home/admin/lnd.sh
#
sudo chmod +x /home/admin/thunderhub.sh

sudo cp thunderhub2.sh /home/thunderhub/thunderhub2.sh
sudo chmod +x /home/thunderhub/thunderhub2.sh
sudo chown thunderhub:thunderhub /home/thunderhub/thunderhub2.sh
#


sudo ufw allow 4081/tcp comment 'allow Mempool SSL'
sudo ufw reload

cd
rm fulcrum.sh

#sudo systemctl enable fulcrum.service

#sudo systemctl start fulcrum.service


