2018-12-02 19:52:01 +01:00
|
|
|
#!/bin/bash
|
2021-08-19 21:02:43 +02:00
|
|
|
RTLVERSION="v0.11.0"
|
2018-12-02 19:52:01 +01:00
|
|
|
|
|
|
|
# check and load raspiblitz config
|
|
|
|
# to know which network is running
|
2019-02-02 23:49:04 +01:00
|
|
|
source /home/admin/raspiblitz.info
|
2018-12-03 17:24:17 +01:00
|
|
|
source /mnt/hdd/raspiblitz.conf
|
2021-08-04 00:18:30 +02:00
|
|
|
|
|
|
|
# command info
|
|
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
|
|
|
echo "# config script to switch the RideTheLightning WebGUI on, off or update"
|
|
|
|
echo
|
2021-08-31 18:23:02 +02:00
|
|
|
echo "# bonus.rtl.sh [on|off|menu|config] <lnd|cln> <testnet|signet>"
|
2021-08-04 00:18:30 +02:00
|
|
|
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 $*'"
|
|
|
|
|
2018-12-02 19:52:01 +01:00
|
|
|
if [ ${#network} -eq 0 ]; then
|
|
|
|
echo "FAIL - missing /mnt/hdd/raspiblitz.conf"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# LNTYPE is lnd | cln
|
2021-08-04 09:25:13 +02:00
|
|
|
if [ $# -gt 1 ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
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
|
2021-08-04 09:25:13 +02:00
|
|
|
if [ $# -gt 2 ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
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
|
|
|
|
|
2021-08-04 09:25:13 +02:00
|
|
|
# prefix for parallel networks
|
|
|
|
if [ "${CHAIN}" == "testnet" ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
netprefix="t"
|
|
|
|
portprefix=1
|
2021-08-04 09:25:13 +02:00
|
|
|
elif [ "${CHAIN}" == "signet" ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
netprefix="s"
|
|
|
|
portprefix=3
|
2021-08-04 09:25:13 +02:00
|
|
|
elif [ "${CHAIN}" == "mainnet" ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
netprefix=""
|
|
|
|
portprefix=""
|
2021-08-31 18:23:02 +02:00
|
|
|
else
|
|
|
|
echo "# CHAIN(${CHAIN})"
|
|
|
|
echo "err='not supported chain'"
|
2021-08-04 00:18:30 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-04 09:25:13 +02:00
|
|
|
# prefix for parallel lightning impl
|
|
|
|
if [ "${LNTYPE}" == "cln" ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
RTLHTTP=${portprefix}7000
|
2021-08-04 09:25:13 +02:00
|
|
|
typeprefix="c"
|
|
|
|
elif [ "${LNTYPE}" == "lnd" ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
RTLHTTP=${portprefix}3000
|
|
|
|
typeprefix=""
|
|
|
|
fi
|
|
|
|
|
2020-01-26 23:35:02 +01:00
|
|
|
# show info menu
|
|
|
|
if [ "$1" = "menu" ]; then
|
2020-01-27 02:00:38 +01:00
|
|
|
|
|
|
|
# get network info
|
2021-08-04 00:18:30 +02:00
|
|
|
localip=$(hostname -I | awk '{print $1}')
|
2020-01-26 23:59:06 +01:00
|
|
|
toraddress=$(sudo cat /mnt/hdd/tor/RTL/hostname 2>/dev/null)
|
2020-05-26 21:34:19 +02:00
|
|
|
fingerprint=$(openssl x509 -in /mnt/hdd/app-data/nginx/tls.cert -fingerprint -noout | cut -d"=" -f2)
|
2020-01-27 02:00:38 +01:00
|
|
|
|
2020-01-26 23:35:02 +01:00
|
|
|
if [ "${runBehindTor}" = "on" ] && [ ${#toraddress} -gt 0 ]; then
|
2020-01-27 02:00:38 +01:00
|
|
|
# Info with TOR
|
2021-04-08 00:02:57 +02:00
|
|
|
/home/admin/config.scripts/blitz.display.sh qr "${toraddress}"
|
2021-08-04 00:18:30 +02:00
|
|
|
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:
|
2020-06-09 11:44:39 +01:00
|
|
|
${fingerprint}\n
|
2020-01-27 02:00:38 +01:00
|
|
|
Use your Password B to login.\n
|
2020-06-09 08:09:14 +01:00
|
|
|
Hidden Service address for TOR Browser (QRcode on LCD):\n${toraddress}
|
2020-06-29 16:10:19 +02:00
|
|
|
" 16 67
|
2021-04-08 00:02:57 +02:00
|
|
|
/home/admin/config.scripts/blitz.display.sh hide
|
2020-01-27 02:00:38 +01:00
|
|
|
else
|
|
|
|
# Info without TOR
|
2021-08-04 00:18:30 +02:00
|
|
|
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:
|
2020-06-09 11:44:39 +01:00
|
|
|
${fingerprint}\n
|
2020-01-27 02:00:38 +01:00
|
|
|
Use your Password B to login.\n
|
|
|
|
Activate TOR to access the web interface from outside your local network.
|
2020-10-08 20:52:37 +02:00
|
|
|
" 15 67
|
2020-01-27 02:00:38 +01:00
|
|
|
fi
|
2020-01-26 23:59:06 +01:00
|
|
|
echo "please wait ..."
|
2020-01-26 23:35:02 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2018-12-02 21:46:00 +01:00
|
|
|
# add default value to raspi config if needed
|
2021-08-04 09:31:15 +02:00
|
|
|
configEntry="${netprefix}${typeprefix}rtlWebinterface"
|
|
|
|
configEntryExists=$(sudo cat /mnt/hdd/raspiblitz.conf | grep -c "${configEntry}")
|
2021-08-04 09:25:13 +02:00
|
|
|
if [ "${configEntryExists}" == "0" ]; then
|
2021-08-04 09:31:15 +02:00
|
|
|
echo "# adding default config entry for '${configEntry}'"
|
|
|
|
sudo /bin/sh -c "echo '${configEntry}=off' >> /mnt/hdd/raspiblitz.conf"
|
2021-08-04 09:25:13 +02:00
|
|
|
else
|
2021-08-04 09:31:15 +02:00
|
|
|
echo "# default config entry for '${configEntry}' exists"
|
2018-12-02 21:46:00 +01:00
|
|
|
fi
|
|
|
|
|
2018-12-02 19:52:01 +01:00
|
|
|
# stop services
|
2021-03-18 13:05:49 +00:00
|
|
|
echo "# making sure services are not running"
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo systemctl stop ${netprefix}${typeprefix}RTL 2>/dev/null
|
2018-12-02 19:52:01 +01:00
|
|
|
|
|
|
|
# switch on
|
2018-12-02 20:43:48 +01:00
|
|
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
2021-08-23 18:35:22 +01:00
|
|
|
echo "# Installing RTL for ${LNTYPE} ${CHAIN}"
|
2018-12-02 19:52:01 +01:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
isInstalled=$(sudo ls /etc/systemd/system/${netprefix}${typeprefix}RTL.service 2>/dev/null | grep -c "${netprefix}${typeprefix}RTL.service")
|
2020-01-11 00:06:08 +00:00
|
|
|
if ! [ ${isInstalled} -eq 0 ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# OK, the ${netprefix}${typeprefix}RTL.service is already installed."
|
2020-01-11 00:06:08 +00:00
|
|
|
else
|
2019-11-24 13:12:55 +00:00
|
|
|
# check and install NodeJS
|
2020-05-29 15:21:38 +01:00
|
|
|
/home/admin/config.scripts/bonus.nodejs.sh on
|
2019-03-13 18:13:49 +01:00
|
|
|
|
2020-03-10 11:20:31 +00:00
|
|
|
# create rtl user
|
2021-08-04 00:18:30 +02:00
|
|
|
if [ $(compgen -u | grep -c rtl) -eq 0 ];then
|
|
|
|
sudo adduser --disabled-password --gecos "" rtl || exit 1
|
2020-05-01 17:48:43 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-23 18:35:22 +01:00
|
|
|
echo "# Make sure symlink to central app-data directory exists"
|
|
|
|
if ! [[ -L "/home/rtl/.lnd" ]]; then
|
|
|
|
sudo rm -rf "/home/rtl/.lnd" # not a symlink.. delete it silently
|
|
|
|
sudo ln -s "/mnt/hdd/app-data/lnd/" "/home/rtl/.lnd" # and create symlink
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f /home/rtl/RTL/rtl ];then
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# OK - the RTL code is already present"
|
2021-08-23 18:35:22 +01:00
|
|
|
cd /home/rtl/RTL
|
|
|
|
sudo -u rtl git pull
|
|
|
|
|
2019-03-13 18:13:49 +01:00
|
|
|
else
|
2021-08-04 00:18:30 +02:00
|
|
|
# download source code and set to tag release
|
|
|
|
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 git clone https://github.com/ShahanaFarooqui/RTL.git /home/rtl/RTL
|
|
|
|
cd /home/rtl/RTL
|
2021-08-23 18:35:22 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# check https://github.com/Ride-The-Lightning/RTL/releases/
|
|
|
|
sudo -u rtl git reset --hard $RTLVERSION
|
|
|
|
# from https://github.com/Ride-The-Lightning/RTL/commits/master
|
|
|
|
# git checkout 917feebfa4fb583360c140e817c266649307ef72
|
|
|
|
if [ -d "/home/rtl/RTL" ]; then
|
|
|
|
echo "# OK - RTL code copy looks good"
|
|
|
|
else
|
|
|
|
echo "# FAIL - code copy did not run correctly"
|
|
|
|
echo "# ABORT - RTL install"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo
|
2021-08-04 00:18:30 +02:00
|
|
|
|
2021-08-23 18:35:22 +01:00
|
|
|
# install
|
|
|
|
echo "# Run: npm install"
|
|
|
|
export NG_CLI_ANALYTICS=false
|
|
|
|
sudo -u rtl npm install --only=prod
|
|
|
|
if ! [ $? -eq 0 ]; then
|
|
|
|
echo "# FAIL - npm install did not run correctly, aborting"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
echo "# OK - RTL install looks good"
|
|
|
|
echo
|
2020-05-26 21:34:19 +02:00
|
|
|
fi
|
2021-08-23 18:35:22 +01:00
|
|
|
|
2021-03-18 13:05:49 +00:00
|
|
|
echo "# Updating Firewall"
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo ufw allow ${RTLHTTP} comment "${netprefix}${typeprefix}RTL HTTP"
|
|
|
|
sudo ufw allow $((RTLHTTP+1)) comment "${netprefix}${typeprefix}RTL HTTPS"
|
2021-03-18 13:05:49 +00:00
|
|
|
echo
|
2018-12-02 19:52:01 +01:00
|
|
|
|
2021-08-23 18:35:22 +01:00
|
|
|
if [ $LNTYPE = lnd ];then
|
|
|
|
echo "# Install service"
|
|
|
|
echo "# Install RTL systemd for ${network} on ${chain}"
|
|
|
|
echo "
|
2021-08-04 00:18:30 +02:00
|
|
|
# Systemd unit for ${netprefix}${typeprefix}RTL
|
|
|
|
# /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
2020-03-10 11:20:31 +00:00
|
|
|
|
|
|
|
[Unit]
|
2021-08-04 00:18:30 +02:00
|
|
|
Description=${netprefix}${typeprefix}RTL daemon
|
2020-03-10 11:20:31 +00:00
|
|
|
Wants=lnd.service
|
|
|
|
After=lnd.service
|
|
|
|
|
|
|
|
[Service]
|
2021-08-04 00:18:30 +02:00
|
|
|
Environment=\"RTL_CONFIG_PATH=/home/rtl/${netprefix}RTL/\"
|
|
|
|
ExecStart=/usr/bin/node /home/rtl/RTL/rtl
|
2020-03-10 11:20:31 +00:00
|
|
|
User=rtl
|
|
|
|
Restart=always
|
|
|
|
TimeoutSec=120
|
|
|
|
RestartSec=30
|
|
|
|
StandardOutput=null
|
|
|
|
StandardError=journal
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# Hardening measures
|
|
|
|
PrivateTmp=true
|
|
|
|
ProtectSystem=full
|
|
|
|
NoNewPrivileges=true
|
|
|
|
PrivateDevices=true
|
|
|
|
|
2020-03-10 11:20:31 +00:00
|
|
|
[Install]
|
|
|
|
WantedBy=multi-user.target
|
2021-08-23 18:35:22 +01:00
|
|
|
" | sudo tee /home/admin/${netprefix}${typeprefix}RTL.service
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo mv /home/admin/${netprefix}${typeprefix}RTL.service /etc/systemd/system/${netprefix}${typeprefix}RTL.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
|
2021-08-23 18:35:22 +01:00
|
|
|
# clnrest
|
|
|
|
/home/admin/config.scripts/cln.rest.sh on ${CHAIN}
|
|
|
|
echo "
|
2021-08-04 00:18:30 +02:00
|
|
|
# Systemd unit for ${netprefix}${typeprefix}RTL
|
|
|
|
# /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\"
|
|
|
|
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
|
2021-08-23 18:35:22 +01:00
|
|
|
" | sudo tee /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
2021-08-04 00:18:30 +02:00
|
|
|
fi
|
|
|
|
fi
|
2021-08-23 18:35:22 +01:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# Setup nginx symlinks"
|
|
|
|
if ! [ -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf ]; then
|
|
|
|
sudo cp /home/admin/assets/nginx/sites-available/rtl_ssl.conf /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
2018-12-02 19:52:01 +01:00
|
|
|
fi
|
2021-08-04 00:18:30 +02:00
|
|
|
if ! [ -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf ]; then
|
|
|
|
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
|
|
|
|
|
|
|
|
echo "# Set ports for Nginx"
|
|
|
|
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
|
2020-05-26 21:34:19 +02:00
|
|
|
|
2021-08-31 18:23:02 +02:00
|
|
|
/home/admin/config.scripts/bonus.rtl.sh config $2 $3
|
2021-03-18 13:05:49 +00:00
|
|
|
|
2019-03-13 18:13:49 +01:00
|
|
|
# setting value in raspi blitz config
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo sed -i "s/^${netprefix}${typeprefix}rtlWebinterface=.*/${netprefix}${typeprefix}rtlWebinterface=on/g" /mnt/hdd/raspiblitz.conf
|
2019-03-13 18:13:49 +01:00
|
|
|
|
2019-11-24 13:12:55 +00:00
|
|
|
# Hidden Service for RTL if Tor is active
|
|
|
|
if [ "${runBehindTor}" = "on" ]; then
|
2020-07-18 15:26:56 +02:00
|
|
|
# make sure to keep in sync with internet.tor.sh script
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/config.scripts/internet.hiddenservice.sh ${netprefix}${typeprefix}RTL 80 $((RTLHTTP+2)) 443 $((RTLHTTP+3))
|
2019-11-24 13:12:55 +00:00
|
|
|
fi
|
2021-08-04 00:18:30 +02:00
|
|
|
|
|
|
|
sudo systemctl enable ${netprefix}${typeprefix}RTL
|
|
|
|
echo "# OK - the ${netprefix}${typeprefix}RTL.service is now enabled"
|
|
|
|
|
2021-03-18 13:05:49 +00:00
|
|
|
source /home/admin/raspiblitz.info
|
|
|
|
if [ "${state}" == "ready" ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# OK - system is ready so starting service"
|
|
|
|
sudo systemctl start ${netprefix}${typeprefix}RTL
|
|
|
|
echo "# Monitor with:"
|
|
|
|
echo "sudo journalctl -f -u ${netprefix}${typeprefix}RTL"
|
2021-03-18 13:05:49 +00:00
|
|
|
else
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# OK - To start manually use: 'sudo systemctl start RTL'"
|
2021-03-18 13:05:49 +00:00
|
|
|
fi
|
2018-12-02 19:52:01 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# switch off
|
2018-12-02 20:43:48 +01:00
|
|
|
if [ "$1" = "0" ] || [ "$1" = "off" ]; then
|
2018-12-02 19:52:01 +01:00
|
|
|
|
|
|
|
# setting value in raspi blitz config
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo sed -i "s/^${netprefix}${typeprefix}rtlWebinterface=.*/${netprefix}${typeprefix}rtlWebinterface=off/g" /mnt/hdd/raspiblitz.conf
|
2018-12-02 19:52:01 +01:00
|
|
|
|
2020-06-11 15:32:00 +01:00
|
|
|
# remove nginx symlinks
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_ssl.conf
|
|
|
|
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_tor.conf
|
|
|
|
sudo rm -f /etc/nginx/sites-enabled/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
|
|
|
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_ssl.conf
|
|
|
|
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor.conf
|
|
|
|
sudo rm -f /etc/nginx/sites-available/${netprefix}${typeprefix}rtl_tor_ssl.conf
|
2020-05-26 21:34:19 +02:00
|
|
|
sudo nginx -t
|
|
|
|
sudo systemctl reload nginx
|
|
|
|
|
2020-07-12 20:05:41 +02:00
|
|
|
# Hidden Service if Tor is active
|
|
|
|
if [ "${runBehindTor}" = "on" ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/config.scripts/internet.hiddenservice.sh off ${netprefix}${typeprefix}RTL
|
2020-07-12 20:05:41 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
isInstalled=$(sudo ls /etc/systemd/system/${netprefix}${typeprefix}RTL.service 2>/dev/null | grep -c "${netprefix}${typeprefix}RTL.service")
|
2018-12-02 19:52:01 +01:00
|
|
|
if [ ${isInstalled} -eq 1 ]; then
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# Removing RTL for ${LNTYPE} ${CHAIN}"
|
|
|
|
sudo systemctl disable ${netprefix}${typeprefix}RTL
|
|
|
|
sudo rm /etc/systemd/system/${netprefix}${typeprefix}RTL.service
|
|
|
|
if [ $LNTYPE = cln ];then
|
|
|
|
/home/admin/config.scripts/cln.rest.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
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "# OK ${netprefix}${typeprefix}RTL removed."
|
2020-05-26 21:34:19 +02:00
|
|
|
else
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "# ${netprefix}${typeprefix}RTL is not installed."
|
2018-12-02 19:52:01 +01:00
|
|
|
fi
|
|
|
|
|
2020-06-10 21:23:17 +01:00
|
|
|
# close ports on firewall
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo ufw deny ${RTLHTTP}
|
|
|
|
sudo ufw deny $((RTLHTTP+1))
|
2018-12-02 19:52:01 +01:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-04-20 00:26:49 +02:00
|
|
|
# config
|
|
|
|
if [ "$1" = "config" ]; then
|
|
|
|
echo "# CONFIG RTL"
|
2021-08-31 18:23:02 +02:00
|
|
|
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
|
|
|
|
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
|
|
|
|
SWAPSERVERPORT=8443
|
|
|
|
elif [ $loop = on ];then
|
|
|
|
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
|
|
|
|
SWAPSERVERPORT=8081
|
|
|
|
fi
|
|
|
|
echo "# Make the loop macaroon group readable"
|
|
|
|
sudo chmod 640 /home/rtl/.loop/mainnet/macaroons.db
|
|
|
|
else
|
|
|
|
echo "# No Loop or LiT is installed"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# prepare RTL-Config.json file
|
|
|
|
echo "# ${netprefix}RTL/RTL.conf"
|
|
|
|
# change of config: https://github.com/Ride-The-Lightning/RTL/tree/v0.6.4
|
|
|
|
sudo cp /home/rtl/RTL/docs/Sample-RTL-Config.json /home/admin/RTL-Config.json
|
|
|
|
sudo chown admin:admin /home/admin/RTL-Config.json
|
|
|
|
sudo chmod 600 /home/admin/RTL-Config.json || exit 1
|
|
|
|
PASSWORD_B=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcpassword | cut -c 13-)
|
|
|
|
# modify sample-RTL-Config.json and save in RTL-Config.json
|
|
|
|
node > /home/admin/RTL-Config.json <<EOF
|
|
|
|
//Read data
|
|
|
|
var data = require('/home/rtl/RTL/docs/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/${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}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}RTL"
|
|
|
|
sudo -u rtl mkdir -p /home/rtl/${netprefix}RTL
|
|
|
|
sudo rm -f /home/rtl/${netprefix}RTL/RTL-Config.json
|
|
|
|
sudo mv /home/admin/RTL-Config.json /home/rtl/${netprefix}RTL/
|
|
|
|
sudo chown rtl:rtl /home/rtl/${netprefix}RTL/RTL-Config.json
|
2021-04-20 00:26:49 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2020-10-13 08:45:17 +01:00
|
|
|
# update
|
|
|
|
if [ "$1" = "update" ]; then
|
|
|
|
echo "# UPDATING RTL"
|
|
|
|
cd /home/rtl/RTL
|
2020-12-21 16:37:29 +00:00
|
|
|
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"
|
2020-10-13 08:45:17 +01:00
|
|
|
sudo -u rtl git pull -p
|
|
|
|
sudo -u rtl npm install --only=prod
|
2020-12-21 16:37:29 +00:00
|
|
|
currentRTLcommit=$(cd /home/rtl/RTL; git describe --tags)
|
|
|
|
echo "# Updated RTL to $currentRTLcommit"
|
|
|
|
else
|
2021-03-18 13:05:49 +00:00
|
|
|
echo "# Unknown option: $updateOption"
|
2020-10-13 08:45:17 +01:00
|
|
|
fi
|
2021-03-18 13:05:49 +00:00
|
|
|
|
2021-08-31 18:23:02 +02:00
|
|
|
/home/admin/config.scripts/bonus.rtl.sh config $2 $3
|
2021-03-18 13:05:49 +00:00
|
|
|
|
2020-12-21 16:37:29 +00:00
|
|
|
echo
|
2020-10-13 08:45:17 +01:00
|
|
|
echo "# Starting the RTL service ... "
|
|
|
|
sudo systemctl start RTL
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2021-03-18 13:05:49 +00:00
|
|
|
echo "# FAIL - Unknown Parameter $1"
|
|
|
|
echo "# may need reboot to run normal again"
|
2019-05-11 06:16:39 +01:00
|
|
|
exit 1
|