From 42b50d0c2963b0614d47bbee35c09b067e4550a9 Mon Sep 17 00:00:00 2001 From: mrhotio <26902309+mrhotio@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:25:20 +0100 Subject: [PATCH] only update on port change --- .../s6-overlay/s6-rc.d/service-proton/finish | 4 ++++ root/etc/s6-overlay/s6-rc.d/service-proton/run | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 root/etc/s6-overlay/s6-rc.d/service-proton/finish diff --git a/root/etc/s6-overlay/s6-rc.d/service-proton/finish b/root/etc/s6-overlay/s6-rc.d/service-proton/finish new file mode 100644 index 000000000..1370c60a0 --- /dev/null +++ b/root/etc/s6-overlay/s6-rc.d/service-proton/finish @@ -0,0 +1,4 @@ +#!/command/with-contenv bash +# shellcheck shell=bash + +rm -rf "${CONFIG_DIR}/forwarded_port" diff --git a/root/etc/s6-overlay/s6-rc.d/service-proton/run b/root/etc/s6-overlay/s6-rc.d/service-proton/run index 745a70156..8e4500d7b 100644 --- a/root/etc/s6-overlay/s6-rc.d/service-proton/run +++ b/root/etc/s6-overlay/s6-rc.d/service-proton/run @@ -13,13 +13,18 @@ while true; do port=$(natpmpc -g "${vpn_gw}" -a 1 0 udp 60 | grep -P -o -m 1 '(?<=Mapped public port\s)\d+') if [[ -n "${port}" ]]; then natpmpc -g "${vpn_gw}" -a 1 0 tcp 60 &> /dev/null - webui_https="http" - if grep -q 'WebUI\\HTTPS\\Enabled=true' "${CONFIG_DIR}/config/qBittorrent.conf"; then - webui_https="https" + touch "${CONFIG_DIR}/forwarded_port" + old_port=$(cat "${CONFIG_DIR}/forwarded_port") + if [[ "${port}" != "${old_port}" ]]; then + echo "${port}" > "${CONFIG_DIR}/forwarded_port" + webui_https="http" + if grep -q 'WebUI\\HTTPS\\Enabled=true' "${CONFIG_DIR}/config/qBittorrent.conf"; then + webui_https="https" + fi + curl -fsSL --insecure -X POST -d "json={\"upnp\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences" + curl -fsSL --insecure -X POST -d "json={\"random_port\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences" + curl -fsSL --insecure -X POST -d "json={\"listen_port\": ${port}}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences" fi - curl -fsSL --insecure -X POST -d "json={\"upnp\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences" - curl -fsSL --insecure -X POST -d "json={\"random_port\": false}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences" - curl -fsSL --insecure -X POST -d "json={\"listen_port\": ${port}}" "${webui_https}://localhost:${WEBUI_PORTS%%/*}/api/v2/app/setPreferences" echo "[INFO] [$(date '+%Y-%m-%d %H:%M:%S')] ProtonVPN forwarded port is \"${port}\"." else echo "[WARNING] [$(date '+%Y-%m-%d %H:%M:%S')] ProtonVPN port forwarding failed!"