Browse Source

Merge pull request #65 from YunoHost-Apps/fix-regenconf

Trying to fix regenconf
Kayou 4 years ago
parent
commit
9cc524fec0

+ 0 - 10
actions.toml

@@ -16,16 +16,6 @@ command = "/bin/bash scripts/actions/reset_default_config \"pihole-FTL.conf\""
 accepted_return_codes = [0]
 accepted_return_codes = [0]
 description = "Reset the config file pihole-FTL.conf."
 description = "Reset the config file pihole-FTL.conf."
 
 
-[reset_default_dnsmasq]
-name = "Reset the config file and restore a default one."
-command = "/bin/bash scripts/actions/reset_default_config \"01-pihole.conf\""
-# user = "root"  # optional
-# cwd = "/" # optional
-# accepted_return_codes = [0, 1, 2, 3]  # optional
-accepted_return_codes = [0]
-description = "Reset the config file dnsmasq.d/01-pihole.conf."
-
-
 [reset_default_nginx]
 [reset_default_nginx]
 name = "Reset the nginx config for this app."
 name = "Reset the nginx config for this app."
 command = "/bin/bash scripts/actions/reset_default_system nginx"
 command = "/bin/bash scripts/actions/reset_default_system nginx"

+ 74 - 48
conf/dnsmasq_regenconf_hook

@@ -1,53 +1,79 @@
 #!/bin/bash
 #!/bin/bash
 
 
-force=${2:-0}  # 0/1 --force argument
-dryrun=${3:-0}  # 0/1 --dry-run argument
-pending_conf=$4 # Path of the pending conf file
-
-temp_dir=/tmp/pi-hole.bck
-
-do_pre_regen() {
-    if [ $dryrun -eq 0 ]
-    then
-        # Créer une sauvegarde des config dnsmasq de pi-hole. Que la regen-conf va sauvagement supprimer
-        mkdir $temp_dir
-        cp -a "/etc/dnsmasq.d/01-pihole.conf" "$temp_dir"
-        test -e "/etc/dnsmasq.d/02-pihole-dhcp.conf" && cp -a "/etc/dnsmasq.d/02-pihole-dhcp.conf" "$temp_dir"
-        test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf" && cp -a "/etc/dnsmasq.d/03-pihole-wildcard.conf" "$temp_dir"
-
-        # Décommente le cache-size de la config par défaut
-        sed --in-place "s/^#pihole# cache-size=/cache-size=/g" /etc/dnsmasq.conf
-        # Et commente celui de pi-hole
-        sed --in-place "s/^cache-size=/#cache-size=/g" /etc/dnsmasq.d/01-pihole.conf
+source /usr/share/yunohost/helpers
+
+app="__APP__"
+
+action=$1
+pending_conf=$4/../dnsmasq
+
+[[ "$action" == "pre" ]] || exit 0
+[[ -d "$pending_conf" ]] || exit 0
+
+#
+# Regen /etc/dnsmasq.d/01-pihole.conf
+#
+dnsmasq_dir="${pending_conf}/etc/dnsmasq.d"
+mkdir -p "$dnsmasq_dir"
+
+cp -a "/etc/.pihole/advanced/01-pihole.conf" "$dnsmasq_dir/"
+
+ynh_replace_string --match_string="@DNS1@" --replace_string="" --target_file="$dnsmasq_dir/01-pihole.conf"
+ynh_replace_string --match_string="@DNS2@" --replace_string="" --target_file="$dnsmasq_dir/01-pihole.conf"
+ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --target_file="$dnsmasq_dir/01-pihole.conf"
+ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file="$dnsmasq_dir/01-pihole.conf"
+query_logging=$(ynh_app_setting_get --app=$app --key=query_logging)
+if [ "$query_logging" = "true" ]; then
+    ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf"
+else
+    ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file="$dnsmasq_dir/01-pihole.conf"
+fi
+
+#
+# Tweak dnsmsasq's general conf cache-size
+#
+
+ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf"
+
+#
+# Regen /etc/dnsmasq.d/02-pihole-dhcp.conf
+#
+
+enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp)
+if [ $enable_dhcp -eq 1 ]
+then
+
+    # Get the default network interface
+    main_iface=$(ip route | grep --max-count=1 default | awk '{print $5;}')
+    # Find the IP associated to the network interface
+    localipv4=$(ip address | grep "${main_iface}\$" | awk '{print $2;}' | cut -d/ -f1)
+
+    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
     fi
