From 9e24b6163764feb211dfa7a46a9815bc0e926c03 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Wed, 27 Dec 2023 19:40:24 +0100 Subject: [PATCH] refactor commands to get IPs --- scripts/config | 6 ++---- scripts/install | 7 ++----- scripts/restore | 6 ++---- scripts/upgrade | 6 ++---- 4 files changed, 8 insertions(+), 17 deletions(-) diff --git a/scripts/config b/scripts/config index a5c77f6..f18214f 100644 --- a/scripts/config +++ b/scripts/config @@ -34,12 +34,10 @@ set__open_port_53() { # regenerate config, needed to add or delete public IPs following the user's choice # get IPv4 for the AGH config file - ipv4_route_output=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | head -n1) - ipv4_addr=$(process_ips "$ipv4_route_output") + ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)") # get IPv6 for the AGH config file - ipv6_route_output=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1) - ipv6_addr=$(process_ips "$ipv6_route_output") + ipv6_addr=$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)") # update the IP adresses in the AGH config file update_config diff --git a/scripts/install b/scripts/install index 4e4eaf0..9797faa 100644 --- a/scripts/install +++ b/scripts/install @@ -39,7 +39,6 @@ fi ynh_app_setting_set --app="$app" --key=open_port_53 --value="$open_port_53" - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= @@ -97,12 +96,10 @@ systemctl restart dnsmasq ynh_store_file_checksum --file="/etc/dnsmasq.d/$app" # get IPv4 for the AGH config file -ipv4_route_output=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | head -n1) -ipv4_addr=$(process_ips "$ipv4_route_output") +ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)") # get IPv6 for the AGH config file -ipv6_route_output=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1) -ipv6_addr=$(process_ips "$ipv6_route_output") +ipv6_addr=$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)") 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 e4abd84..d028225 100644 --- a/scripts/restore +++ b/scripts/restore @@ -45,12 +45,10 @@ ynh_restore_file --origin_path="$install_dir" # environment, else AGH will try to bind port 53 on non-existent IPs and crash # get IPv4 for the AGH config file -ipv4_route_output=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | head -n1) -ipv4_addr=$(process_ips "$ipv4_route_output") +ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)") # get IPv6 for the AGH config file -ipv6_route_output=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1) -ipv6_addr=$(process_ips "$ipv6_route_output") +ipv6_addr=$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)") # update the IP adresses in the AGH config file update_config diff --git a/scripts/upgrade b/scripts/upgrade index 41c1a14..e9b0afe 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -148,12 +148,10 @@ systemctl restart dnsmasq ynh_store_file_checksum --file="/etc/dnsmasq.d/$app" # get IPv4 for the AGH config file -ipv4_route_output=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | head -n1) -ipv4_addr=$(process_ips "$ipv4_route_output") +ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)") # get IPv6 for the AGH config file -ipv6_route_output=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1) -ipv6_addr=$(process_ips "$ipv6_route_output") +ipv6_addr=$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)") # update the IP adresses in the AGH config file update_config