From 6990346014ebcd6c22d29458b984765ea17b032f Mon Sep 17 00:00:00 2001 From: ashley Date: Tue, 9 Sep 2025 11:48:53 +0200 Subject: [PATCH] add ip change --- backend-services/scripts/ip.sh | 37 ++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 backend-services/scripts/ip.sh diff --git a/backend-services/scripts/ip.sh b/backend-services/scripts/ip.sh new file mode 100644 index 00000000..ca4eff4a --- /dev/null +++ b/backend-services/scripts/ip.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +#CHANGE BOTH OF THESE TO THE CORRECT VALUES +domain="server_ddns_ip_here" +wireguard_file="/path/to/wg0.conf" + +new_ip=$(dig +short "$domain" | tail -n1) +current_ip=$(grep -Eo 'Endpoint = [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' "$wireguard_file" | awk '{print $3}') + +while true; do +read -p "Are you sure you want to run this? Have you checked the gluetun logs first? [Yy/Nn]" yn +case $yn in Y|y|Yes|yes* ) + if [[ "$new_ip" == "$current_ip" ]]; then + echo "IP is already up to date: $current_ip" + exit 0 +else + sed -i -r "s/^(Endpoint = +)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)(:[0-9]+)/\1$new_ip\3/" "$wireguard_file" + + echo "IP updated in $wireguard_file, new IP is: $(grep '^Endpoint' "$wireguard_file")" + + echo "Restarting gluetun..." + + docker restart gluetun >/dev/null 2>&1 + + echo "Restarting companion..." + + docker restart invidious-companion-1 >/dev/null 2>&1 + +exit 0 +fi +;; + +N|n|No|no* ) exit;; + * ) echo "Please answer yes or no.";; + + esac +done