sudo ufw allow 4002 comment 'allow ThunderHub SSL'

sudo ufw reload

sudo cat << EOF | sudo tee /etc/nginx/streams-enabled/thunderhub-reverse-proxy.conf
upstream thunderhub {
  server 127.0.0.1:3010;
}
server {
  listen 4002 ssl;
  proxy_pass thunderhub;
}
EOF

sudo systemctl reload nginx

sudo cp /data/lnd/data/chain/bitcoin/mainnet/admin.macaroon /home/thunderhub/admin.macaroon
sudo chown thunderhub:thunderhub /home/thunderhub/admin.macaroon

sudo cat << EOF | sudo tee /etc/systemd/system/thunderhub.service
# RaspiBolt: systemd unit for Thunderhub
# /etc/systemd/system/thunderhub.service

[Unit]
Description=Thunderhub
Wants=lnd.service
After=network.target lnd.service

[Service]
WorkingDirectory=/home/thunderhub/thunderhub
ExecStart=/usr/bin/npm run start:prod
User=thunderhub
Restart=always
TimeoutSec=120
RestartSec=30
StandardOutput=null
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable thunderhub.service
cd
rm 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 
rm thunderhub2.sh
sudo su thunderhub
