From dcbe995061a1d5f032db59283175090d2b21affa Mon Sep 17 00:00:00 2001 From: Taylor Helsper Date: Wed, 7 Jun 2023 21:59:19 -0500 Subject: [PATCH] Add option to reset thunderhub config --- .../etc/systemd/system/thunderhub.service | 1 + rootfs/standard/usr/bin/mynode_startup.sh | 27 +------------- .../usr/bin/service_scripts/pre_thunderhub.sh | 37 +++++++++++++++++++ rootfs/standard/var/pynode/device_info.py | 7 ++++ rootfs/standard/var/www/mynode/settings.py | 10 +++++ .../var/www/mynode/templates/settings.html | 11 ++++++ 6 files changed, 67 insertions(+), 26 deletions(-) create mode 100755 rootfs/standard/usr/bin/service_scripts/pre_thunderhub.sh diff --git a/rootfs/standard/etc/systemd/system/thunderhub.service b/rootfs/standard/etc/systemd/system/thunderhub.service index 1db45612..ab220e2a 100644 --- a/rootfs/standard/etc/systemd/system/thunderhub.service +++ b/rootfs/standard/etc/systemd/system/thunderhub.service @@ -9,6 +9,7 @@ After=lnd.service [Service] ExecStartPre=/usr/bin/is_not_shutting_down.sh ExecStartPre=/usr/bin/wait_on_lnd.sh +ExecStartPre=+/usr/bin/service_scripts/pre_thunderhub.sh Environment=PORT=3030 WorkingDirectory=/opt/mynode/thunderhub ExecStart=/usr/bin/npm run start diff --git a/rootfs/standard/usr/bin/mynode_startup.sh b/rootfs/standard/usr/bin/mynode_startup.sh index db03fcf4..3e826a23 100755 --- a/rootfs/standard/usr/bin/mynode_startup.sh +++ b/rootfs/standard/usr/bin/mynode_startup.sh @@ -428,32 +428,7 @@ fi # Setup Thunderhub -mkdir -p /mnt/hdd/mynode/thunderhub/ -if [ ! -f /mnt/hdd/mynode/thunderhub/.env.local ]; then - cp -f /usr/share/mynode/thunderhub.env /mnt/hdd/mynode/thunderhub/.env.local -fi -if [ ! -f /mnt/hdd/mynode/thunderhub/thub_config.yaml ]; then - cp -f /usr/share/mynode/thub_config.yaml /mnt/hdd/mynode/thunderhub/thub_config.yaml -fi -THUNDERHUB_CONFIG_UPDATE_NUM=1 -if [ ! -f /mnt/hdd/mynode/thunderhub/update_settings_$THUNDERHUB_CONFIG_UPDATE_NUM ]; then - cp -f /usr/share/mynode/thunderhub.env /mnt/hdd/mynode/thunderhub/.env.local - cp -f /usr/share/mynode/thub_config.yaml /mnt/hdd/mynode/thunderhub/thub_config.yaml - touch /mnt/hdd/mynode/thunderhub/update_settings_$THUNDERHUB_CONFIG_UPDATE_NUM -fi -if [ -f /mnt/hdd/mynode/thunderhub/thub_config.yaml ]; then - if [ -f /home/bitcoin/.mynode/.hashedpw_bcrypt ]; then - HASH_BCRYPT=$(cat /home/bitcoin/.mynode/.hashedpw_bcrypt) - sed -i "s#masterPassword:.*#masterPassword: \"thunderhub-$HASH_BCRYPT\"#g" /mnt/hdd/mynode/thunderhub/thub_config.yaml - fi - if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then - sed -i "s/mainnet/testnet/g" /mnt/hdd/mynode/thunderhub/thub_config.yaml || true - else - sed -i "s/testnet/mainnet/g" /mnt/hdd/mynode/thunderhub/thub_config.yaml || true - fi -fi - -chown -R bitcoin:bitcoin /mnt/hdd/mynode/thunderhub +# Moved to pre_thunderhub.sh # Setup CKBunker CKBUNKER_CONFIG_UPDATE_NUM=1 diff --git a/rootfs/standard/usr/bin/service_scripts/pre_thunderhub.sh b/rootfs/standard/usr/bin/service_scripts/pre_thunderhub.sh new file mode 100755 index 00000000..7b899bb4 --- /dev/null +++ b/rootfs/standard/usr/bin/service_scripts/pre_thunderhub.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +source /usr/share/mynode/mynode_config.sh + +set -x +set -e + +# Thunderhub config +mkdir -p /mnt/hdd/mynode/thunderhub/ +if [ ! -f /mnt/hdd/mynode/thunderhub/.env.local ]; then + cp -f /usr/share/mynode/thunderhub.env /mnt/hdd/mynode/thunderhub/.env.local +fi +if [ ! -f /mnt/hdd/mynode/thunderhub/thub_config.yaml ]; then + cp -f /usr/share/mynode/thub_config.yaml /mnt/hdd/mynode/thunderhub/thub_config.yaml +fi +THUNDERHUB_CONFIG_UPDATE_NUM=1 +if [ ! -f /mnt/hdd/mynode/thunderhub/update_settings_$THUNDERHUB_CONFIG_UPDATE_NUM ]; then + cp -f /usr/share/mynode/thunderhub.env /mnt/hdd/mynode/thunderhub/.env.local + cp -f /usr/share/mynode/thub_config.yaml /mnt/hdd/mynode/thunderhub/thub_config.yaml + touch /mnt/hdd/mynode/thunderhub/update_settings_$THUNDERHUB_CONFIG_UPDATE_NUM +fi +if [ -f /mnt/hdd/mynode/thunderhub/thub_config.yaml ]; then + if [ -f /home/bitcoin/.mynode/.hashedpw_bcrypt ]; then + HASH_BCRYPT=$(cat /home/bitcoin/.mynode/.hashedpw_bcrypt) + sed -i "s#masterPassword:.*#masterPassword: \"thunderhub-$HASH_BCRYPT\"#g" /mnt/hdd/mynode/thunderhub/thub_config.yaml + fi + if [ -f /mnt/hdd/mynode/settings/.testnet_enabled ]; then + sed -i "s/mainnet/testnet/g" /mnt/hdd/mynode/thunderhub/thub_config.yaml || true + else + sed -i "s/testnet/mainnet/g" /mnt/hdd/mynode/thunderhub/thub_config.yaml || true + fi +fi + +chown -R bitcoin:bitcoin /mnt/hdd/mynode/thunderhub + +sync +sleep 3s \ No newline at end of file diff --git a/rootfs/standard/var/pynode/device_info.py b/rootfs/standard/var/pynode/device_info.py index 825ec757..4f757220 100644 --- a/rootfs/standard/var/pynode/device_info.py +++ b/rootfs/standard/var/pynode/device_info.py @@ -1160,6 +1160,13 @@ def reset_rtl_config(): os.system("rm -rf /mnt/hdd/mynode/rtl/RTL-Config.json") os.system("systemctl restart rtl") +#================================== +# Thunderhub Functions +#================================== +def reset_thunderhub_config(): + os.system("rm -rf /mnt/hdd/mynode/thunderhub/thub_config.yaml") + os.system("systemctl restart thunderhub") + #================================== # Sphinx Relay Server Functions #================================== diff --git a/rootfs/standard/var/www/mynode/settings.py b/rootfs/standard/var/www/mynode/settings.py index f64a6859..36943f30 100644 --- a/rootfs/standard/var/www/mynode/settings.py +++ b/rootfs/standard/var/www/mynode/settings.py @@ -564,6 +564,16 @@ def reset_rtl_config_page(): flash("RTL Configuration Reset", category="message") return redirect("/settings") +@mynode_settings.route("/settings/reset-thunderhub-config") +def reset_thunderhub_config_page(): + check_logged_in() + + t = Timer(1.0, reset_thunderhub_config) + t.start() + + flash("Thunderhub Configuration Reset", category="message") + return redirect("/settings") + @mynode_settings.route("/settings/reset-specter-config") def reset_specter_config_page(): check_logged_in() diff --git a/rootfs/standard/var/www/mynode/templates/settings.html b/rootfs/standard/var/www/mynode/templates/settings.html index 5833fa35..6d08d8da 100644 --- a/rootfs/standard/var/www/mynode/templates/settings.html +++ b/rootfs/standard/var/www/mynode/templates/settings.html @@ -1106,6 +1106,17 @@ +
+ +
Thunderhub
+ +
Reset Thunderhub Configuration
+ This will delete your Thunderhub configuration and restart the application. +
+ Reset Configuration +
+ +
BTC RPC Explorer