-}
-
-do_post_regen() {
-    # Restaure la config dnsmasq de pi-hole
-    cp -a "$temp_dir/01-pihole.conf"	"/etc/dnsmasq.d/"
-    test -e "$temp_dir/02-pihole-dhcp.conf" && cp -a "$temp_dir/02-pihole-dhcp.conf" "/etc/dnsmasq.d/"
-    test -e "$temp_dir/03-pihole-wildcard.conf" && cp -a "$temp_dir/03-pihole-wildcard.conf" "/etc/dnsmasq.d/"
-    # Supprime le dossier temporaire
-    test -n $temp_dir && rm -r $temp_dir
-
-    # Commente le cache-size de la config par défaut
-    sed --in-place "s/^cache-size=/#pihole# cache-size=/g" /etc/dnsmasq.conf
-
-    # Reload dnsmasq
-    systemctl reload dnsmasq
-}
-
-case "$1" in
-    pre)
-        do_pre_regen
-        ;;
-    post)
-        do_post_regen
-        ;;
-    *)
-        echo "Hook called with unknown argument \`$1'" >&2
-        exit 1
-        ;;
-esac
+    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 -a "/etc/yunohost/apps/$app/conf/02-pihole-dhcp.conf" "$dnsmasq_dir/"
+
+    # And set the config
+    ynh_replace_string --match_string="__A_RANGE__" --replace_string="$ip_beginning_part.$a_range" --target_file="${pending_conf}/etc/dnsmasq.d/02-pihole-dhcp.conf"
+    ynh_replace_string --match_string="__B_RANGE__" --replace_string="$ip_beginning_part.$b_range" --target_file="${pending_conf}/etc/dnsmasq.d/02-pihole-dhcp.conf"
+    ynh_replace_string --match_string="__GATEWAY__" --replace_string="$gateway" --target_file="${pending_conf}/etc/dnsmasq.d/02-pihole-dhcp.conf"
 
 
+    # Set a static ip for the server.
+    echo "dhcp-host=$hw_adress,$localipv4" > "${dnsmasq_dir}/04-pihole-static-dhcp.conf"
+fi
 exit 0
 exit 0

+ 6 - 1
scripts/actions/reset_default_app

@@ -31,6 +31,7 @@ app=$YNH_APP_INSTANCE_NAME
 
 
 path_url=$(ynh_app_setting_get --app=$app --key=path)
 path_url=$(ynh_app_setting_get --app=$app --key=path)
 domain=$(ynh_app_setting_get --app=$app --key=domain)
 domain=$(ynh_app_setting_get --app=$app --key=domain)
+final_path=$(ynh_app_setting_get --app=$app --key=final_path)
 pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
 pihole_version="$(ynh_app_setting_get --app=$app --key=pihole_version)"
 
 
 #=================================================
 #=================================================
@@ -228,7 +229,11 @@ ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --ta
 # REINSTALL CONF_REGEN HOOK
 # REINSTALL CONF_REGEN HOOK
 #=================================================
 #=================================================
 
 
-(cd scripts; cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app)
+(
+    cd scripts
+    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"
+)
 
 
 #=================================================
 #=================================================
 # RESTART PIHOLE-FTL
 # RESTART PIHOLE-FTL

+ 0 - 23
scripts/actions/reset_default_config

@@ -34,8 +34,6 @@ if [ "$file" = "setupVars.conf" ]; then
     config_file="/etc/pihole/setupVars.conf"
     config_file="/etc/pihole/setupVars.conf"
 elif [ "$file" = "pihole-FTL.conf" ]; then
 elif [ "$file" = "pihole-FTL.conf" ]; then
     config_file="/etc/pihole/pihole-FTL.conf"
     config_file="/etc/pihole/pihole-FTL.conf"
-elif [ "$file" = "01-pihole.conf" ]; then
-    config_file="/etc/dnsmasq.d/01-pihole.conf"
 fi
 fi
 
 
 #=================================================
 #=================================================
