mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-24 22:58:43 +01:00
cln: refactor RTL install for parallel instances
This commit is contained in:
parent
a8788f72cd
commit
5123f49006
1 changed files with 244 additions and 126 deletions
|
@ -1,23 +1,75 @@
|
|||
#!/bin/bash
|
||||
RTLVERSION="v0.10.1"
|
||||
|
||||
# command info
|
||||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
||||
echo "# config script to switch the RideTheLightning WebGUI on, off or update"
|
||||
echo "# bonus.rtl.sh [on|off|update<commit>|menu|config]"
|
||||
echo "# installs the version $RTLVERSION by default"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# check and load raspiblitz config
|
||||
# to know which network is running
|
||||
source /home/admin/raspiblitz.info
|
||||
source /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# command info
|
||||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
||||
echo "# config script to switch the RideTheLightning WebGUI on, off or update"
|
||||
echo
|
||||
echo "# bonus.rtl.sh [on|off|menu] <lnd|cln> <testnet|signet>"
|
||||
echo "# sets up lnd on ${chain}net by default"
|
||||
echo "# able to run intances for lnd and cln parallel"
|
||||
echo "# lnd mainnet and testnet can run parallel"
|
||||
echo "# cln can only have one network active at a time"
|
||||
echo
|
||||
echo "# bonus.rtl.sh [update<commit>|config]"
|
||||
echo "# installs the version $RTLVERSION by default"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "# Running: 'bonus.rtl.sh $*'"
|
||||
|
||||
if [ ${#network} -eq 0 ]; then
|
||||
echo "FAIL - missing /mnt/hdd/raspiblitz.conf"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# LNTYPE is lnd | cln
|
||||
if [ $# -gt 1 ];then
|
||||
LNTYPE=$2
|
||||
else
|
||||
LNTYPE=lnd
|
||||
fi
|
||||
if [ ${LNTYPE} != lnd ]&&[ ${LNTYPE} != cln ];then
|
||||
echo "# ${LNTYPE} is not a supported LNTYPE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# CHAIN is signet | testnet | mainnet
|
||||
if [ $# -gt 2 ];then
|
||||
CHAIN=$3
|
||||
else
|
||||
CHAIN=${chain}net
|
||||
fi
|
||||
if [ ${CHAIN} != testnet ]&&[ ${CHAIN} != mainnet ]&&[ ${CHAIN} != signet ];then
|
||||
echo "# ${CHAIN} is not a supported CHAIN"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# prefix for parallel services
|
||||
if [ ${CHAIN} = testnet ];then
|
||||
chainprefix="t"
|
||||
portprefix=1
|
||||
elif [ ${CHAIN} = signet ];then
|
||||
chainprefix="s"
|
||||
portprefix=3
|
||||
elif [ ${CHAIN} = mainnet ];then
|
||||
chainprefix=""
|
||||
portprefix=""
|
||||
fi
|
||||
|
||||
if [ ${LNTYPE} = cln ]; then
|
||||
RTLHTTP=${portprefix}7000
|
||||
typeprefix=c
|
||||
elif [ ${LNTYPE} = lnd ];then
|
||||
RTLHTTP=${portprefix}3000
|
||||
typeprefix=""
|
||||
fi
|
||||
|
||||
# show info menu
|
||||
if [ "$1" = "menu" ]; then
|
||||
|
||||
|
@ -29,9 +81,9 @@ if [ "$1" = "menu" ]; then
|
|||
if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then
|
||||
# Info with TOR
|
||||
/home/admin/config.scripts/blitz.display.sh qr "${toraddress}"
|
||||
whiptail --title " Ride The Lightning (RTL) " --msgbox "Open in your local web browser:
|
||||
http://${localip}:3000\n
|
||||
https://${localip}:3001 with Fingerprint:
|
||||
whiptail --title "Ride The Lightning (RTL - $LNTYPE - $CHAIN)" --msgbox "Open in your local web browser:
|
||||
http://${localip}:${RTLHTTP}\n
|
||||
https://${localip}:$((RTLHTTP+1)) with Fingerprint:
|
||||
${fingerprint}\n
|
||||
Use your Password B to login.\n
|
||||
Hidden Service address for TOR Browser (QRcode on LCD):\n${toraddress}
|
||||
|
@ -39,9 +91,9 @@ Hidden Service address for TOR Browser (QRcode on LCD):\n${toraddress}
|
|||
/home/admin/config.scripts/blitz.display.sh hide
|
||||
else
|
||||
# Info without TOR
|
||||
whiptail --title " Ride The Lightning (RTL) " --msgbox "Open in your local web browser & accept self-signed cert:
|
||||
http://${localip}:3000\n
|
||||
https://${localip}:3001 with Fingerprint:
|
||||
whiptail --title "Ride The Lightning (RTL - $LNTYPE - $CHAIN)" --msgbox "Open in your local web browser & accept self-signed cert:
|
||||
http://${localip}:${RTLHTTP}\n
|
||||
https://${localip}:$((RTLHTTP+1)) with Fingerprint:
|
||||
${fingerprint}\n
|
||||
Use your Password B to login.\n
|
||||
Activate TOR to access the web interface from outside your local network.
|
||||
|
@ -52,15 +104,19 @@ Activate TOR to access the web interface from outside your local network.
|
|||
fi
|
||||
|
||||
# add default value to raspi config if needed
|
||||
if ! grep -Eq "^rtlWebinterface=" /mnt/hdd/raspiblitz.conf; then
|
||||
echo "rtlWebinterface=off" >> /mnt/hdd/raspiblitz.conf
|
||||
if ! grep -Eq "^${chainprefix}${typeprefix}rtlWebinterface=" /mnt/hdd/raspiblitz.conf; then
|
||||
echo "${chainprefix}${typeprefix}rtlWebinterface=off" >> /mnt/hdd/raspiblitz.conf
|
||||
fi
|
||||
|
||||
# stop services
|
||||
echo "# making sure services are not running"
|
||||
sudo systemctl stop RTL 2>/dev/null
|
||||
sudo systemctl stop ${chainprefix}${typeprefix}RTL 2>/dev/null
|
||||
|
||||
function configRTL() {
|
||||
|
||||
if [ $LNTYPE = lnd ];then
|
||||
echo "# Make sure rtl is member of lndadmin"
|
||||
sudo /usr/sbin/usermod --append --groups lndadmin rtl
|
||||
SWAPSERVERPORT=8443
|
||||
if [ "$(grep -Ec "(loop=|lit=)" < /mnt/hdd/raspiblitz.conf)" -gt 0 ];then
|
||||
if [ $lit = on ];then
|
||||
|
@ -83,6 +139,7 @@ function configRTL() {
|
|||
else
|
||||
echo "# No Loop or LiT is installed"
|
||||
fi
|
||||
fi
|
||||
|
||||
# prepare RTL-Config.json file
|
||||
echo "# RTL.conf"
|
||||
|
@ -96,6 +153,7 @@ function configRTL() {
|
|||
//Read data
|
||||
var data = require('/home/rtl/RTL/sample-RTL-Config.json');
|
||||
//Manipulate data
|
||||
data.port = '$RTLHTTP'
|
||||
data.nodes[0].lnNode = '$hostname'
|
||||
data.nodes[0].Authentication.macaroonPath = '/home/rtl/.lnd/data/chain/${network}/${chain}net/'
|
||||
data.nodes[0].Authentication.configPath = '/home/rtl/.lnd/lnd.conf';
|
||||
|
@ -115,20 +173,23 @@ EOF
|
|||
|
||||
# switch on
|
||||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
||||
echo "# INSTALL RTL"
|
||||
echo "# Installing the RTL for ${LNTYPE} ${CHAIN}"
|
||||
|
||||
isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
|
||||
isInstalled=$(sudo ls /etc/systemd/system/${chainprefix}${typeprefix}RTL.service 2>/dev/null | grep -c "${chainprefix}${typeprefix}RTL.service")
|
||||
if ! [ ${isInstalled} -eq 0 ]; then
|
||||
echo "# RTL already installed."
|
||||
echo "# OK, the ${chainprefix}${typeprefix}RTL.service is already installed."
|
||||
else
|
||||
# check and install NodeJS
|
||||
/home/admin/config.scripts/bonus.nodejs.sh on
|
||||
|
||||
# create rtl user
|
||||
if [ $(compgen -u | grep -c rtl) -eq 0 ];then
|
||||
sudo adduser --disabled-password --gecos "" rtl || exit 1
|
||||
fi
|
||||
|
||||
echo "# Make sure rtl is member of lndadmin"
|
||||
sudo /usr/sbin/usermod --append --groups lndadmin rtl
|
||||
if [ -f /home/rtl/RTL/rtl.js ];then
|
||||
echo "# OK - the RTL code is already present"
|
||||
else
|
||||
|
||||
echo "# Make sure symlink to central app-data directory exists"
|
||||
if ! [[ -L "/home/rtl/.lnd" ]]; then
|
||||
|
@ -153,7 +214,7 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
|||
echo "# ABORT - RTL install"
|
||||
exit 1
|
||||
fi
|
||||
echo ""
|
||||
echo
|
||||
|
||||
# install
|
||||
echo "# Run: npm install"
|
||||
|
@ -166,36 +227,22 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
|||
echo "# OK - RTL install looks good"
|
||||
echo
|
||||
fi
|
||||
|
||||
# setup nginx symlinks
|
||||
if ! [ -f /etc/nginx/sites-available/rtl_ssl.conf ]; then
|
||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-available/rtl_ssl.conf
|
||||
fi
|
||||
if ! [ -f /etc/nginx/sites-available/rtl_tor.conf ]; then
|
||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor.conf /etc/nginx/sites-available/rtl_tor.conf
|
||||
fi
|
||||
if ! [ -f /etc/nginx/sites-available/rtl_tor_ssl.conf ]; then
|
||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor_ssl.conf /etc/nginx/sites-available/rtl_tor_ssl.conf
|
||||
fi
|
||||
sudo ln -sf /etc/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-enabled/
|
||||
sudo ln -sf /etc/nginx/sites-available/rtl_tor.conf /etc/nginx/sites-enabled/
|
||||
sudo ln -sf /etc/nginx/sites-available/rtl_tor_ssl.conf /etc/nginx/sites-enabled/
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
|
||||
echo "# Updating Firewall"
|
||||
sudo ufw allow 3000 comment 'RTL HTTP'
|
||||
sudo ufw allow 3001 comment 'RTL HTTPS'
|
||||
sudo ufw allow ${RTLHTTP} comment "${chainprefix}${typeprefix}RTL HTTP"
|
||||
sudo ufw allow $((RTLHTTP+1)) comment "${chainprefix}${typeprefix}RTL HTTPS"
|
||||
echo
|
||||
|
||||
if [ $LNTYPE = lnd ];then
|
||||
echo "# Install service"
|
||||
echo "# Install RTL systemd for ${network} on ${chain}"
|
||||
cat > /home/admin/RTL.service <<EOF
|
||||
# Systemd unit for RTL
|
||||
# /etc/systemd/system/RTL.service
|
||||
cat > /home/admin/${chainprefix}${typeprefix}RTL.service <<EOF
|
||||
# Systemd unit for ${chainprefix}${typeprefix}RTL
|
||||
# /etc/systemd/system/${chainprefix}${typeprefix}RTL.service
|
||||
|
||||
[Unit]
|
||||
Description=RTL daemon
|
||||
Description=${chainprefix}${typeprefix}RTL daemon
|
||||
Wants=lnd.service
|
||||
After=lnd.service
|
||||
|
||||
|
@ -211,30 +258,94 @@ StandardError=journal
|
|||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
sudo mv /home/admin/${chainprefix}${typeprefix}RTL.service /etc/systemd/system/${chainprefix}${typeprefix}RTL.service
|
||||
sudo sed -i "s|chain/bitcoin/mainnet|chain/${network}/${CHAIN}|" /etc/systemd/system/${chainprefix}${typeprefix}RTL.service
|
||||
sudo chown root:root /etc/systemd/system/${chainprefix}${typeprefix}RTL.service
|
||||
|
||||
elif [ $LNTYPE = cln ];then
|
||||
|
||||
# clnrest
|
||||
/home/admin/config.scripts/bonus.clnrest.sh on ${CHAIN}
|
||||
|
||||
echo "
|
||||
# Systemd unit for ${chainprefix}${typeprefix}RTL
|
||||
# /etc/systemd/system/${chainprefix}${typeprefix}RTL.service
|
||||
|
||||
[Unit]
|
||||
Description=${chainprefix}${typeprefix}RTL daemon
|
||||
Wants=${chainprefix}lightning.service
|
||||
After=${chainprefix}lightning.service
|
||||
|
||||
[Service]
|
||||
Environment=\"PORT=$RTLHTTP\"
|
||||
Environment=\"LN_IMPLEMENTATION=CLT\"
|
||||
Environment=\"LN_SERVER_URL=https://localhost:${portprefix}6100\"
|
||||
Environment=\"CONFIG_PATH=/home/bitcoin/.lightning/${chainprefix}config\"
|
||||
Environment=\"MACAROON_PATH=/home/bitcoin/c-lightning-REST/certs\"
|
||||
ExecStart=/usr/bin/node /home/rtl/RTL/rtl
|
||||
User=rtl
|
||||
Restart=always
|
||||
TimeoutSec=120
|
||||
RestartSec=30
|
||||
StandardOutput=null
|
||||
StandardError=journal
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
" | sudo tee /etc/systemd/system/${chainprefix}${typeprefix}RTL.service
|
||||
|
||||
sudo mv /home/admin/RTL.service /etc/systemd/system/RTL.service
|
||||
sudo sed -i "s|chain/bitcoin/mainnet|chain/${network}/${chain}net|" /etc/systemd/system/RTL.service
|
||||
sudo chown root:root /etc/systemd/system/RTL.service
|
||||
sudo systemctl enable RTL
|
||||
echo "OK - the RTL service is now enabled"
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "# Setup nginx symlinks"
|
||||
if ! [ -f /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_ssl.conf ]; then
|
||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_ssl.conf
|
||||
fi
|
||||
if ! [ -f /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor.conf ]; then
|
||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor.conf /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor.conf
|
||||
fi
|
||||
if ! [ -f /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor_ssl.conf ]; then
|
||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor_ssl.conf /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor_ssl.conf
|
||||
fi
|
||||
|
||||
echo "# Set ports for Nginx"
|
||||
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_ssl.conf
|
||||
sudo sed -i "s/3001/$((RTLHTTP+1))/g" /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_ssl.conf
|
||||
|
||||
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor.conf
|
||||
sudo sed -i "s/3002/$((RTLHTTP+2))/g" /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor.conf
|
||||
|
||||
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor_ssl.conf
|
||||
sudo sed -i "s/3003/$((RTLHTTP+3))/g" /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor_ssl.conf
|
||||
|
||||
sudo ln -sf /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_ssl.conf /etc/nginx/sites-enabled/
|
||||
sudo ln -sf /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor.conf /etc/nginx/sites-enabled/
|
||||
sudo ln -sf /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor_ssl.conf /etc/nginx/sites-enabled/
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
|
||||
configRTL
|
||||
|
||||
# setting value in raspi blitz config
|
||||
sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=on/g" /mnt/hdd/raspiblitz.conf
|
||||
sudo sed -i "s/^${chainprefix}${typeprefix}rtlWebinterface=.*/${chainprefix}${typeprefix}rtlWebinterface=on/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# Hidden Service for RTL if Tor is active
|
||||
if [ "${runBehindTor}" = "on" ]; then
|
||||
# make sure to keep in sync with internet.tor.sh script
|
||||
/home/admin/config.scripts/internet.hiddenservice.sh RTL 80 3002 443 3003
|
||||
/home/admin/config.scripts/internet.hiddenservice.sh ${chainprefix}${typeprefix}RTL 80 $((RTLHTTP+2)) 443 $((RTLHTTP+3))
|
||||
fi
|
||||
|
||||
sudo systemctl enable ${chainprefix}${typeprefix}RTL
|
||||
echo "# OK - the ${chainprefix}${typeprefix}RTL.service is now enabled"
|
||||
|
||||
source /home/admin/raspiblitz.info
|
||||
if [ "${state}" == "ready" ]; then
|
||||
echo "# OK - the RTL.service is enabled, system is ready so starting service"
|
||||
sudo systemctl start RTL
|
||||
echo "# OK - system is ready so starting service"
|
||||
sudo systemctl start ${chainprefix}${typeprefix}RTL
|
||||
echo "# Monitor with:"
|
||||
echo "sudo journalctl -f -u ${chainprefix}${typeprefix}RTL"
|
||||
else
|
||||
echo "# OK - the RTL.service is enabled, to start manually use: 'sudo systemctl start RTL'"
|
||||
echo "# OK - To start manually use: 'sudo systemctl start RTL'"
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
@ -243,38 +354,45 @@ fi
|
|||
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
||||
|
||||
# setting value in raspi blitz config
|
||||
sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=off/g" /mnt/hdd/raspiblitz.conf
|
||||
sudo sed -i "s/^${chainprefix}${typeprefix}rtlWebinterface=.*/${chainprefix}${typeprefix}rtlWebinterface=off/g" /mnt/hdd/raspiblitz.conf
|
||||
|
||||
# remove nginx symlinks
|
||||
sudo rm -f /etc/nginx/sites-enabled/rtl_ssl.conf
|
||||
sudo rm -f /etc/nginx/sites-enabled/rtl_tor.conf
|
||||
sudo rm -f /etc/nginx/sites-enabled/rtl_tor_ssl.conf
|
||||
sudo rm -f /etc/nginx/sites-available/rtl_ssl.conf
|
||||
sudo rm -f /etc/nginx/sites-available/rtl_tor.conf
|
||||
sudo rm -f /etc/nginx/sites-available/rtl_tor_ssl.conf
|
||||
sudo rm -f /etc/nginx/sites-enabled/${chainprefix}${typeprefix}rtl_ssl.conf
|
||||
sudo rm -f /etc/nginx/sites-enabled/${chainprefix}${typeprefix}rtl_tor.conf
|
||||
sudo rm -f /etc/nginx/sites-enabled/${chainprefix}${typeprefix}rtl_tor_ssl.conf
|
||||
sudo rm -f /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_ssl.conf
|
||||
sudo rm -f /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor.conf
|
||||
sudo rm -f /etc/nginx/sites-available/${chainprefix}${typeprefix}rtl_tor_ssl.conf
|
||||
sudo nginx -t
|
||||
sudo systemctl reload nginx
|
||||
|
||||
# Hidden Service if Tor is active
|
||||
if [ "${runBehindTor}" = "on" ]; then
|
||||
/home/admin/config.scripts/internet.hiddenservice.sh off RTL
|
||||
/home/admin/config.scripts/internet.hiddenservice.sh off ${chainprefix}${typeprefix}RTL
|
||||
fi
|
||||
|
||||
isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
|
||||
isInstalled=$(sudo ls /etc/systemd/system/${chainprefix}${typeprefix}RTL.service 2>/dev/null | grep -c "${chainprefix}${typeprefix}RTL.service")
|
||||
if [ ${isInstalled} -eq 1 ]; then
|
||||
echo "# REMOVING RTL"
|
||||
sudo systemctl disable RTL
|
||||
sudo rm /etc/systemd/system/RTL.service
|
||||
# delete user and home directory
|
||||
echo "# Removing the RTL for ${LNTYPE} ${CHAIN}"
|
||||
sudo systemctl disable ${chainprefix}${typeprefix}RTL
|
||||
sudo rm /etc/systemd/system/${chainprefix}${typeprefix}RTL.service
|
||||
if [ $LNTYPE = cln ];then
|
||||
/home/admin/config.scripts/bonus.clnrest.sh off ${CHAIN}
|
||||
fi
|
||||
if [ "$(echo "$@" | grep -c purge)" -gt 0 ];then
|
||||
echo "# Removing the binaries"
|
||||
echo "# Delete user and home directory"
|
||||
sudo userdel -rf rtl
|
||||
echo "# OK RTL removed."
|
||||
fi
|
||||
|
||||
echo "# OK ${chainprefix}${typeprefix}RTL removed."
|
||||
else
|
||||
echo "# RTL is not installed."
|
||||
echo "# ${chainprefix}${typeprefix}RTL is not installed."
|
||||
fi
|
||||
|
||||
# close ports on firewall
|
||||
sudo ufw deny 3000
|
||||
sudo ufw deny 3001
|
||||
sudo ufw deny ${RTLHTTP}
|
||||
sudo ufw deny $((RTLHTTP+1))
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue