From 381a255ea9c2a91488e1a3b09fb8f2516cf3e80b Mon Sep 17 00:00:00 2001 From: dramirezRT Date: Sun, 4 Dec 2022 21:36:04 +0100 Subject: [PATCH 1/2] Proper ip cleanup when updating ISP IP @Cabecinha84 @TechDufus @XK4MiLX For reference from https://github.com/RunOnFlux/fluxnode-multitool/pull/10 --- flux_common.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/flux_common.sh b/flux_common.sh index 6b134e47..94e90a2b 100644 --- a/flux_common.sh +++ b/flux_common.sh @@ -1695,6 +1695,7 @@ function selfhosting() { sudo chown $USER:$USER /home/$USER/ip_check.sh cat <<-'EOF' > /home/$USER/ip_check.sh #!/bin/bash + USER=$(whoami) function get_ip(){ WANIP=$(curl --silent -m 10 https://api4.my-ip.io/ip | tr -dc '[:alnum:].') @@ -1724,6 +1725,11 @@ function selfhosting() { if [[ "$device_name" != "" && "$WANIP" != "" ]]; then date_timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "New IP detected, IP: $WANIP was added at $date_timestamp" >> /home/$USER/ip_history.log + for i in $(ip --oneline addr show ${device_name}:0 | grep "/32" | awk '{print $4}'); + do + [[ $i == "${WANIP}/32" ]] && exit 0 + sudo ip addr del $i dev $device_name:0 + done sudo ip addr add $WANIP dev $device_name && sleep 2 fi fi @@ -1734,11 +1740,19 @@ function selfhosting() { if [[ "$api_port" == "" ]]; then api_port="16127" fi - confirmed_ip=$(curl -SsL -m 10 http://localhost:$api_port/flux/info | jq -r .data.node.status.ip | sed -r 's/:.+//') + confirmed_ip=$(curl -SsL --retry 5 -m 10 http://localhost:$api_port/flux/info | jq -r .data.node.status.ip | sed -r 's/:.+//') if [[ "$WANIP" != "" && "$confirmed_ip" != "" ]]; then if [[ "$WANIP" != "$confirmed_ip" ]]; then + current_reg_ip=$(ip --oneline addr show ${device_name} | grep "/32" | awk '{print $4}') + [[ "${WANIP}/32" == "${current_reg_ip}" ]] && exit 0 + date_timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "New IP detected, IP: $WANIP was added at $date_timestamp" >> /home/$USER/ip_history.log + for i in $(ip --oneline addr show ${device_name} | grep "/32" | awk '{print $4}'); + do + [[ $i == "${WANIP}/32" ]] && exit 0 + sudo ip addr del $i dev $device_name + done sudo ip addr add $WANIP dev $device_name && sleep 2 fi fi From dfc8652579038125263e9cf1ccf35753b39f4e3c Mon Sep 17 00:00:00 2001 From: dramirezRT Date: Sun, 4 Dec 2022 21:43:03 +0100 Subject: [PATCH 2/2] Update flux_common.sh --- flux_common.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flux_common.sh b/flux_common.sh index 94e90a2b..f6f515c6 100644 --- a/flux_common.sh +++ b/flux_common.sh @@ -1725,10 +1725,10 @@ function selfhosting() { if [[ "$device_name" != "" && "$WANIP" != "" ]]; then date_timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo -e "New IP detected, IP: $WANIP was added at $date_timestamp" >> /home/$USER/ip_history.log - for i in $(ip --oneline addr show ${device_name}:0 | grep "/32" | awk '{print $4}'); + for i in $(ip --oneline addr show ${device_name} | grep "/32" | awk '{print $4}'); do [[ $i == "${WANIP}/32" ]] && exit 0 - sudo ip addr del $i dev $device_name:0 + sudo ip addr del $i dev $device_name done sudo ip addr add $WANIP dev $device_name && sleep 2 fi