@@ -77,27 +75,6 @@ then
 
 
     # Restart pihole-FTL
     # Restart pihole-FTL
     ynh_systemd_action --action=restart --service_name=pihole-FTL
     ynh_systemd_action --action=restart --service_name=pihole-FTL
-
-elif [ "$file" = "01-pihole.conf" ]
-then
-    cp "$pihole_local_repo/advanced/01-pihole.conf" $config_file
-    # Use dns from /etc/resolv.dnsmasq.conf
-    ynh_replace_string --match_string="@DNS1@" --replace_string="" --target_file=$config_file
-    ynh_replace_string --match_string="@DNS2@" --replace_string="" --target_file=$config_file
-    ynh_replace_string --match_string="^no-resolv" --replace_string="#no-resolv" --target_file=$config_file
-
-    ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file=$config_file
-    if [ "$query_logging" = "true" ]; then
-        ynh_replace_string --match_string="^#log-queries" --replace_string="log-queries" --target_file=$config_file
-    else
-        ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file=$config_file
-    fi
-
-    # Fix a too recent option for our dnsmasq version.
-    ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file=$config_file
-
-    # 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
 fi
 fi
 
 
 # Calculate and store the config file checksum into the app settings
 # Calculate and store the config file checksum into the app settings

+ 0 - 7
scripts/backup

@@ -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="/etc/init.d/pihole-FTL"
 ynh_backup --src_path="/usr/bin/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
 if test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf"; then
     ynh_backup --src_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
     ynh_backup --src_path="/etc/dnsmasq.d/03-pihole-wildcard.conf"
 fi
 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"
 ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app"
 
 

+ 15 - 70
scripts/install

@@ -260,7 +260,7 @@ else
 
 
     # Replace the service dnsmasq by pihole-FTL
     # Replace the service dnsmasq by pihole-FTL
     # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
     # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
-    ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/multi-user.target.wants/dnsmasq.service
+    ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
 
 
     # Reload systemd config
     # Reload systemd config
     systemctl daemon-reload
     systemctl daemon-reload
@@ -290,36 +290,6 @@ echo "INSTALL_WEB=true" >> $setupVars
 # Calculate and store the config file checksum into the app settings
 # Calculate and store the config file checksum into the app settings
 ynh_store_file_checksum --file="$setupVars"
 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
-
-# Calculate and store the config file checksum into the app settings
-ynh_store_file_checksum --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
 # CONFIGURE DNS FOR THE LOCAL DOMAINS
 #=================================================
 #=================================================
@@ -343,37 +313,6 @@ done <<< "$(yunohost domain list | grep "\." | sed 's/.*: \|.*- //')"
 # ENABLE DHCP SERVER
 # 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
 # Open the UDP port 67 for dhcp
 ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
 ynh_exec_fully_quiet yunohost firewall allow UDP 67 --no-upnp
 
 
@@ -408,15 +347,9 @@ then
     ynh_script_progression --message="Restarting Dnsmasq..." --weight=2
     ynh_script_progression --message="Restarting Dnsmasq..." --weight=2
 
 
     ynh_systemd_action --action=restart --service_name=dnsmasq
     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
+    ynh_systemd_action --action=restart --service_name=pihole-FTL
+fi
 
 
 #=================================================
 #=================================================
 # BUILD THE LISTS WITH GRAVITY
 # BUILD THE LISTS WITH GRAVITY
@@ -436,6 +369,18 @@ ynh_exec_warn_less /opt/pihole/gravity.sh
 #=================================================
 #=================================================
 
 
 cp ../conf/dnsmasq_regenconf_hook /usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
 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"
+
+systemctl daemon-reload
+ynh_exec_warn_less 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
 # GENERIC FINALISATION

+ 15 - 18
scripts/remove

@@ -54,7 +54,7 @@ else
     fi
     fi
 
 
     # Move back the service configuration for dnsmasq
     # Move back the service configuration for dnsmasq
-    ynh_secure_remove --file="/etc/systemd/system/multi-user.target.wants/dnsmasq.service"
+    ynh_secure_remove --file="/etc/systemd/system/dnsmasq.service"
     mv /lib/systemd/system/.dnsmasq.service.backup_by_pihole /lib/systemd/system/dnsmasq.service
     mv /lib/systemd/system/.dnsmasq.service.backup_by_pihole /lib/systemd/system/dnsmasq.service
     mv /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq
     mv /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq
 
 
