From 952f48f41ac45de7416b5a9a5ef2be99047582e2 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Thu, 28 Dec 2023 06:16:48 +0100 Subject: [PATCH] edit the 'ip' commands because we need the IP without route too (they may be private IPs) --- scripts/config | 10 ++++++++-- scripts/install | 5 +++-- scripts/restore | 5 +++-- scripts/upgrade | 9 +++++++-- 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/scripts/config b/scripts/config index 35e4c17..a9b878a 100644 --- a/scripts/config +++ b/scripts/config @@ -33,11 +33,17 @@ set__open_port_53() { fi # regenerate config, needed to add or delete public IPs following the user's choice + + # get the name of the network interface in IPv4 and IPv6 + ipv4_interface="$(get_network_interface 4)" + ipv6_interface="$(get_network_interface 6)" + # get IPv4 for the AGH config file - ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)") + ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | grep inet)") # get IPv6 for the AGH config file - ipv6_addr=$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)") + # the 'sed' is used to get rid of the network prefix ('/64' for example) + ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')") # update the IP adresses in the AGH config file update_agh_config diff --git a/scripts/install b/scripts/install index cd17771..3fb1995 100644 --- a/scripts/install +++ b/scripts/install @@ -85,10 +85,11 @@ ipv6_interface="$(get_network_interface 6)" configure_network_interface_dnsmasq "$ipv4_interface" "$ipv6_interface" # get IPv4 for the AGH config file (with a starting "- ") -ipv4_addr=$(echo "- " "$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)")") +ipv4_addr=$(echo "- " "$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | grep inet)")") # get IPv6 for the AGH config file (with a starting "- ") -ipv6_addr=$(echo "- " "$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)")") +# the 'sed' is used to get rid of the network prefix ('/64' for example) +ipv6_addr=$(echo "- " "$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')")") password=$(python3 -c "import bcrypt; print(bcrypt.hashpw(b\"$password\", bcrypt.gensalt(rounds=10)).decode())") ynh_app_setting_set --app="$app" --key=password --value="$password" diff --git a/scripts/restore b/scripts/restore index 18e5cba..961a845 100644 --- a/scripts/restore +++ b/scripts/restore @@ -52,10 +52,11 @@ ipv6_interface="$(get_network_interface 6)" configure_network_interface_dnsmasq "$ipv4_interface" "$ipv6_interface" # get IPv4 for the AGH config file -ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)") +ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | grep inet)") # get IPv6 for the AGH config file -ipv6_addr=$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)") +# the 'sed' is used to get rid of the network prefix ('/64' for example) +ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')") # update the IP adresses in the AGH config file update_agh_config diff --git a/scripts/upgrade b/scripts/upgrade index 3706d5b..4f42065 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -124,11 +124,16 @@ usermod -a -G ssl-cert "$app" #================================================= ynh_script_progression --message="Updating a configuration file..." --weight=1 +# get the name of the network interface in IPv4 and IPv6 +ipv4_interface="$(get_network_interface 4)" +ipv6_interface="$(get_network_interface 6)" + # get IPv4 for the AGH config file -ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)") +ipv4_addr=$(process_ips "$(ip -4 address show "$ipv4_interface" 2> /dev/null | grep inet)") # get IPv6 for the AGH config file -ipv6_addr=$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)") +# the 'sed' is used to get rid of the network prefix ('/64' for example) +ipv6_addr=$(process_ips "$(ip -6 address show "$ipv6_interface" 2> /dev/null | grep inet | sed 's&/.*&&')") # update the IP adresses in the AGH config file update_agh_config