mirror of
https://github.com/YunoHost-Apps/adguardhome_ynh.git
synced 2024-09-03 18:06:23 +02:00
mopved all the code to create a dnsmask config with the network interface to personal helpers
This commit is contained in:
parent
7e74ca5827
commit
b95d192aa6
4 changed files with 33 additions and 42 deletions
|
@ -8,6 +8,31 @@
|
|||
# PERSONAL HELPERS
|
||||
#=================================================
|
||||
|
||||
configure_network_interface_dnsmasq(){
|
||||
# used to put the network interface in a dedicated dnsmasq config
|
||||
|
||||
ipv4_interface=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
ipv6_interface=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
|
||||
if [ -z "$ipv4_interface" ] && [ -z "$ipv6_interface" ]; then
|
||||
ynh_die --message="Impossible to find the main network interface, please report this issue."
|
||||
elif [ "$ipv4_interface" != "$ipv6_interface" ]; then
|
||||
if [ -z "$ipv4_interface" ]; then
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv6_interface" > "/etc/dnsmasq.d/$app"
|
||||
elif [ -z "$ipv6_interface" ]; then
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface" > "/etc/dnsmasq.d/$app"
|
||||
else
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface, $ipv6_interface" > "/etc/dnsmasq.d/$app"
|
||||
fi
|
||||
else
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface" > "/etc/dnsmasq.d/$app"
|
||||
fi
|
||||
|
||||
systemctl restart dnsmasq
|
||||
|
||||
ynh_store_file_checksum --file="/etc/dnsmasq.d/$app"
|
||||
}
|
||||
|
||||
is_public_ip(){
|
||||
# used to discriminate publics IPs over privates IPs
|
||||
# private IPv4 start with: 10.; 169.; 172. or 192.168.
|
||||
|
|
|
@ -77,27 +77,8 @@ usermod -a -G ssl-cert "$app"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Adding a configuration file..." --weight=1
|
||||
|
||||
# echo the ip route command to prevent a crash if the server doesn't have any ipv4/6
|
||||
ipv4_interface=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
ipv6_interface=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
|
||||
if [ -z "$ipv4_interface" ] && [ -z "$ipv6_interface" ]; then
|
||||
ynh_die --message="Impossible to find the main network interface, please report this issue."
|
||||
elif [ "$ipv4_interface" != "$ipv6_interface" ]; then
|
||||
if [ -z "$ipv4_interface" ]; then
|
||||
echo -e "bind-interface\nexcept-interface=$ipv6_interface" > "/etc/dnsmasq.d/$app"
|
||||
elif [ -z "$ipv6_interface" ]; then
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface" > "/etc/dnsmasq.d/$app"
|
||||
else
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface, $ipv6_interface" > "/etc/dnsmasq.d/$app"
|
||||
fi
|
||||
else
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface" > "/etc/dnsmasq.d/$app"
|
||||
fi
|
||||
|
||||
systemctl restart dnsmasq
|
||||
|
||||
ynh_store_file_checksum --file="/etc/dnsmasq.d/$app"
|
||||
# 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)")
|
||||
|
|
|
@ -41,9 +41,12 @@ ynh_script_progression --message="Restoring the app main directory..." --weight=
|
|||
|
||||
ynh_restore_file --origin_path="$install_dir"
|
||||
|
||||
# we need to update IP adresses in case the backup is restored in a different
|
||||
# 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
|
||||
|
||||
# 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)")
|
||||
|
||||
|
|
|
@ -126,26 +126,8 @@ usermod -a -G ssl-cert "$app"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
||||
|
||||
ipv4_interface=$(echo "$(ip -4 route get 1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
ipv6_interface=$(echo "$(ip -6 route get ::1.2.3.4 2> /dev/null)" | head -n1 | grep -oP '(?<=dev )\w+' || true)
|
||||
|
||||
if [ -z "$ipv4_interface" ] && [ -z "$ipv6_interface" ]; then
|
||||
ynh_die --message="Impossible to find the main network interface, please report this issue."
|
||||
elif [ "$ipv4_interface" != "$ipv6_interface" ]; then
|
||||
if [ -z "$ipv4_interface" ]; then
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv6_interface" > "/etc/dnsmasq.d/$app"
|
||||
elif [ -z "$ipv6_interface" ]; then
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface" > "/etc/dnsmasq.d/$app"
|
||||
else
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface, $ipv6_interface" > "/etc/dnsmasq.d/$app"
|
||||
fi
|
||||
else
|
||||
echo -e "bind-interfaces\nexcept-interface=$ipv4_interface" > "/etc/dnsmasq.d/$app"
|
||||
fi
|
||||
|
||||
systemctl restart dnsmasq
|
||||
|
||||
ynh_store_file_checksum --file="/etc/dnsmasq.d/$app"
|
||||
# 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