mirror of
https://github.com/YunoHost-Apps/adguardhome_ynh.git
synced 2024-09-03 18:06:23 +02:00
replace two 'for loops' in install & upgrade scripts by process_ips()
This commit is contained in:
parent
5bdc4b9203
commit
a5f4285411
3 changed files with 28 additions and 57 deletions
|
@ -25,6 +25,27 @@ is_public_ip(){
|
|||
fi
|
||||
}
|
||||
|
||||
process_ips(){
|
||||
# used to process the IPs to put them in the AGH's config file
|
||||
|
||||
local ips="$1"
|
||||
|
||||
for i in $(seq "$(echo "$ips" | wc -w)" -1 1); do
|
||||
ip=$(echo "$ips" | awk "{print \$$i}")
|
||||
if ynh_validate_ip4 --ip_address="$ip"; then
|
||||
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
|
||||
# if the IP is public and the user doesn't want to expose port 53, skip it
|
||||
break
|
||||
else
|
||||
ips="- $ip"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
return "$ips"
|
||||
}
|
||||
|
||||
#=================================================
|
||||
# EXPERIMENTAL HELPERS
|
||||
#=================================================
|
||||
|
|
|
@ -97,35 +97,10 @@ systemctl restart dnsmasq
|
|||
ynh_store_file_checksum --file="/etc/dnsmasq.d/$app"
|
||||
|
||||
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")
|
||||
|
||||
ipv6_route_output=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1)
|
||||
|
||||
ipv4_addr=""
|
||||
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
|
||||
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
|
||||
if ynh_validate_ip4 --ip_address="$ip"; then
|
||||
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
|
||||
# if the IP is public and the user doesn't want to expose port 53, skip it
|
||||
break
|
||||
else
|
||||
ipv4_addr="- $ip"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
ipv6_addr=""
|
||||
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
|
||||
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
|
||||
if ynh_validate_ip6 --ip_address="$ip"; then
|
||||
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
|
||||
# if the IP is public and the user doesn't want to expose port 53, skip it
|
||||
break
|
||||
else
|
||||
ipv6_addr="- $ip"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
ipv6_addr=$(process_ips "$ipv6_route_output")
|
||||
|
||||
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"
|
||||
|
|
|
@ -147,36 +147,11 @@ systemctl restart dnsmasq
|
|||
|
||||
ynh_store_file_checksum --file="/etc/dnsmasq.d/$app"
|
||||
|
||||
ipv4_route_output=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1)
|
||||
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")
|
||||
|
||||
ipv6_route_output=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1)
|
||||
|
||||
ipv4_addr=""
|
||||
for i in $(seq "$(echo "$ipv4_route_output" | wc -w)" -1 1); do
|
||||
ip=$(echo "$ipv4_route_output" | awk "{print \$$i}")
|
||||
if ynh_validate_ip4 --ip_address="$ip"; then
|
||||
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
|
||||
# if the IP is public and the user doesn't want to expose port 53, skip it
|
||||
break
|
||||
else
|
||||
ipv4_addr="$ip"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
ipv6_addr=""
|
||||
for i in $(seq "$(echo "$ipv6_route_output" | wc -w)" -1 1); do
|
||||
ip=$(echo "$ipv6_route_output" | awk "{print \$$i}")
|
||||
if ynh_validate_ip6 --ip_address="$ip"; then
|
||||
if is_public_ip "$ip" && [ "$open_port_53" == "false" ] ; then
|
||||
# if the IP is public and the user doesn't want to expose port 53, skip it
|
||||
break
|
||||
else
|
||||
ipv6_addr="$ip"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
ipv6_addr=$(process_ips "$ipv6_route_output")
|
||||
|
||||
# Reset the bind_hosts if the current ip is 0.0.0.0
|
||||
python3 -c "import yaml
|
||||
|
|
Loading…
Add table
Reference in a new issue