From 1d5e520b73eaecd3d1e13cc69adb55bf45992499 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Thu, 28 Dec 2023 00:52:42 +0100 Subject: [PATCH] rework process_ips() --- scripts/_common.sh | 10 ++++++++-- scripts/install | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 87d70ed..f67a2ca 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -60,6 +60,7 @@ process_ips(){ # used to process the IPs to put them in the AGH's config file local ips="$1" + if [ "$2" == "install" ]; then local install=true; fi for i in $(seq "$(echo "$ips" | wc -w)" -1 1); do ip=$(echo "$ips" | awk "{print \$$i}") @@ -69,8 +70,13 @@ process_ips(){ if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then break else - ips="$ip" - break + if $install; then + ips="- $ip" + break + else + ips="$ip" + break + fi fi fi done diff --git a/scripts/install b/scripts/install index 4bca14c..daed02f 100644 --- a/scripts/install +++ b/scripts/install @@ -80,11 +80,11 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1 # put the network interface in a dedicated dnsmasq config configure_network_interface_dnsmasq -# 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)")") +# get IPv4 for the AGH config file (special argument "install" at the end to get a starting "- " by IP) +ipv4_addr=$(echo "- " "$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)" install)") -# 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)")") +# get IPv6 for the AGH config file (special argument "install" at the end to get a starting "- " by IP) +ipv6_addr=$(echo "- " "$(process_ips "$(ip -6 route get ::1.2.3.4 2> /dev/null | head -n1)" install)") 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"