mirror of
https://github.com/YunoHost-Apps/pihole_ynh.git
synced 2024-09-03 20:05:58 +02:00
manage all dnsmasq conf by the regenconf
This commit is contained in:
parent
a09381efeb
commit
ff32be711d
5 changed files with 28 additions and 98 deletions
|
@ -77,16 +77,9 @@ ynh_backup --src_path="/etc/sudoers.d/pihole"
|
|||
ynh_backup --src_path="/etc/init.d/pihole-FTL"
|
||||
ynh_backup --src_path="/usr/bin/pihole-FTL"
|
||||
|
||||
ynh_backup --src_path="/etc/dnsmasq.d/01-pihole.conf"
|
||||
if test -e "/etc/dnsmasq.d/02-pihole-dhcp.conf"; then
|
||||
ynh_backup --src_path="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
fi
|
||||
if test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf"; then
|
||||
ynh_backup --src_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||
fi
|
||||
if test -e "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"; then
|
||||
ynh_backup --src_path="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
|
||||
fi
|
||||
|
||||
ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
|
||||
|
||||
|
|
|
@ -290,33 +290,6 @@ echo "INSTALL_WEB=true" >> $setupVars
|
|||
# Calculate and store the config file checksum into the app settings
|
||||
ynh_store_file_checksum --file="$setupVars"
|
||||
|
||||
#=================================================
|
||||
# SET UP DNSMASQ CONFIG
|
||||
#=================================================
|
||||
ynh_script_progression --message="Setting up Dnsmasq config..." --weight=2
|
||||
|
||||
# ynh_systemd_action --action=stop --service_name=dnsmasq
|
||||
|
||||
pihole_dnsmasq_config="/etc/dnsmasq.d/01-pihole.conf"
|
||||
cp "$pihole_local_repo/advanced/01-pihole.conf" $pihole_dnsmasq_config
|
||||
# Use dns from /etc/resolv.dnsmasq.conf
|
||||
ynh_replace_string --match_string="@DNS1@" --replace_string="" --target_file=$pihole_dnsmasq_config
|
||||
ynh_replace_string --match_string="@DNS2@" --replace_string="" --target_file=$pihole_dnsmasq_config
|
||||
ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --target_file=$pihole_dnsmasq_config
|
||||
|
||||
ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file=$pihole_dnsmasq_config
|
||||
if [ "$query_logging" = "true" ]; then
|
||||
ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file=$pihole_dnsmasq_config
|
||||
else
|
||||
ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file=$pihole_dnsmasq_config
|
||||
fi
|
||||
|
||||
# Fix a too recent option for our dnsmasq version.
|
||||
ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file=$pihole_dnsmasq_config
|
||||
|
||||
# To prevent any conflict with the original dnsmasq config, comment cache-size in the original config.
|
||||
ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file=/etc/dnsmasq.conf
|
||||
|
||||
#=================================================
|
||||
# CONFIGURE DNS FOR THE LOCAL DOMAINS
|
||||
#=================================================
|
||||
|
@ -340,37 +313,6 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
|
|||
# ENABLE DHCP SERVER
|
||||
#=================================================
|
||||
|
||||
if [ $enable_dhcp -eq 1 ]
|
||||
then
|
||||
ynh_script_progression --message="Enabling dhcp server..."
|
||||
max_dhcp_range=250
|
||||
dhcp_range=100
|
||||
# Define the dhcp range from the current ip
|
||||
ip_beginning_part=$(echo "$localipv4" | cut -d. -f1-3)
|
||||
ip_fourth_part=$(echo "$localipv4" | cut -d. -f4)
|
||||
b_range=$(( $ip_fourth_part + $dhcp_range ))
|
||||
if [ $b_range -gt $max_dhcp_range ]; then
|
||||
b_range=$max_dhcp_range
|
||||
fi
|
||||
a_range=$(( $b_range - $dhcp_range ))
|
||||
|
||||
# Get the gateway
|
||||
gateway=$(ip route | grep default | awk '{print $3;}')
|
||||
# And the mac adress
|
||||
hw_adress=$(ip link | grep -A1 "$main_iface" | tail -n1 | awk '{print $2;}')
|
||||
|
||||
# Copy the config file
|
||||
cp "../conf/02-pihole-dhcp.conf" "/etc/dnsmasq.d/"
|
||||
|
||||
# And set the config
|
||||
ynh_replace_string --match_string="__A_RANGE__" --replace_string="$ip_beginning_part.$a_range" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
ynh_replace_string --match_string="__B_RANGE__" --replace_string="$ip_beginning_part.$b_range" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
ynh_replace_string --match_string="__GATEWAY__" --replace_string="$gateway" --target_file="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
|
||||
# Set a static ip for the server.
|
||||
echo "dhcp-host=$hw_adress,$localipv4" > "/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
|
||||
fi
|
||||
|
||||
# Open the UDP port 67 for dhcp
|
||||
ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
|
||||
|
||||
|
@ -407,14 +349,6 @@ then
|
|||
ynh_systemd_action --action=restart --service_name=dnsmasq
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
# START PIHOLE-FTL
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2
|
||||
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL
|
||||
|
||||
#=================================================
|
||||
# BUILD THE LISTS WITH GRAVITY
|
||||
#=================================================
|
||||
|
@ -435,6 +369,16 @@ ynh_exec_warn_less /opt/pihole/gravity.sh
|
|||
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
|
||||
|
||||
yunohost tools regen-conf dnsmasq
|
||||
|
||||
#=================================================
|
||||
# START PIHOLE-FTL
|
||||
#=================================================
|
||||
|
||||
ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2
|
||||
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
|
|
|
@ -152,10 +152,7 @@ ynh_secure_remove --file="/etc/sudoers.d/pihole"
|
|||
ynh_script_progression --message="Removing Dnsmasq config..." --weight=2
|
||||
|
||||
ynh_systemd_action --action=stop --service_name=dnsmasq
|
||||
ynh_secure_remove --file="/etc/dnsmasq.d/01-pihole.conf"
|
||||
ynh_secure_remove --file="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
ynh_secure_remove --file="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||
ynh_secure_remove --file="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
|
||||
|
||||
ynh_replace_string --match_string="#pihole# " --replace_string="" --target_file=/etc/dnsmasq.conf
|
||||
|
||||
|
@ -170,6 +167,14 @@ ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" -
|
|||
# And remove extra lines, added by PiHole
|
||||
sed -i "/#Added by pihole#/d" /etc/hosts
|
||||
|
||||
#=================================================
|
||||
# REMOVE CONF_REGEN HOOK
|
||||
#=================================================
|
||||
|
||||
ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
|
||||
|
||||
yunohost tools regen-conf dnsmasq
|
||||
|
||||
#=================================================
|
||||
# RESTART DNSMASQ
|
||||
#=================================================
|
||||
|
@ -183,12 +188,6 @@ then
|
|||
fi
|
||||
ynh_systemd_action --action=restart --service_name=dnsmasq
|
||||
|
||||
#=================================================
|
||||
# REMOVE CONF_REGEN HOOK
|
||||
#=================================================
|
||||
|
||||
ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
|
||||
|
||||
#=================================================
|
||||
# GENERIC FINALISATION
|
||||
#=================================================
|
||||
|
|
|
@ -193,18 +193,10 @@ fi
|
|||
#=================================================
|
||||
ynh_script_progression --message="Restoring Dnsmasq config..."
|
||||
|
||||
ynh_systemd_action --action=stop --service_name=dnsmasq
|
||||
|
||||
ynh_restore_file --origin_path="/etc/dnsmasq.d/01-pihole.conf"
|
||||
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/02-pihole-dhcp.conf" && \
|
||||
ynh_restore_file --origin_path="/etc/dnsmasq.d/02-pihole-dhcp.conf"
|
||||
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/03-pihole-wildcard.conf" && \
|
||||
ynh_restore_file --origin_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
|
||||
test -e "${YNH_APP_BACKUP_DIR}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" && \
|
||||
ynh_restore_file --origin_path="/etc/dnsmasq.d/04-pihole-static-dhcp.conf"
|
||||
|
||||
# To prevent any conflict with the original dnsmasq config, comment cache-size in the original config.
|
||||
ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file=/etc/dnsmasq.conf
|
||||
yunohost tools regen-conf dnsmasq
|
||||
|
||||
#=================================================
|
||||
# CONFIGURE DNS FOR THE LOCAL DOMAINS
|
||||
|
|
|
@ -355,13 +355,6 @@ fi
|
|||
# Remove git usage for version. Which fails because we use here a release instead of master.
|
||||
ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --target_file=/etc/cron.d/pihole
|
||||
|
||||
#=================================================
|
||||
# START PIHOLE-FTL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2
|
||||
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL
|
||||
|
||||
#=================================================
|
||||
# ADVERTISE SERVICE IN ADMIN PANEL
|
||||
#=================================================
|
||||
|
@ -375,6 +368,15 @@ yunohost service add pihole-FTL --description="PiHole backend service" --log="/v
|
|||
cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
|
||||
ynh_replace_string --match_string="__APP__" --replace_string="$app" --target_file="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
|
||||
|
||||
yunohost tools regen-conf dnsmasq
|
||||
|
||||
#=================================================
|
||||
# START PIHOLE-FTL
|
||||
#=================================================
|
||||
ynh_script_progression --message="Restarting PiHole-FTL..." --weight=2
|
||||
|
||||
ynh_systemd_action --action=restart --service_name=pihole-FTL
|
||||
|
||||
#=================================================
|
||||
# RELOAD NGINX
|
||||
#=================================================
|
||||
|
|
Loading…
Add table
Reference in a new issue