mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-27 12:06:36 +02:00
refactoring RTL install script
This commit is contained in:
@@ -8,15 +8,13 @@ source /mnt/hdd/raspiblitz.conf
|
|||||||
|
|
||||||
# command info
|
# command info
|
||||||
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
||||||
echo "# config script to switch the RideTheLightning WebGUI on, off or update"
|
echo "# config script for RideTheLightning $RTLVERSION WebInterface"
|
||||||
echo
|
|
||||||
echo "# bonus.rtl.sh [on|off|menu|config] <lnd|cln> <mainnet|testnet|signet>"
|
|
||||||
echo "# able to run intances for lnd and cln parallel"
|
echo "# able to run intances for lnd and cln parallel"
|
||||||
echo "# lnd mainnet and testnet can run parallel"
|
echo "# lnd mainnet and testnet can run parallel"
|
||||||
echo "# cln can only have one network active at a time"
|
echo "# cln can only have one network active at a time"
|
||||||
echo
|
echo "# bonus.rtl.sh [on|off|menu] <lnd|cln> <mainnet|testnet|signet>"
|
||||||
echo "# bonus.rtl.sh update"
|
echo "# bonus.rtl.sh connect-services"
|
||||||
echo "# installs the version $RTLVERSION by default"
|
echo "# bonus.rtl.sh prestart <mainnet|testnet|signet>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -24,7 +22,7 @@ echo "# Running: 'bonus.rtl.sh $*'"
|
|||||||
|
|
||||||
# LNTYPE is lnd | cln
|
# LNTYPE is lnd | cln
|
||||||
LNTYPE=$2
|
LNTYPE=$2
|
||||||
if [ "${LNTYPE}" != "lnd" ] && [ "${LNTYPE}" != "cln" ]; then
|
if [ "${LNTYPE}" != "" ] && [ "${LNTYPE}" != "lnd" ] && [ "${LNTYPE}" != "cln" ]; then
|
||||||
echo "# ${LNTYPE} is not a supported LNTYPE"
|
echo "# ${LNTYPE} is not a supported LNTYPE"
|
||||||
echo "err='not supported parameter'"
|
echo "err='not supported parameter'"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -33,7 +31,7 @@ echo "# LNTYPE(${LNTYPE})"
|
|||||||
|
|
||||||
# CHAIN is signet | testnet | mainnet
|
# CHAIN is signet | testnet | mainnet
|
||||||
CHAIN=$3
|
CHAIN=$3
|
||||||
if [ ${CHAIN} != testnet ] && [ ${CHAIN} != mainnet ] && [ ${CHAIN} != signet ]; then
|
if [ "${CHAIN}" != "" ] && [ "${CHAIN}" != "testnet" ] && [ "${CHAIN}" != "mainnet" ] && [ "${CHAIN}" != "signet" ]; then
|
||||||
echo "# ${CHAIN} is not a supported CHAIN"
|
echo "# ${CHAIN} is not a supported CHAIN"
|
||||||
echo "err='not supported parameter'"
|
echo "err='not supported parameter'"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -67,7 +65,7 @@ echo "# typeprefix(${typeprefix})"
|
|||||||
|
|
||||||
# construct needed varibale elements
|
# construct needed varibale elements
|
||||||
configEntry="${netprefix}${typeprefix}rtlWebinterface"
|
configEntry="${netprefix}${typeprefix}rtlWebinterface"
|
||||||
systemdService="${netprefix}${typeprefix}RTL.service"
|
systemdService="${netprefix}${typeprefix}RTL"
|
||||||
echo "# configEntry(${configEntry})"
|
echo "# configEntry(${configEntry})"
|
||||||
echo "# systemdService(${systemdService})"
|
echo "# systemdService(${systemdService})"
|
||||||
|
|
||||||
@@ -78,6 +76,12 @@ echo "# systemdService(${systemdService})"
|
|||||||
# show info menu
|
# show info menu
|
||||||
if [ "$1" = "menu" ]; then
|
if [ "$1" = "menu" ]; then
|
||||||
|
|
||||||
|
# check that parameters are set
|
||||||
|
if [ "${LNTYPE}" == "" ] || [ "${CHAIN}" == "" ]; then
|
||||||
|
echo "# missing parameter"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# get network info
|
# get network info
|
||||||
localip=$(hostname -I | awk '{print $1}')
|
localip=$(hostname -I | awk '{print $1}')
|
||||||
toraddress=$(sudo cat /mnt/hdd/tor/${netprefix}${typeprefix}RTL/hostname 2>/dev/null)
|
toraddress=$(sudo cat /mnt/hdd/tor/${netprefix}${typeprefix}RTL/hostname 2>/dev/null)
|
||||||
@@ -122,38 +126,54 @@ fi
|
|||||||
echo "# making sure services are not running"
|
echo "# making sure services are not running"
|
||||||
sudo systemctl stop ${systemdService} 2>/dev/null
|
sudo systemctl stop ${systemdService} 2>/dev/null
|
||||||
|
|
||||||
# switch on
|
|
||||||
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
|
||||||
echo "# Installing RTL for ${LNTYPE} ${CHAIN}"
|
|
||||||
|
|
||||||
isInstalled=$(sudo ls /etc/systemd/system/${systemdService} 2>/dev/null | grep -c "${systemdService}")
|
##########################
|
||||||
if ! [ ${isInstalled} -eq 0 ]; then
|
# ON
|
||||||
|
#########################
|
||||||
|
|
||||||
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
||||||
|
|
||||||
|
# check that parameters are set
|
||||||
|
if [ "${LNTYPE}" == "" ] || [ "${CHAIN}" == "" ]; then
|
||||||
|
echo "# missing parameter"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# check that is installed
|
||||||
|
isInstalled=$(sudo ls /etc/systemd/system/${systemdService}.service 2>/dev/null | grep -c "${systemdService}.service")
|
||||||
|
if [ ${isInstalled} -eq 1 ]; then
|
||||||
echo "# OK, the ${netprefix}${typeprefix}RTL.service is already installed."
|
echo "# OK, the ${netprefix}${typeprefix}RTL.service is already installed."
|
||||||
else
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "# Installing RTL for ${LNTYPE} ${CHAIN}"
|
||||||
|
|
||||||
# check and install NodeJS
|
# check and install NodeJS
|
||||||
/home/admin/config.scripts/bonus.nodejs.sh on
|
/home/admin/config.scripts/bonus.nodejs.sh on
|
||||||
|
|
||||||
# create rtl user
|
# create rtl user (one for all instances)
|
||||||
if [ $(compgen -u | grep -c rtl) -eq 0 ];then
|
if [ $(compgen -u | grep -c rtl) -eq 0 ];then
|
||||||
sudo adduser --disabled-password --gecos "" rtl || exit 1
|
sudo adduser --disabled-password --gecos "" rtl || exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "# Make sure symlink to central app-data directory exists"
|
echo "# Make sure symlink to central app-data directory exists"
|
||||||
if ! [[ -L "/home/rtl/.lnd" ]]; then
|
if ! [[ -L "/home/rtl/.lnd" ]]; then
|
||||||
sudo rm -rf "/home/rtl/.lnd" # not a symlink.. delete it silently
|
sudo rm -rf "/home/rtl/.lnd" 2>/dev/null # not a symlink.. delete it silently
|
||||||
sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/rtl/.lnd" # and create symlink
|
sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/rtl/.lnd" # and create symlink
|
||||||
fi
|
fi
|
||||||
|
if [ "${LNTYPE}" == "lnd"]; then
|
||||||
|
# for LND make sure user rtl is allowed to access admin macaroons
|
||||||
|
echo "# adding user rtl to group lndadmin"
|
||||||
|
sudo /usr/sbin/usermod --append --groups lndadmin rtl
|
||||||
|
fi
|
||||||
|
|
||||||
|
# source code (one place for all instances)
|
||||||
if [ -f /home/rtl/RTL/rtl ];then
|
if [ -f /home/rtl/RTL/rtl ];then
|
||||||
echo "# OK - the RTL code is already present"
|
echo "# OK - the RTL code is already present - just update"
|
||||||
cd /home/rtl/RTL
|
cd /home/rtl/RTL
|
||||||
sudo -u rtl git pull
|
sudo -u rtl git pull
|
||||||
|
|
||||||
else
|
else
|
||||||
# download source code and set to tag release
|
# download source code and set to tag release
|
||||||
echo "# Get the RTL Source Code"
|
echo "# Get the RTL Source Code"
|
||||||
rm -rf /home/admin/RTL 2>/dev/null
|
|
||||||
sudo -u rtl rm -rf /home/rtl/RTL 2>/dev/null
|
sudo -u rtl rm -rf /home/rtl/RTL 2>/dev/null
|
||||||
sudo -u rtl git clone https://github.com/ShahanaFarooqui/RTL.git /home/rtl/RTL
|
sudo -u rtl git clone https://github.com/ShahanaFarooqui/RTL.git /home/rtl/RTL
|
||||||
cd /home/rtl/RTL
|
cd /home/rtl/RTL
|
||||||
@@ -166,8 +186,8 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
|||||||
if [ -d "/home/rtl/RTL" ]; then
|
if [ -d "/home/rtl/RTL" ]; then
|
||||||
echo "# OK - RTL code copy looks good"
|
echo "# OK - RTL code copy looks good"
|
||||||
else
|
else
|
||||||
echo "# FAIL - code copy did not run correctly"
|
echo "# FAIL - RTL code not available"
|
||||||
echo "# ABORT - RTL install"
|
echo "err='code download falied'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
@@ -185,25 +205,22 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "# Updating Firewall"
|
echo "# Updating Firewall"
|
||||||
sudo ufw allow ${RTLHTTP} comment "${netprefix}${typeprefix}RTL HTTP"
|
sudo ufw allow ${RTLHTTP} comment "${systemdService} HTTP"
|
||||||
sudo ufw allow $((RTLHTTP+1)) comment "${netprefix}${typeprefix}RTL HTTPS"
|
sudo ufw allow $((RTLHTTP+1)) comment "${systemdService} HTTPS"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if [ $LNTYPE = lnd ];then
|
echo "# Create Systemd Service: ${systemdService}.service (Template)"
|
||||||
echo "# Install service"
|
|
||||||
echo "# Install RTL systemd for ${network} on ${chain}"
|
|
||||||
echo "
|
echo "
|
||||||
# Systemd unit for ${netprefix}${typeprefix}RTL
|
# Systemd unit for ${systemdService}
|
||||||
# /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
|
||||||
|
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=${netprefix}${typeprefix}RTL daemon
|
Description=${systemdService} Webinterface
|
||||||
Wants=lnd.service
|
Wants=
|
||||||
After=lnd.service
|
After=
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Environment=\"RTL_CONFIG_PATH=/home/rtl/${netprefix}${typeprefix}RTL/\"
|
Environment=\"RTL_CONFIG_PATH=/home/rtl/${systemdService}/\"
|
||||||
ExecStartPre=-/home/admin/config.scripts/bonus.rtl.sh config ${LNTYPE} ${CHAIN}
|
ExecStartPre=-/home/admin/config.scripts/bonus.rtl.sh prestart ${LNTYPE} ${CHAIN}
|
||||||
ExecStart=/usr/bin/node /home/rtl/RTL/rtl
|
ExecStart=/usr/bin/node /home/rtl/RTL/rtl
|
||||||
User=rtl
|
User=rtl
|
||||||
Restart=always
|
Restart=always
|
||||||
@@ -220,82 +237,25 @@ PrivateDevices=true
|
|||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
" | sudo tee /home/admin/${netprefix}${typeprefix}RTL.service
|
" | sudo tee /etc/systemd/system/${systemdService}.service
|
||||||
sudo mv /home/admin/${netprefix}${typeprefix}RTL.service /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
sudo chown root:root /etc/systemd/system/${systemdService}.service
|
||||||
sudo sed -i "s|chain/bitcoin/mainnet|chain/${network}/${CHAIN}|" /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
|
||||||
sudo chown root:root /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
|
||||||
|
|
||||||
elif [ $LNTYPE = cln ];then
|
# adapt systemd service template for LND
|
||||||
# clnrest
|
if [ "${LNTYPE}" == "lnd" ]; then
|
||||||
/home/admin/config.scripts/cln.rest.sh on ${CHAIN}
|
echo "# modifying ${systemdService}.service for LND"
|
||||||
echo "
|
sudo sed -i "s/^Wants=.*/Wants=${netprefix}lnd.service/g" /etc/systemd/system/${systemdService}.service
|
||||||
# Systemd unit for ${netprefix}${typeprefix}RTL
|
sudo sed -i "s/^After=.*/After=${netprefix}lnd.service/g" /etc/systemd/system/${systemdService}.service
|
||||||
# /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
|
||||||
|
|
||||||
[Unit]
|
|
||||||
Description=${netprefix}${typeprefix}RTL daemon
|
|
||||||
Wants=${netprefix}lightningd.service
|
|
||||||
After=${netprefix}lightningd.service
|
|
||||||
|
|
||||||
[Service]
|
|
||||||
Environment=\"RTL_CONFIG_PATH=/home/rtl/${netprefix}RTL/\"
|
|
||||||
Environment=\"PORT=$RTLHTTP\"
|
|
||||||
Environment=\"LN_IMPLEMENTATION=CLT\"
|
|
||||||
Environment=\"LN_SERVER_URL=https://localhost:${portprefix}6100\"
|
|
||||||
Environment=\"CONFIG_PATH=/home/bitcoin/.lightning/${netprefix}config\"
|
|
||||||
Environment=\"MACAROON_PATH=/home/bitcoin/c-lightning-REST/certs\"
|
|
||||||
ExecStartPre=-/home/admin/config.scripts/bonus.rtl.sh config ${LNTYPE} ${CHAIN}
|
|
||||||
ExecStart=/usr/bin/node /home/rtl/RTL/rtl
|
|
||||||
User=rtl
|
|
||||||
Restart=always
|
|
||||||
TimeoutSec=120
|
|
||||||
RestartSec=30
|
|
||||||
StandardOutput=null
|
|
||||||
StandardError=journal
|
|
||||||
|
|
||||||
# Hardening measures
|
|
||||||
PrivateTmp=true
|
|
||||||
ProtectSystem=full
|
|
||||||
NoNewPrivileges=true
|
|
||||||
PrivateDevices=true
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=multi-user.target
|
|
||||||
" | sudo tee /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "# Setup nginx symlinks"
|
# adapt systemd service template for LND
|
||||||
if ! [ -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf ]; then
|
if [ "${LNTYPE}" == "cln" ]; then
|
||||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
echo "# modifying ${systemdService}.service for CLN"
|
||||||
fi
|
sudo sed -i "s/^Wants=.*/Wants=${netprefix}lightningd.service/g" /etc/systemd/system/${systemdService}.service
|
||||||
if ! [ -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf ]; then
|
sudo sed -i "s/^After=.*/After=${netprefix}lightningd.service/g" /etc/systemd/system/${systemdService}.service
|
||||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor.conf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
|
||||||
fi
|
|
||||||
if ! [ -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf ]; then
|
|
||||||
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor_ssl.conf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "# Set ports for Nginx"
|
# Note about RTL config file
|
||||||
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
echo "# NOTE: the RTL config for this instance will be done on the fly as a prestart in systemd"
|
||||||
sudo sed -i "s/3001/$((RTLHTTP+1))/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
|
||||||
|
|
||||||
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
|
||||||
sudo sed -i "s/3002/$((RTLHTTP+2))/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
|
||||||
|
|
||||||
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
|
||||||
sudo sed -i "s/3003/$((RTLHTTP+3))/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
|
||||||
|
|
||||||
sudo ln -sf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf /etc/nginx/sites-enabled/
|
|
||||||
sudo ln -sf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf /etc/nginx/sites-enabled/
|
|
||||||
sudo ln -sf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf /etc/nginx/sites-enabled/
|
|
||||||
sudo nginx -t
|
|
||||||
sudo systemctl reload nginx
|
|
||||||
|
|
||||||
/home/admin/config.scripts/bonus.rtl.sh config $2 $3
|
|
||||||
|
|
||||||
# setting value in raspi blitz config
|
|
||||||
sudo sed -i "s/^${netprefix}${typeprefix}rtlWebinterface=.*/${netprefix}${typeprefix}rtlWebinterface=on/g" /mnt/hdd/raspiblitz.conf
|
|
||||||
|
|
||||||
# Hidden Service for RTL if Tor is active
|
# Hidden Service for RTL if Tor is active
|
||||||
if [ "${runBehindTor}" = "on" ]; then
|
if [ "${runBehindTor}" = "on" ]; then
|
||||||
@@ -303,59 +263,219 @@ WantedBy=multi-user.target
|
|||||||
/home/admin/config.scripts/internet.hiddenservice.sh ${netprefix}${typeprefix}RTL 80 $((RTLHTTP+2)) 443 $((RTLHTTP+3))
|
/home/admin/config.scripts/internet.hiddenservice.sh ${netprefix}${typeprefix}RTL 80 $((RTLHTTP+2)) 443 $((RTLHTTP+3))
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sudo systemctl enable ${netprefix}${typeprefix}RTL
|
# nginx configuration
|
||||||
echo "# OK - the ${netprefix}${typeprefix}RTL.service is now enabled"
|
echo "# Setup nginx confs"
|
||||||
|
sudo cp /home/admin/assets/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
||||||
|
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor.conf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
||||||
|
sudo cp /home/admin/assets/nginx/sites-available/rtl_tor_ssl.conf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
||||||
|
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
||||||
|
sudo sed -i "s/3001/$((RTLHTTP+1))/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
||||||
|
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
||||||
|
sudo sed -i "s/3002/$((RTLHTTP+2))/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
||||||
|
sudo sed -i "s/3000/$RTLHTTP/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
||||||
|
sudo sed -i "s/3003/$((RTLHTTP+3))/g" /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
||||||
|
sudo ln -sf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf /etc/nginx/sites-enabled/
|
||||||
|
sudo ln -sf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf /etc/nginx/sites-enabled/
|
||||||
|
sudo ln -sf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf /etc/nginx/sites-enabled/
|
||||||
|
sudo nginx -t
|
||||||
|
sudo systemctl reload nginx
|
||||||
|
|
||||||
source /home/admin/raspiblitz.info
|
# run config as root to connect prepare services (lit, pool, ...)
|
||||||
if [ "${state}" == "ready" ]; then
|
sudo /home/admin/config.scripts/bonus.rtl.sh connect-services
|
||||||
echo "# OK - system is ready so starting service"
|
|
||||||
sudo systemctl start ${netprefix}${typeprefix}RTL
|
# raspiblitz.config
|
||||||
echo "# Monitor with:"
|
sudo sed -i "s/^${configEntry}=.*/${configEntry}=on/g" /mnt/hdd/raspiblitz.conf
|
||||||
echo "sudo journalctl -f -u ${netprefix}${typeprefix}RTL"
|
|
||||||
else
|
sudo systemctl enable ${systemdService}
|
||||||
echo "# OK - To start manually use: 'sudo systemctl start RTL'"
|
sudo systemctl start ${systemdService}
|
||||||
fi
|
echo "# OK - the ${systemdService}.service is now enabled & started"
|
||||||
|
echo "# Monitor with: sudo journalctl -f -u sudo journalctl -f -u"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# CONNECT SERVICES
|
||||||
|
# will be called by lit or loop services to make sure services
|
||||||
|
# are connected or on RTL install/update
|
||||||
|
#########################
|
||||||
|
|
||||||
|
if [ "$1" = "connect-services" ]; then
|
||||||
|
|
||||||
|
if [ "$USER" != "root" ] && [ "$USER" != "admin" ]; then
|
||||||
|
echo "# FAIL: run as user root or admin"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "## RTL CONNECT-SERVICES (when run as admin or root)"
|
||||||
|
|
||||||
|
# LIT & LOOP Swap Server
|
||||||
|
echo "# checking of swap server ..."
|
||||||
|
if [ "${lit}" = "on" ]; then
|
||||||
|
echo "# LIT DETECTED"
|
||||||
|
echo "# Add the rtl user to the lit group"
|
||||||
|
sudo /usr/sbin/usermod --append --groups lit rtl
|
||||||
|
echo "# Symlink the lit-loop.macaroon"
|
||||||
|
sudo rm -rf "/home/rtl/.loop" # delete symlink
|
||||||
|
sudo ln -s "/home/lit/.loop/" "/home/rtl/.loop" # create symlink
|
||||||
|
echo "# Make the loop macaroon group readable"
|
||||||
|
sudo chmod 640 /home/rtl/.loop/mainnet/macaroons.db
|
||||||
|
elif [ "${loop}" = "on" ]; then
|
||||||
|
echo "# LOOP DETECTED"
|
||||||
|
echo "# Add the rtl user to the loop group"
|
||||||
|
sudo /usr/sbin/usermod --append --groups loop rtl
|
||||||
|
echo "# Symlink the loop.macaroon"
|
||||||
|
sudo rm -rf "/home/rtl/.loop" # delete symlink
|
||||||
|
sudo ln -s "/home/loop/.loop/" "/home/rtl/.loop" # create symlink
|
||||||
|
echo "# Make the loop macaroon group readable"
|
||||||
|
sudo chmod 640 /home/rtl/.loop/mainnet/macaroons.db
|
||||||
|
else
|
||||||
|
echo "# No lit or loop single detected"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "# RTL CONNECT-SERVICES done"
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# PRESTART
|
||||||
|
# - will be called as prestart by systemd service (as user rtl)
|
||||||
|
#########################
|
||||||
|
|
||||||
|
if [ "$1" = "prestart" ]; then
|
||||||
|
|
||||||
|
# check that parameters are set
|
||||||
|
if [ "${LNTYPE}" == "" ] || [ "${CHAIN}" == "" ]; then
|
||||||
|
echo "# missing parameter"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# users need to be `rtl` so that it can be run by systemd as prestart (no SUDO available)
|
||||||
|
if [ "$USER" != "rtl" ]; then
|
||||||
|
echo "# FAIL: run as user rtl"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "## RTL PRESTART CONFIG (called by systemd prestart)"
|
||||||
|
|
||||||
|
# getting the up-to-date RPC password
|
||||||
|
RPCPASSWORD=$(cat /mnt/hdd/${network}/${network}.conf | grep "^rpcpassword=" | cut -d "=" -f2)
|
||||||
|
echo "# Using RPCPASSWORD(${RPCPASSWORD})"
|
||||||
|
|
||||||
|
# determine correct loop swap server port (lit over loop single)
|
||||||
|
if [ "${lit}" = "on" ]; then
|
||||||
|
echo "# use lit loop port"
|
||||||
|
SWAPSERVERPORT=8443
|
||||||
|
elif [ "${loop}" = "on" ]; then
|
||||||
|
echo "# use loop single instance port"
|
||||||
|
SWAPSERVERPORT=8081
|
||||||
|
else
|
||||||
|
echo "# No lit or loop single detected"
|
||||||
|
SWAPSERVERPORT=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
# prepare RTL-Config.json file
|
||||||
|
echo "# PREPARE /home/rtl/${systemdService}/RTL-Config.json"
|
||||||
|
# make and clean directory
|
||||||
|
mkdir -p /home/rtl/${systemdService}
|
||||||
|
rm -f /home/rtl/${systemdService}/RTL-Config.json 2>/dev/null
|
||||||
|
# copy template
|
||||||
|
cp /home/rtl/RTL/docs/Sample-RTL-Config.json /home/rtl/${systemdService}/RTL-Config.json
|
||||||
|
chmod 600 /home/rtl/${systemdService}/RTL-Config.json
|
||||||
|
|
||||||
|
# LND changes of config
|
||||||
|
if [ "${LNType}" == "lnd" ]; then
|
||||||
|
echo "# LND Config"
|
||||||
|
cat /home/rtl/${systemdService}/RTL-Config.json | \
|
||||||
|
jq ".port = \"${RTLHTTP}\"" | \
|
||||||
|
jq ".multiPass = \"${RPCPASSWORD}\"" | \
|
||||||
|
jq ".nodes[0].lnNode = \"${hostname}\"" | \
|
||||||
|
jq ".nodes[0].lnImplementation = \"LND\"" | \
|
||||||
|
jq ".nodes[0].Authentication.macaroonPath = \"/home/rtl/.lnd/data/chain/${network}/${CHAIN}/\"" | \
|
||||||
|
jq ".nodes[0].Authentication.configPath = \"/home/rtl/.lnd/${netprefix}lnd.conf\"" | \
|
||||||
|
jq ".nodes[0].Authentication.swapMacaroonPath = \"/home/rtl/.loop/${CHAIN}/\"" | \
|
||||||
|
jq ".nodes[0].Authentication.boltzMacaroonPath = \"/home/rtl/.boltz-lnd/macaroons/\"" | \
|
||||||
|
jq ".nodes[0].Settings.userPersona = \"OPERATOR\"" | \
|
||||||
|
jq ".nodes[0].nodes[0].Settings.channelBackupPath = \"/home/rtl/${systemdService}-SCB-backup-$hostname\"" | \
|
||||||
|
jq ".nodes[0].nodes[0].Settings.swapServerUrl = \"https://localhost:${SWAPSERVERPORT}\"" > /home/rtl/${systemdService}/RTL-Config.json.tmp
|
||||||
|
mv /home/rtl/${systemdService}/RTL-Config.json.tmp /home/rtl/${systemdService}/RTL-Config.json
|
||||||
|
fi
|
||||||
|
|
||||||
|
# C-Lightning changes of config
|
||||||
|
# https://github.com/Ride-The-Lightning/RTL/blob/master/docs/C-Lightning-setup.md
|
||||||
|
if [ "${LNType}" == "cln" ]; then
|
||||||
|
echo "# CLN Config"
|
||||||
|
cat /home/rtl/${systemdService}/RTL-Config.json | \
|
||||||
|
jq ".port = \"${RTLHTTP}\"" | \
|
||||||
|
jq ".multiPass = \"${RPCPASSWORD}\"" | \
|
||||||
|
jq ".nodes[0].lnNode = \"${hostname}\"" | \
|
||||||
|
jq ".nodes[0].lnImplementation = \"CLT\"" | \
|
||||||
|
jq ".nodes[0].Authentication.macaroonPath = \"/home/bitcoin/c-lightning-REST/certs\"" | \
|
||||||
|
jq ".nodes[0].Authentication.configPath = \"/home/bitcoin/.lightning/${netprefix}config\"" | \
|
||||||
|
jq ".nodes[0].Authentication.swapMacaroonPath = \"/home/rtl/.loop/${CHAIN}/\"" | \
|
||||||
|
jq ".nodes[0].Authentication.boltzMacaroonPath = \"/home/rtl/.boltz-lnd/macaroons/\"" | \
|
||||||
|
jq ".nodes[0].Settings.userPersona = \"OPERATOR\"" | \
|
||||||
|
jq ".nodes[0].Settings.lnServerUrl = \"https://localhost:${portprefix}6100\"" | \
|
||||||
|
jq ".nodes[0].nodes[0].Settings.channelBackupPath = \"/home/rtl/${systemdService}-SCB-backup-$hostname\"" | \
|
||||||
|
jq ".nodes[0].nodes[0].Settings.swapServerUrl = \"https://localhost:${SWAPSERVERPORT}\"" > /home/rtl/${systemdService}/RTL-Config.json.tmp
|
||||||
|
mv /home/rtl/${systemdService}/RTL-Config.json.tmp /home/rtl/${systemdService}/RTL-Config.json
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "# RTL prestart config done"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
##########################
|
||||||
|
# OFF
|
||||||
|
#########################
|
||||||
|
|
||||||
# switch off
|
# switch off
|
||||||
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
||||||
|
|
||||||
|
# check that parameters are set
|
||||||
|
if [ "${LNTYPE}" == "" ] || [ "${CHAIN}" == "" ]; then
|
||||||
|
echo "# missing parameter"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
# setting value in raspi blitz config
|
# setting value in raspi blitz config
|
||||||
sudo sed -i "s/^${netprefix}${typeprefix}rtlWebinterface=.*/${netprefix}${typeprefix}rtlWebinterface=off/g" /mnt/hdd/raspiblitz.conf
|
sudo sed -i "s/^${configEntry}=.*/${configEntry}=off/g" /mnt/hdd/raspiblitz.conf
|
||||||
|
|
||||||
# remove nginx symlinks
|
# remove nginx symlinks
|
||||||
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_ssl.conf
|
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_ssl.conf 2>/dev/null
|
||||||
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_tor.conf
|
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_tor.conf 2>/dev/null
|
||||||
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_tor_ssl.conf 2>/dev/null
|
||||||
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf 2>/dev/null
|
||||||
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf 2>/dev/null
|
||||||
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf 2>/dev/null
|
||||||
sudo nginx -t
|
sudo nginx -t
|
||||||
sudo systemctl reload nginx
|
sudo systemctl reload nginx
|
||||||
|
|
||||||
# Hidden Service if Tor is active
|
# Hidden Service if Tor is active
|
||||||
if [ "${runBehindTor}" = "on" ]; then
|
if [ "${runBehindTor}" = "on" ]; then
|
||||||
/home/admin/config.scripts/internet.hiddenservice.sh off ${netprefix}${typeprefix}RTL
|
/home/admin/config.scripts/internet.hiddenservice.sh off ${systemdService}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
isInstalled=$(sudo ls /etc/systemd/system/${netprefix}${typeprefix}RTL.service 2>/dev/null | grep -c "${netprefix}${typeprefix}RTL.service")
|
isInstalled=$(sudo ls /etc/systemd/system/${systemdService}.service 2>/dev/null | grep -c "${systemdService}.service")
|
||||||
if [ ${isInstalled} -eq 1 ]; then
|
if [ ${isInstalled} -eq 1 ]; then
|
||||||
|
|
||||||
echo "# Removing RTL for ${LNTYPE} ${CHAIN}"
|
echo "# Removing RTL for ${LNTYPE} ${CHAIN}"
|
||||||
sudo systemctl disable ${netprefix}${typeprefix}RTL
|
sudo systemctl disable ${systemdService}.service
|
||||||
sudo rm /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
sudo rm /etc/systemd/system/${systemdService}.service
|
||||||
if [ $LNTYPE = cln ];then
|
|
||||||
/home/admin/config.scripts/cln.rest.sh off ${CHAIN}
|
# only if 'purge' is an additional parameter (might otherwise other instances/services might need this)
|
||||||
fi
|
|
||||||
if [ "$(echo "$@" | grep -c purge)" -gt 0 ];then
|
if [ "$(echo "$@" | grep -c purge)" -gt 0 ];then
|
||||||
echo "# Removing the binaries"
|
echo "# Removing the binaries"
|
||||||
echo "# Delete user and home directory"
|
echo "# Delete user and home directory"
|
||||||
sudo userdel -rf rtl
|
sudo userdel -rf rtl
|
||||||
|
if [ $LNTYPE = cln ];then
|
||||||
|
/home/admin/config.scripts/cln.rest.sh off ${CHAIN}
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "# OK ${netprefix}${typeprefix}RTL removed."
|
echo "# OK ${systemdService} removed."
|
||||||
else
|
else
|
||||||
echo "# ${netprefix}${typeprefix}RTL is not installed."
|
echo "# ${systemdService} is not installed."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# close ports on firewall
|
# close ports on firewall
|
||||||
@@ -364,114 +484,51 @@ if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# config
|
# DEAKTIVATED FOR NOW:
|
||||||
if [ "$1" = "config" ]; then
|
# - parameter scheme is conflicting with setting all perfixes etc
|
||||||
echo "# CONFIG RTL"
|
# - also just updating to latest has high change of breaking
|
||||||
if [ $LNTYPE = lnd ]; then
|
#if [ "$1" = "update" ]; then
|
||||||
echo "# Make sure rtl is member of lndadmin"
|
# echo "# UPDATING RTL"
|
||||||
sudo /usr/sbin/usermod --append --groups lndadmin rtl
|
# cd /home/rtl/RTL
|
||||||
SWAPSERVERPORT=8443
|
# updateOption="$2"
|
||||||
if [ "$(grep -Ec "(loop=|lit=)" < /mnt/hdd/raspiblitz.conf)" -gt 0 ];then
|
# if [ ${#updateOption} -eq 0 ]; then
|
||||||
if [ $lit = on ];then
|
# # from https://github.com/apotdevin/thunderhub/blob/master/scripts/updateToLatest.sh
|
||||||
echo "# Add the rtl user to the lit group"
|
# # fetch latest master
|
||||||
sudo /usr/sbin/usermod --append --groups lit rtl
|
# sudo -u rtl git fetch
|
||||||
echo "# Symlink the lit-loop.macaroon"
|
# # unset $1
|
||||||
sudo rm -rf "/home/rtl/.loop" # delete symlink
|
# set --
|
||||||
sudo ln -s "/home/lit/.loop/" "/home/rtl/.loop" # create symlink
|
# UPSTREAM=${1:-'@{u}'}
|
||||||
SWAPSERVERPORT=8443
|
# LOCAL=$(git rev-parse @)
|
||||||
elif [ $loop = on ];then
|
# REMOTE=$(git rev-parse "$UPSTREAM")
|
||||||
echo "# Add the rtl user to the loop group"
|
# if [ $LOCAL = $REMOTE ]; then
|
||||||
sudo /usr/sbin/usermod --append --groups loop rtl
|
# TAG=$(git tag | sort -V | tail -1)
|
||||||
echo "# Symlink the loop.macaroon"
|
# echo "# You are up-to-date on version" $TAG
|
||||||
sudo rm -rf "/home/rtl/.loop" # delete symlink
|
# else
|
||||||
sudo ln -s "/home/loop/.loop/" "/home/rtl/.loop" # create symlink
|
# echo "# Pulling latest changes..."
|
||||||
SWAPSERVERPORT=8081
|
# sudo -u rtl git pull -p
|
||||||
fi
|
# echo "# Reset to the latest release tag"
|
||||||
echo "# Make the loop macaroon group readable"
|
# TAG=$(git tag | sort -V | tail -1)
|
||||||
sudo chmod 640 /home/rtl/.loop/mainnet/macaroons.db
|
# sudo -u rtl git reset --hard $TAG
|
||||||
else
|
# echo "# updating to the latest"
|
||||||
echo "# No Loop or LiT is installed"
|
# # https://github.com/Ride-The-Lightning/RTL#or-update-existing-dependencies
|
||||||
fi
|
# sudo -u rtl npm install --only=prod
|
||||||
fi
|
# echo "# Updated to version" $TAG
|
||||||
|
# fi
|
||||||
# prepare RTL-Config.json file
|
# elif [ "$updateOption" = "commit" ]; then
|
||||||
echo "# ${netprefix}${typeprefix}RTL/RTL.conf"
|
# echo "# updating to the latest commit in https://github.com/Ride-The-Lightning/RTL"
|
||||||
# change of config: https://github.com/Ride-The-Lightning/RTL/tree/v0.6.4
|
# sudo -u rtl git pull -p
|
||||||
sudo cp /home/rtl/RTL/docs/Sample-RTL-Config.json /home/admin/RTL-Config.json
|
# sudo -u rtl npm install --only=prod
|
||||||
sudo chown admin:admin /home/admin/RTL-Config.json
|
# currentRTLcommit=$(cd /home/rtl/RTL; git describe --tags)
|
||||||
sudo chmod 600 /home/admin/RTL-Config.json || exit 1
|
# echo "# Updated RTL to $currentRTLcommit"
|
||||||
PASSWORD_B=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcpassword | cut -c 13-)
|
# else
|
||||||
# modify sample-RTL-Config.json and save in RTL-Config.json
|
# echo "# Unknown option: $updateOption"
|
||||||
node > /home/admin/RTL-Config.json <<EOF
|
# fi
|
||||||
//Read data
|
#
|
||||||
var data = require('/home/rtl/RTL/docs/Sample-RTL-Config.json');
|
# echo
|
||||||
//Manipulate data
|
# echo "# Starting the RTL service ... "
|
||||||
data.port = '$RTLHTTP'
|
# sudo systemctl start RTL
|
||||||
data.nodes[0].lnNode = '$hostname'
|
# exit 0
|
||||||
data.nodes[0].Authentication.macaroonPath = '/home/rtl/.lnd/data/chain/${network}/${chain}net/'
|
#fi
|
||||||
data.nodes[0].Authentication.configPath = '/home/rtl/.lnd/${netprefix}lnd.conf';
|
|
||||||
data.nodes[0].Authentication.swapMacaroonPath = '/home/rtl/.loop/${chain}net/'
|
|
||||||
data.nodes[0].Authentication.boltzMacaroonPath = '/home/rtl/.boltz-lnd/macaroons/'
|
|
||||||
data.multiPass = '$PASSWORD_B';
|
|
||||||
data.nodes[0].Settings.userPersona = 'OPERATOR'
|
|
||||||
data.nodes[0].Settings.channelBackupPath = '/home/rtl/${netprefix}${typeprefix}RTL-SCB-backup-$hostname'
|
|
||||||
data.nodes[0].Settings.swapServerUrl = 'https://localhost:$SWAPSERVERPORT'
|
|
||||||
//Output data
|
|
||||||
console.log(JSON.stringify(data, null, 2));
|
|
||||||
EOF
|
|
||||||
echo "# creatking dir: /home/rtl/${netprefix}${typeprefix}RTL"
|
|
||||||
sudo -u rtl mkdir -p /home/rtl/${netprefix}${typeprefix}}RTL
|
|
||||||
sudo rm -f /home/rtl/${netprefix}${typeprefix}RTL/RTL-Config.json
|
|
||||||
sudo mv /home/admin/RTL-Config.json /home/rtl/${netprefix}${typeprefix}RTL/
|
|
||||||
sudo chown rtl:rtl /home/rtl/${netprefix}${typeprefix}RTL/RTL-Config.json
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# update
|
|
||||||
if [ "$1" = "update" ]; then
|
|
||||||
echo "# UPDATING RTL"
|
|
||||||
cd /home/rtl/RTL
|
|
||||||
updateOption="$2"
|
|
||||||
if [ ${#updateOption} -eq 0 ]; then
|
|
||||||
# from https://github.com/apotdevin/thunderhub/blob/master/scripts/updateToLatest.sh
|
|
||||||
# fetch latest master
|
|
||||||
sudo -u rtl git fetch
|
|
||||||
# unset $1
|
|
||||||
set --
|
|
||||||
UPSTREAM=${1:-'@{u}'}
|
|
||||||
LOCAL=$(git rev-parse @)
|
|
||||||
REMOTE=$(git rev-parse "$UPSTREAM")
|
|
||||||
if [ $LOCAL = $REMOTE ]; then
|
|
||||||
TAG=$(git tag | sort -V | tail -1)
|
|
||||||
echo "# You are up-to-date on version" $TAG
|
|
||||||
else
|
|
||||||
echo "# Pulling latest changes..."
|
|
||||||
sudo -u rtl git pull -p
|
|
||||||
echo "# Reset to the latest release tag"
|
|
||||||
TAG=$(git tag | sort -V | tail -1)
|
|
||||||
sudo -u rtl git reset --hard $TAG
|
|
||||||
echo "# updating to the latest"
|
|
||||||
# https://github.com/Ride-The-Lightning/RTL#or-update-existing-dependencies
|
|
||||||
sudo -u rtl npm install --only=prod
|
|
||||||
echo "# Updated to version" $TAG
|
|
||||||
fi
|
|
||||||
elif [ "$updateOption" = "commit" ]; then
|
|
||||||
echo "# updating to the latest commit in https://github.com/Ride-The-Lightning/RTL"
|
|
||||||
sudo -u rtl git pull -p
|
|
||||||
sudo -u rtl npm install --only=prod
|
|
||||||
currentRTLcommit=$(cd /home/rtl/RTL; git describe --tags)
|
|
||||||
echo "# Updated RTL to $currentRTLcommit"
|
|
||||||
else
|
|
||||||
echo "# Unknown option: $updateOption"
|
|
||||||
fi
|
|
||||||
|
|
||||||
/home/admin/config.scripts/bonus.rtl.sh config $2 $3
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "# Starting the RTL service ... "
|
|
||||||
sudo systemctl start RTL
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "# FAIL - Unknown Parameter $1"
|
echo "# FAIL - Unknown Parameter $1"
|
||||||
echo "# may need reboot to run normal again"
|
echo "# may need reboot to run normal again"
|
||||||
|
Reference in New Issue
Block a user