@@ -151,13 +151,7 @@ ynh_secure_remove --file="/etc/sudoers.d/pihole"
 #=================================================
 #=================================================
 ynh_script_progression --message="Removing Dnsmasq config..." --weight=2
 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/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
 
 
 #=================================================
 #=================================================
 # CLEAN /etc/hosts
 # CLEAN /etc/hosts
@@ -171,23 +165,21 @@ ynh_replace_string --match_string="#Commented by pihole# " --replace_string="" -
 sed -i "/#Added by pihole#/d" /etc/hosts
 sed -i "/#Added by pihole#/d" /etc/hosts
 
 
 #=================================================
 #=================================================
-# RESTART DNSMASQ
+# REMOVE CONF_REGEN HOOK
 #=================================================
 #=================================================
-ynh_script_progression --message="Restarting Dnsmasq..."
 
 
-if [ "$pihole_version" == "Last available" ]
-then
-    # Quietly start dnsmasq a first time, because it usually doesn't start correctly the first time.
-    ynh_exec_fully_quiet systemctl start dnsmasq
-    sleep 1
-fi
-ynh_systemd_action --action=restart --service_name=dnsmasq
+ynh_systemd_action --action=stop --service_name=dnsmasq
+
+ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
+
+ynh_exec_warn_less yunohost tools regen-conf dnsmasq
 
 
 #=================================================
 #=================================================
-# REMOVE CONF_REGEN HOOK
+# RESTART DNSMASQ
 #=================================================
 #=================================================
+ynh_script_progression --message="Restarting Dnsmasq..."
 
 
-ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
+ynh_systemd_action --action=restart --service_name=dnsmasq
 
 
 #=================================================
 #=================================================
 # GENERIC FINALISATION
 # GENERIC FINALISATION
@@ -196,6 +188,11 @@ ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app
 #=================================================
 #=================================================
 ynh_script_progression --message="Removing the dedicated system user..." --weight=2
 ynh_script_progression --message="Removing the dedicated system user..." --weight=2
 
 
+if [ "$pihole_version" == "Last 3.X" ]
+then
+    # Dirty hack to remove correctly the user
+    killall -u $app
+fi
 ynh_system_user_delete --username=$app
 ynh_system_user_delete --username=$app
 
 
 #=================================================
 #=================================================

+ 3 - 10
scripts/restore

@@ -182,7 +182,7 @@ then
 
 
     # Replace the service dnsmasq by pihole-FTL
     # Replace the service dnsmasq by pihole-FTL
     # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
     # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
-    ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/multi-user.target.wants/dnsmasq.service
+    ln -s /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
 
 
     # Reload systemd config
     # Reload systemd config
     systemctl daemon-reload
     systemctl daemon-reload
@@ -193,18 +193,11 @@ fi
 #=================================================
 #=================================================
 ynh_script_progression --message="Restoring Dnsmasq config..."
 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" && \
 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"
     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
+systemctl daemon-reload
+ynh_exec_warn_less yunohost tools regen-conf dnsmasq
 
 
 #=================================================
 #=================================================
 # CONFIGURE DNS FOR THE LOCAL DOMAINS
 # CONFIGURE DNS FOR THE LOCAL DOMAINS

+ 12 - 8
scripts/upgrade

@@ -305,7 +305,7 @@ else
 
 
     # Replace the service dnsmasq by pihole-FTL
     # Replace the service dnsmasq by pihole-FTL
     # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
     # That way, YunoHost can continue to use dnsmasq by actually using pihole-FTL
-    ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/multi-user.target.wants/dnsmasq.service
+    ln -sf /run/systemd/generator.late/pihole-FTL.service /etc/systemd/system/dnsmasq.service
 
 
     # Reload systemd config
     # Reload systemd config
     systemctl daemon-reload
     systemctl daemon-reload
@@ -355,13 +355,6 @@ fi
 # Remove git usage for version. Which fails because we use here a release instead of master.
 # 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
 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
 # ADVERTISE SERVICE IN ADMIN PANEL
 #=================================================
 #=================================================
@@ -373,6 +366,17 @@ 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
 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"
+
+systemctl daemon-reload
+ynh_exec_warn_less 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
 # RELOAD NGINX