2018-12-02 19:52:01 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# command info
|
|
|
|
if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
|
|
|
|
echo "small config script to switch WebGUI RideTheLightning on or off"
|
2020-01-26 23:35:02 +01:00
|
|
|
echo "bonus.rtl.sh [on|off|menu]"
|
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-01-26 23:35:02 +01:00
|
|
|
localip=$(ip addr | grep 'state UP' -A2 | 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)
|
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
|
2020-01-26 23:57:37 +01:00
|
|
|
/home/admin/config.scripts/blitz.lcd.sh qr "${toraddress}"
|
2020-01-27 02:00:38 +01:00
|
|
|
whiptail --title " Ride The Lightning (RTL) " --msgbox "Open the following URL in your local web browser:
|
2020-01-26 23:35:02 +01:00
|
|
|
http://${localip}:3000
|
2020-01-27 02:00:38 +01:00
|
|
|
Use your Password B to login.\n
|
|
|
|
Hidden Service address for TOR Browser (QR see LCD):\n${toraddress}
|
2020-01-27 00:12:10 +01:00
|
|
|
" 12 67
|
2020-01-27 02:00:38 +01:00
|
|
|
/home/admin/config.scripts/blitz.lcd.sh hide
|
|
|
|
else
|
|
|
|
# Info without TOR
|
|
|
|
whiptail --title " Ride The Lightning (RTL) " --msgbox "Open the following URL in your local web browser:
|
|
|
|
http://${localip}:3000
|
|
|
|
Use your Password B to login.\n
|
|
|
|
Activate TOR to access the web interface from outside your local network.
|
|
|
|
" 12 57
|
|
|
|
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
|
2020-01-11 09:38:17 +00:00
|
|
|
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"
|
|
|
|
sudo systemctl stop RTL 2>/dev/null
|
|
|
|
|
|
|
|
# switch on
|
2018-12-02 20:43:48 +01:00
|
|
|
if [ "$1" = "1" ] || [ "$1" = "on" ]; then
|
2018-12-02 19:52:01 +01:00
|
|
|
echo "*** INSTALL RTL ***"
|
|
|
|
|
|
|
|
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."
|
2018-12-02 19:52:01 +01:00
|
|
|
|
2020-01-11 00:06:08 +00:00
|
|
|
else
|
2019-11-24 13:12:55 +00:00
|
|
|
# check and install NodeJS
|
|
|
|
/home/admin/config.scripts/bonus.nodejs.sh
|
2019-03-13 18:13:49 +01:00
|
|
|
|
2020-01-11 00:06:08 +00:00
|
|
|
# check for Python2 (install if missing)
|
|
|
|
# TODO remove Python2 ASAP!
|
2020-01-11 00:12:23 +00:00
|
|
|
echo "*** Check for Python2 ***"
|
2020-01-11 00:06:08 +00:00
|
|
|
/usr/bin/which python2 &>/dev/null
|
2020-01-11 00:12:23 +00:00
|
|
|
if ! [ $? -eq 0 ]; then
|
|
|
|
echo "*** Install Python2 ***"
|
2020-01-11 00:06:08 +00:00
|
|
|
sudo apt-get update
|
|
|
|
sudo apt-get install -y python2
|
|
|
|
fi
|
|
|
|
|
2020-03-10 11:20:31 +00:00
|
|
|
# create rtl user
|
|
|
|
sudo adduser --disabled-password --gecos "" rtl
|
|
|
|
|
2019-01-14 21:58:03 +01:00
|
|
|
# download source code and set to tag release
|
2018-12-02 19:52:01 +01:00
|
|
|
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
|
|
|
|
sudo -u rtl git reset --hard v0.6.7
|
2020-01-09 19:39:58 +00:00
|
|
|
# from https://github.com/Ride-The-Lightning/RTL/commits/master
|
2020-01-13 20:31:36 +00:00
|
|
|
# git checkout 917feebfa4fb583360c140e817c266649307ef72
|
2020-02-13 12:31:59 +00:00
|
|
|
# git fetch origin
|
|
|
|
# git checkout feature/0.6.5
|
2020-03-10 11:20:31 +00:00
|
|
|
if [ -d "/home/rtl/RTL" ]; then
|
2019-03-13 18:13:49 +01:00
|
|
|
echo "OK - RTL code copy looks good"
|
|
|
|
else
|
|
|
|
echo "FAIL - code copy did not run correctly"
|
|
|
|
echo "ABORT - RTL install"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo ""
|
2019-02-05 02:40:42 +01:00
|
|
|
|
2019-01-14 21:58:03 +01:00
|
|
|
# install
|
|
|
|
echo "*** Run: npm install ***"
|
2019-11-24 13:12:55 +00:00
|
|
|
export NG_CLI_ANALYTICS=false
|
2020-03-10 11:20:31 +00:00
|
|
|
sudo -u rtl npm install --only=production
|
2018-12-02 19:52:01 +01:00
|
|
|
cd ..
|
2020-01-13 20:31:36 +00:00
|
|
|
# check if node_modules exist now
|
2020-03-10 11:20:31 +00:00
|
|
|
if [ -d "/home/rtl/RTL/node_modules" ]; then
|
2019-03-13 18:13:49 +01:00
|
|
|
echo "OK - RTL install looks good"
|
|
|
|
else
|
|
|
|
echo "FAIL - npm install did not run correctly"
|
|
|
|
echo "ABORT - RTL install"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-12-02 19:52:01 +01:00
|
|
|
echo ""
|
|
|
|
|
2020-01-11 00:21:03 +00:00
|
|
|
# now remove Python2 again
|
|
|
|
echo "*** Now remove Python2 again ***"
|
|
|
|
sudo apt-get purge -y python2
|
|
|
|
sudo apt-get autoremove -y
|
|
|
|
|
2020-02-13 12:31:59 +00:00
|
|
|
# prepare RTL-Config.json file
|
2019-01-14 21:58:03 +01:00
|
|
|
echo "*** RTL.conf ***"
|
2020-02-13 12:31:59 +00:00
|
|
|
# change of config: https://github.com/Ride-The-Lightning/RTL/tree/v0.6.4
|
2020-03-10 11:20:31 +00:00
|
|
|
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
|
2020-01-20 11:39:08 +00:00
|
|
|
PASSWORD_B=$(sudo cat /mnt/hdd/${network}/${network}.conf | grep rpcpassword | cut -c 13-)
|
2020-03-10 11:20:31 +00:00
|
|
|
# modify sample-RTL-Config.json and save in RTL-Config.json
|
|
|
|
sudo node > /home/admin/RTL-Config.json <<EOF
|
2020-02-13 12:31:59 +00:00
|
|
|
//Read data
|
2020-03-10 11:20:31 +00:00
|
|
|
var data = require('/home/rtl/RTL/sample-RTL-Config.json');
|
2020-02-13 12:31:59 +00:00
|
|
|
//Manipulate data
|
|
|
|
data.nodes[0].lnNode = '$hostname'
|
|
|
|
data.nodes[0].Authentication.macaroonPath = '/mnt/hdd/lnd/data/chain/${network}/${chain}net/';
|
|
|
|
data.nodes[0].Authentication.configPath = '/mnt/hdd/lnd/lnd.conf';
|
|
|
|
data.multiPass = '$PASSWORD_B';
|
|
|
|
data.nodes[0].Settings.userPersona = 'OPERATOR'
|
2020-03-10 11:20:31 +00:00
|
|
|
data.nodes[0].Settings.channelBackupPath = '/home/rtl/RTL-SCB-backup-$hostname'
|
2020-02-13 12:31:59 +00:00
|
|
|
//Output data
|
|
|
|
console.log(JSON.stringify(data, null, 2));
|
|
|
|
EOF
|
2020-03-10 11:20:31 +00:00
|
|
|
sudo mv /home/admin/RTL-Config.json /home/rtl/RTL/
|
|
|
|
sudo chown rtl:rtl /home/rtl/RTL/RTL-Config.json
|
2019-01-14 21:58:03 +01:00
|
|
|
echo ""
|
|
|
|
|
2018-12-02 19:52:01 +01:00
|
|
|
# open firewall
|
|
|
|
echo "*** Updating Firewall ***"
|
2019-12-04 08:13:21 +00:00
|
|
|
sudo ufw allow 3000 comment 'RTL'
|
2018-12-02 19:52:01 +01:00
|
|
|
sudo ufw --force enable
|
|
|
|
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]
|
|
|
|
ExecStart=/usr/bin/node /home/rtl/RTL/rtl --lndir /home/admin/.lnd/data/chain/bitcoin/mainnet
|
|
|
|
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
|
|
|
|
sudo systemctl enable RTL
|
2019-11-24 13:12:55 +00:00
|
|
|
echo "OK - the RTL service is now enabled"
|
2018-12-02 19:52:01 +01:00
|
|
|
fi
|
2019-11-24 13:12:55 +00:00
|
|
|
|
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
|
|
|
|
|
2019-11-24 13:12:55 +00:00
|
|
|
# Hidden Service for RTL if Tor is active
|
|
|
|
if [ "${runBehindTor}" = "on" ]; then
|
2019-12-04 10:09:14 +00:00
|
|
|
# correct old Hidden Service with port
|
|
|
|
sudo sed -i "s/^HiddenServicePort 3000 127.0.0.1:3000/HiddenServicePort 80 127.0.0.1:3000/g" /etc/tor/torrc
|
|
|
|
/home/admin/config.scripts/internet.hiddenservice.sh RTL 80 3000
|
2019-11-24 13:12:55 +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
|
|
|
|
sudo sed -i "s/^rtlWebinterface=.*/rtlWebinterface=off/g" /mnt/hdd/raspiblitz.conf
|
|
|
|
|
|
|
|
isInstalled=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
|
|
|
|
if [ ${isInstalled} -eq 1 ]; then
|
|
|
|
echo "*** REMOVING RTL ***"
|
|
|
|
sudo systemctl stop RTL
|
|
|
|
sudo systemctl disable RTL
|
|
|
|
sudo rm /etc/systemd/system/RTL.service
|
2020-03-10 11:20:31 +00:00
|
|
|
sudo rm -rf /home/rtl/RTL
|
2018-12-02 19:52:01 +01:00
|
|
|
echo "OK RTL removed."
|
|
|
|
else
|
|
|
|
echo "RTL is not installed."
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "needs reboot to activate new setting"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2019-11-24 13:12:55 +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
|