raspiblitz/home.admin/config.scripts/bonus.rtl.sh

329 lines
11 KiB
Bash
Raw Normal View History

2018-12-02 19:52:01 +01:00
#!/bin/bash
RTLVERSION="v0.10.1"
2018-12-02 19:52:01 +01:00
# 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]"
echo "# installs the version $RTLVERSION by default"
2018-12-02 19:52:01 +01:00
exit 1
fi
# 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
2018-12-02 19:52:01 +01:00
if [ ${#network} -eq 0 ]; then
echo "FAIL - missing /mnt/hdd/raspiblitz.conf"
exit 1
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
2020-10-14 18:52:31 +02:00
localip=$(ip addr | grep 'state UP' -A2 | egrep -v 'docker0|veth' | grep 'eth0\|wlan0\|enp0' | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
2020-01-26 23:59:06 +01:00
toraddress=$(sudo cat /mnt/hdd/tor/RTL/hostname 2>/dev/null)
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}"
2020-07-16 19:38:49 +02:00
whiptail --title " Ride The Lightning (RTL) " --msgbox "Open in your local web browser & accept self-signed cert:
2020-06-29 16:10:19 +02:00
https://${localip}:3001\n
2020-06-09 11:44:39 +01:00
SHA1 Thumb/Fingerprint:
${fingerprint}\n
2020-01-27 02:00:38 +01:00
Use your Password B to login.\n
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
2020-07-16 19:38:49 +02:00
whiptail --title " Ride The Lightning (RTL) " --msgbox "Open in your local web browser & accept self-signed cert:
2020-06-29 16:10:19 +02:00
https://${localip}:3001\n
2020-06-09 11:44:39 +01:00
SHA1 Thumb/Fingerprint:
${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
if ! grep -Eq "^rtlWebinterface=" /mnt/hdd/raspiblitz.conf; then
2018-12-02 21:46:00 +01:00
echo "rtlWebinterface=off" >> /mnt/hdd/raspiblitz.conf
fi
2018-12-02 19:52:01 +01:00
# stop services
echo "# making sure services are not running"
2018-12-02 19:52:01 +01:00
sudo systemctl stop RTL 2>/dev/null
function configRTL() {
SWAPSERVERPORT=8081
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
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
# prepare RTL-Config.json file
echo "# RTL.conf"
# change of config: https://github.com/Ride-The-Lightning/RTL/tree/v0.6.4
sudo cp /home/rtl/RTL/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
sudo node > /home/admin/RTL-Config.json <<EOF
//Read data
var data = require('/home/rtl/RTL/sample-RTL-Config.json');
//Manipulate data
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';
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/RTL-SCB-backup-$hostname'
data.nodes[0].Settings.swapServerUrl = 'https://localhost:$SWAPSERVERPORT'
//Output data
console.log(JSON.stringify(data, null, 2));
EOF
sudo rm -f /home/rtl/RTL/RTL-Config.json
sudo mv /home/admin/RTL-Config.json /home/rtl/RTL/
sudo chown rtl:rtl /home/rtl/RTL/RTL-Config.json
}
2018-12-02 19:52:01 +01:00
# switch on
2018-12-02 20:43:48 +01:00
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
echo "# INSTALL RTL"
2018-12-02 19:52:01 +01:00
isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
2020-01-11 00:06:08 +00:00
if ! [ ${isInstalled} -eq 0 ]; then
echo "# RTL already installed."
2020-01-11 00:06:08 +00:00
else
# 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
sudo adduser --disabled-password --gecos "" rtl || exit 1
2020-03-10 11:20:31 +00:00
echo "# Make sure rtl is member of lndadmin"
2020-05-01 17:48:43 +02:00
sudo /usr/sbin/usermod --append --groups lndadmin rtl
echo "# Make sure symlink to central app-data directory exists"
2020-05-01 17:48:43 +02:00
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
2019-01-14 21:58:03 +01:00
# download source code and set to tag release
echo "# Get the RTL Source Code"
2020-03-10 11:20:31 +00:00
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
2020-08-27 11:55:46 +01:00
# check https://github.com/Ride-The-Lightning/RTL/releases/
sudo -u rtl git reset --hard $RTLVERSION
2020-01-09 19:39:58 +00:00
# from https://github.com/Ride-The-Lightning/RTL/commits/master
# git checkout 917feebfa4fb583360c140e817c266649307ef72
2020-08-27 12:58:12 +02:00
if [ -d "/home/rtl/RTL" ]; then
echo "# OK - RTL code copy looks good"
2019-03-13 18:13:49 +01:00
else
echo "# FAIL - code copy did not run correctly"
echo "# ABORT - RTL install"
2019-03-13 18:13:49 +01:00
exit 1
fi
echo ""
2019-01-14 21:58:03 +01:00
# install
echo "# Run: npm install"
export NG_CLI_ANALYTICS=false
2020-03-22 10:00:11 +00:00
sudo -u rtl npm install --only=prod
if ! [ $? -eq 0 ]; then
echo "# FAIL - npm install did not run correctly, aborting"
exit 1
2019-03-13 18:13:49 +01:00
else
echo "# OK - RTL install looks good"
echo
2019-03-13 18:13:49 +01:00
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'
echo
2018-12-02 19:52:01 +01:00
echo "# Install service"
echo "# Install RTL systemd for ${network} on ${chain}"
2020-03-10 11:20:31 +00:00
cat > /home/admin/RTL.service <<EOF
# Systemd unit for RTL
# /etc/systemd/system/RTL.service
[Unit]
Description=RTL daemon
Wants=lnd.service
After=lnd.service
[Service]
2020-05-01 17:48:43 +02:00
ExecStart=/usr/bin/node /home/rtl/RTL/rtl --lndir /home/rtl/.lnd/data/chain/bitcoin/mainnet
2020-03-10 11:20:31 +00:00
User=rtl
Restart=always
TimeoutSec=120
RestartSec=30
StandardOutput=null
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
sudo mv /home/admin/RTL.service /etc/systemd/system/RTL.service
2018-12-02 19:52:01 +01:00
sudo sed -i "s|chain/bitcoin/mainnet|chain/${network}/${chain}net|" /etc/systemd/system/RTL.service
2020-05-01 17:58:29 +02:00
sudo chown root:root /etc/systemd/system/RTL.service
2018-12-02 19:52:01 +01:00
sudo systemctl enable RTL
echo "OK - the RTL service is now enabled"
2018-12-02 19:52:01 +01:00
fi
configRTL
2019-03-13 18:13:49 +01:00
# setting value in raspi blitz config
sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=on/g" /mnt/hdd/raspiblitz.conf
# 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
/home/admin/config.scripts/internet.hiddenservice.sh RTL 80 3002 443 3003
fi
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
else
echo "# OK - the RTL.service is enabled, to start manually use: 'sudo systemctl start RTL'"
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
sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=off/g" /mnt/hdd/raspiblitz.conf
2020-06-11 15:32:00 +01:00
# 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
2020-06-26 22:57:12 +02:00
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 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
fi
2018-12-02 19:52:01 +01:00
isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
if [ ${isInstalled} -eq 1 ]; then
echo "# REMOVING RTL"
2018-12-02 19:52:01 +01:00
sudo systemctl disable RTL
sudo rm /etc/systemd/system/RTL.service
# delete user and home directory
sudo userdel -rf rtl
echo "# OK RTL removed."
else
echo "# RTL is not installed."
2018-12-02 19:52:01 +01:00
fi
# close ports on firewall
sudo ufw deny 3000
sudo ufw deny 3001
2018-12-02 19:52:01 +01:00
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
configRTL
echo
echo "# Starting the RTL service ... "
sudo systemctl start RTL
exit 0
fi
echo "# FAIL - Unknown Parameter $1"
echo "# may need reboot to run normal again"
2019-05-11 06:16:39 +01:00
exit 1