mirror of
https://github.com/YunoHost-Apps/adguardhome_ynh.git
synced 2024-09-03 18:06:23 +02:00
new function: get_network_interface()
This commit is contained in:
parent
cd382bed1c
commit
f4f916a8b2
4 changed files with 22 additions and 11 deletions
|
@ -8,15 +8,21 @@
|
|||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
get_network_interface(){
|
||||
# get the network interface name for IPv4 and IPv6
|
||||
|
||||
local IPvx="$1"
|
||||
|
||||
# note: echo the IP route command to prevent a crash if the server doesn't have any IPv4/6
|
||||
# shellcheck disable=SC2005
|
||||
echo ipv4_interface="$(echo "$(ip -"$IPvx" route get 1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)"
|
||||
}
|
||||
|
||||
configure_network_interface_dnsmasq(){
|
||||
# used to put the network interface in a dedicated dnsmasq config
|
||||
|
||||
# get the network interface name for IPv4 and IPv6
|
||||
# note: echo the IP route command to prevent a crash if the server doesn't have any IPv4/6
|
||||
# shellcheck disable=SC2005
|
||||
ipv4_interface=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
# shellcheck disable=SC2005
|
||||
ipv6_interface=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
local ipv4_interface="$1"
|
||||
local ipv6_interface="$2"
|
||||
|
||||
if [ -z "$ipv4_interface" ] && [ -z "$ipv6_interface" ]; then
|
||||
ynh_die --message="Impossible to find the main network interface, please report this issue."
|
||||
|
|
|
@ -77,8 +77,12 @@ usermod -a -G ssl-cert "$app"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Adding 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)"
|
||||
|
||||
# put the network interface in a dedicated dnsmasq config
|
||||
configure_network_interface_dnsmasq
|
||||
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)")")
|
||||
|
|
|
@ -44,8 +44,12 @@ ynh_restore_file --origin_path="$install_dir"
|
|||
# we need to refresh IP adresses in case the backup is restored in a different
|
||||
# environment, else AGH will try to bind port 53 on non-existent IPs and crash
|
||||
|
||||
# get the name of the network interface in IPv4 and IPv6
|
||||
ipv4_interface="$(get_network_interface 4)"
|
||||
ipv6_interface="$(get_network_interface 6)"
|
||||
|
||||
# put the network interface in a dedicated dnsmasq config
|
||||
configure_network_interface_dnsmasq
|
||||
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)")
|
||||
|
|
|
@ -124,9 +124,6 @@ usermod -a -G ssl-cert "$app"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Updating 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
|
||||
ipv4_addr=$(process_ips "$(ip -4 route get 1.2.3.4 2> /dev/null | head -n1 | head -n1)")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue