fix #2703 keeping to RTL config changes thru reboot & sd card update (#2774)

* #2703 dont delete RTL config
* #2703 move RTL config to HDD
* fix config exists detection
This commit is contained in:
/rootzoll 2021-12-08 01:12:56 +01:00 committed by GitHub
parent 6b5efb8e40
commit f3773f2eda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -184,6 +184,10 @@ if [ "$1" = "1" ] || [ "$1" = "on" ]; then
sudo ufw allow $((RTLHTTP+1)) comment "${systemdService} HTTPS"
echo
# make sure config directory exists
sudo mkdir -p /mnt/hdd/app-data/rtl 2>/dev/null
sudo chown -R rtl:rtl /mnt/hdd/app-data/rtl
echo "# Create Systemd Service: ${systemdService}.service (Template)"
echo "
# Systemd unit for ${systemdService}
@ -194,7 +198,7 @@ Wants=
After=
[Service]
Environment=\"RTL_CONFIG_PATH=/home/rtl/${systemdService}/\"
Environment=\"RTL_CONFIG_PATH=/mnt/hdd/app-data/rtl/${systemdService}/\"
ExecStartPre=-/home/admin/config.scripts/bonus.rtl.sh prestart ${LNTYPE} ${CHAIN}
ExecStart=/usr/bin/node /home/rtl/RTL/rtl
User=rtl
@ -359,20 +363,26 @@ if [ "$1" = "prestart" ]; then
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
echo "# PREPARE /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json"
# make sure directory exists
mkdir -p /mnt/hdd/app-data/rtl/${systemdService} 2>/dev/null
# check if RTL-Config.json exists
configExists=$(ls /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json 2>/dev/null | grep -c "RTL-Config.json")
if [ "${configExists}" == "0" ]; then
# copy template
cp /home/rtl/RTL/docs/Sample-RTL-Config.json /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json
chmod 600 /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json
fi
# LND changes of config
if [ "${LNTYPE}" == "lnd" ]; then
echo "# LND Config"
cat /home/rtl/${systemdService}/RTL-Config.json | \
cat /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json | \
jq ".port = \"${RTLHTTP}\"" | \
jq ".multiPass = \"${RPCPASSWORD}\"" | \
jq ".multiPassHashed = \"\"" | \
jq ".nodes[0].lnNode = \"${hostname}\"" | \
jq ".nodes[0].lnImplementation = \"LND\"" | \
jq ".nodes[0].Authentication.macaroonPath = \"/home/rtl/.lnd/data/chain/${network}/${CHAIN}/\"" | \
@ -381,18 +391,19 @@ if [ "$1" = "prestart" ]; then
jq ".nodes[0].Authentication.boltzMacaroonPath = \"/home/rtl/.boltz-lnd/macaroons/\"" | \
jq ".nodes[0].Settings.userPersona = \"OPERATOR\"" | \
jq ".nodes[0].Settings.lnServerUrl = \"https://localhost:${portprefix}8080\"" | \
jq ".nodes[0].Settings.channelBackupPath = \"/home/rtl/${systemdService}-SCB-backup-$hostname\"" | \
jq ".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
jq ".nodes[0].Settings.channelBackupPath = \"/mnt/hdd/app-data/rtl/${systemdService}-SCB-backup-$hostname\"" | \
jq ".nodes[0].Settings.swapServerUrl = \"https://localhost:${SWAPSERVERPORT}\"" > /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json.tmp
mv /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json.tmp /mnt/hdd/app-data/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}" == "cl" ]; then
echo "# CL Config"
cat /home/rtl/${systemdService}/RTL-Config.json | \
cat /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json | \
jq ".port = \"${RTLHTTP}\"" | \
jq ".multiPass = \"${RPCPASSWORD}\"" | \
jq ".multiPassHashed = \"\"" | \
jq ".nodes[0].lnNode = \"${hostname}\"" | \
jq ".nodes[0].lnImplementation = \"CLT\"" | \
jq ".nodes[0].Authentication.macaroonPath = \"/home/bitcoin/c-lightning-REST/certs\"" | \
@ -401,9 +412,9 @@ if [ "$1" = "prestart" ]; then
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].Settings.channelBackupPath = \"/home/rtl/${systemdService}-SCB-backup-$hostname\"" | \
jq ".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
jq ".nodes[0].Settings.channelBackupPath = \"/mnt/hdd/app-data/rtl/${systemdService}-SCB-backup-$hostname\"" | \
jq ".nodes[0].Settings.swapServerUrl = \"https://localhost:${SWAPSERVERPORT}\"" > /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json.tmp
mv /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json.tmp /mnt/hdd/app-data/rtl/${systemdService}/RTL-Config.json
fi
echo "# RTL prestart config done"