1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/adguardhome_ynh.git synced 2024-09-03 18:06:23 +02:00

rework process_ips()

This commit is contained in:
OniriCorpe 2023-12-28 00:52:42 +01:00
parent a9e36a82ec
commit 1d5e520b73
2 changed files with 12 additions and 6 deletions

View file

@ -60,6 +60,7 @@ process_ips(){
# used to process the IPs to put them in the AGH's config file # used to process the IPs to put them in the AGH's config file
local ips="$1" local ips="$1"
if [ "$2" == "install" ]; then local install=true; fi
for i in $(seq "$(echo "$ips" | wc -w)" -1 1); do for i in $(seq "$(echo "$ips" | wc -w)" -1 1); do
ip=$(echo "$ips" | awk "{print \$$i}") ip=$(echo "$ips" | awk "{print \$$i}")
@ -68,11 +69,16 @@ process_ips(){
# if the IP is public and the user doesn't want to expose port 53, skip it # if the IP is public and the user doesn't want to expose port 53, skip it
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
break break
else
if $install; then
ips="- $ip"
break
else else
ips="$ip" ips="$ip"
break break
fi fi
fi fi
fi
done done
echo "$ips" echo "$ips"

View file

@ -80,11 +80,11 @@ ynh_script_progression --message="Adding a configuration file..." --weight=1
# put the network interface in a dedicated dnsmasq config # put the network interface in a dedicated dnsmasq config
configure_network_interface_dnsmasq configure_network_interface_dnsmasq
# get IPv4 for the AGH config file (with a starting "- ") # 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)")") 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 "- ") # 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)")") 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())") 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" ynh_app_setting_set --app="$app" --key=password --value="$password"