From 82ae8d433a9bb7505914eb3db0560ee983259cb1 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 14:01:46 +0200 Subject: [PATCH 1/9] Trying to fix regenconf --- conf/dnsmasq_regenconf_hook | 66 +++++++++++++++++++++---------- scripts/actions/reset_default_app | 6 ++- scripts/install | 3 +- scripts/remove | 2 +- scripts/restore | 2 +- scripts/upgrade | 3 +- 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/conf/dnsmasq_regenconf_hook b/conf/dnsmasq_regenconf_hook index 0e4c2ef..b54edfd 100755 --- a/conf/dnsmasq_regenconf_hook +++ b/conf/dnsmasq_regenconf_hook @@ -1,38 +1,64 @@ #!/bin/bash +source /usr/share/yunohost/helpers + 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 +app="__APP__" do_pre_regen() { if [ $dryrun -eq 0 ] then + dnsmasq_dir="${pending_conf}/etc/dnsmasq.d" + mkdir -p "$dnsmasq_dir" + cp -a "/etc/dnsmasq.conf" "${pending_conf}/etc/dnsmasq.conf" # 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" + cp -a "/etc/dnsmasq.d/01-pihole.conf" "$dnsmasq_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 + ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.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 + 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" > "${pending_conf}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" + 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 } diff --git a/scripts/actions/reset_default_app b/scripts/actions/reset_default_app index 8e3fba5..301406d 100755 --- a/scripts/actions/reset_default_app +++ b/scripts/actions/reset_default_app @@ -228,7 +228,11 @@ ynh_replace_string --match_string=".*updatechecker.*" --replace_string="#&" --ta # 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 diff --git a/scripts/install b/scripts/install index 9c3c494..6df124b 100644 --- a/scripts/install +++ b/scripts/install @@ -260,7 +260,7 @@ else # Replace the service dnsmasq by 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 systemctl daemon-reload @@ -436,6 +436,7 @@ 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" #================================================= # GENERIC FINALISATION diff --git a/scripts/remove b/scripts/remove index b9e9537..99a9f82 100755 --- a/scripts/remove +++ b/scripts/remove @@ -54,7 +54,7 @@ else fi # 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 /etc/init.d/.dnsmasq.backup_by_pihole /etc/init.d/dnsmasq diff --git a/scripts/restore b/scripts/restore index 2cf05da..628b1c8 100644 --- a/scripts/restore +++ b/scripts/restore @@ -182,7 +182,7 @@ then # Replace the service dnsmasq by 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 systemctl daemon-reload diff --git a/scripts/upgrade b/scripts/upgrade index eea787a..2806466 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -305,7 +305,7 @@ else # Replace the service dnsmasq by 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 systemctl daemon-reload @@ -373,6 +373,7 @@ 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" #================================================= # RELOAD NGINX From 57c86aaa1549dc73dbf90f7a152da1eef1e781f8 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 14:20:55 +0200 Subject: [PATCH 2/9] use the template version of 01-pihole.conf --- conf/dnsmasq_regenconf_hook | 15 ++++++++++++++- scripts/install | 3 --- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/conf/dnsmasq_regenconf_hook b/conf/dnsmasq_regenconf_hook index b54edfd..f9341bf 100755 --- a/conf/dnsmasq_regenconf_hook +++ b/conf/dnsmasq_regenconf_hook @@ -14,7 +14,20 @@ do_pre_regen() { mkdir -p "$dnsmasq_dir" cp -a "/etc/dnsmasq.conf" "${pending_conf}/etc/dnsmasq.conf" # Créer une sauvegarde des config dnsmasq de pi-hole. Que la regen-conf va sauvagement supprimer - cp -a "/etc/dnsmasq.d/01-pihole.conf" "$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" + 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 + + # Fix a too recent option for our dnsmasq version. + ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf" ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf" diff --git a/scripts/install b/scripts/install index 6df124b..0450562 100644 --- a/scripts/install +++ b/scripts/install @@ -314,9 +314,6 @@ 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 From e68ad3f8ba15fc072f3021c5d24bcb5ea786ca79 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Tue, 14 Sep 2021 14:31:20 +0200 Subject: [PATCH 3/9] Yolorework the regenconf script --- conf/dnsmasq_regenconf_hook | 133 +++++++++++++++++------------------- 1 file changed, 62 insertions(+), 71 deletions(-) diff --git a/conf/dnsmasq_regenconf_hook b/conf/dnsmasq_regenconf_hook index f9341bf..7394955 100755 --- a/conf/dnsmasq_regenconf_hook +++ b/conf/dnsmasq_regenconf_hook @@ -2,91 +2,82 @@ source /usr/share/yunohost/helpers -force=${2:-0} # 0/1 --force argument -dryrun=${3:-0} # 0/1 --dry-run argument -pending_conf=$4 # Path of the pending conf file app="__APP__" -do_pre_regen() { - if [ $dryrun -eq 0 ] - then - dnsmasq_dir="${pending_conf}/etc/dnsmasq.d" - mkdir -p "$dnsmasq_dir" - cp -a "/etc/dnsmasq.conf" "${pending_conf}/etc/dnsmasq.conf" - # Créer une sauvegarde des config dnsmasq de pi-hole. Que la regen-conf va sauvagement supprimer - 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" +action=$1 +pending_conf=$4/../dnsmasq - ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file="$dnsmasq_dir/01-pihole.conf" - 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 +[[ "$action" == "pre" ]] || exit 0 +[[ -d "$pending_conf" ]] || exit 0 - # Fix a too recent option for our dnsmasq version. - ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf" +# +# Regen /etc/dnsmasq.d/01-pihole.conf +# +dnsmasq_dir="${pending_conf}/etc/dnsmasq.d" +mkdir -p "$dnsmasq_dir" - ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf" +cp -a "/etc/.pihole/advanced/01-pihole.conf" "$dnsmasq_dir/" - enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp) - if [ $enable_dhcp -eq 1 ] - then +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" - # 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) +ynh_replace_string --match_string="@INT@" --replace_string="$main_iface" --target_file="$dnsmasq_dir/01-pihole.conf" +# FIXME : query_logging ain't defined +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 - 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 )) +# Fix a too recent option for our dnsmasq version. +ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf" - # 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;}') +# +# Tweak dnsmsasq's general conf cache-size +# - # Copy the config file - cp -a "/etc/yunohost/apps/$app/conf/02-pihole-dhcp.conf" "$dnsmasq_dir/" +ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf" - # 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" +# +# Regen /etc/dnsmasq.d/02-pihole-dhcp.conf +# - # Set a static ip for the server. - echo "dhcp-host=$hw_adress,$localipv4" > "${pending_conf}/etc/dnsmasq.d/04-pihole-static-dhcp.conf" - fi +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 -} + a_range=$(( $b_range - $dhcp_range )) -do_post_regen() { - # Reload dnsmasq - systemctl reload dnsmasq -} + # 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;}') -case "$1" in - pre) - do_pre_regen - ;; - post) - do_post_regen - ;; - *) - echo "Hook called with unknown argument \`$1'" >&2 - exit 1 - ;; -esac + # 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 From a09381efeb41181cede5fba26a134162c808ec1b Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 14:48:52 +0200 Subject: [PATCH 4/9] fix query_logging in the regenconf --- conf/dnsmasq_regenconf_hook | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/conf/dnsmasq_regenconf_hook b/conf/dnsmasq_regenconf_hook index 7394955..be9d1fa 100755 --- a/conf/dnsmasq_regenconf_hook +++ b/conf/dnsmasq_regenconf_hook @@ -21,15 +21,13 @@ 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" -# FIXME : query_logging ain't defined +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 - # Fix a too recent option for our dnsmasq version. ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf" From ff32be711da2b54e643cbadd18d0ad86dec81161 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 15:07:29 +0200 Subject: [PATCH 5/9] manage all dnsmasq conf by the regenconf --- scripts/backup | 7 ----- scripts/install | 76 +++++++------------------------------------------ scripts/remove | 17 ++++++----- scripts/restore | 10 +------ scripts/upgrade | 16 ++++++----- 5 files changed, 28 insertions(+), 98 deletions(-) diff --git a/scripts/backup b/scripts/backup index 2202c71..0646942 100644 --- a/scripts/backup +++ b/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="/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" diff --git a/scripts/install b/scripts/install index 0450562..3ea3036 100644 --- a/scripts/install +++ b/scripts/install @@ -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 #================================================= diff --git a/scripts/remove b/scripts/remove index 99a9f82..4888cfa 100755 --- a/scripts/remove +++ b/scripts/remove @@ -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 #================================================= diff --git a/scripts/restore b/scripts/restore index 628b1c8..aba0d0a 100644 --- a/scripts/restore +++ b/scripts/restore @@ -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 diff --git a/scripts/upgrade b/scripts/upgrade index 2806466..427fdbe 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -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 #================================================= From faf899152249181722f262cbc9313c5877d8456a Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 15:25:03 +0200 Subject: [PATCH 6/9] remove action for dnsmasq --- actions.toml | 10 ---------- scripts/actions/reset_default_config | 23 ----------------------- 2 files changed, 33 deletions(-) diff --git a/actions.toml b/actions.toml index fc7f8aa..71fd449 100644 --- a/actions.toml +++ b/actions.toml @@ -16,16 +16,6 @@ command = "/bin/bash scripts/actions/reset_default_config \"pihole-FTL.conf\"" accepted_return_codes = [0] 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] name = "Reset the nginx config for this app." command = "/bin/bash scripts/actions/reset_default_system nginx" diff --git a/scripts/actions/reset_default_config b/scripts/actions/reset_default_config index fcec8b7..c3b6fe4 100755 --- a/scripts/actions/reset_default_config +++ b/scripts/actions/reset_default_config @@ -34,8 +34,6 @@ if [ "$file" = "setupVars.conf" ]; then config_file="/etc/pihole/setupVars.conf" elif [ "$file" = "pihole-FTL.conf" ]; then config_file="/etc/pihole/pihole-FTL.conf" -elif [ "$file" = "01-pihole.conf" ]; then - config_file="/etc/dnsmasq.d/01-pihole.conf" fi #================================================= @@ -77,27 +75,6 @@ then # Restart 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 # Calculate and store the config file checksum into the app settings From 452c6b664d5c15f581dfa14f1a7e23d18ed417b6 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 15:25:17 +0200 Subject: [PATCH 7/9] remove a tmp fix for old dnsmasq versions --- conf/dnsmasq_regenconf_hook | 2 -- 1 file changed, 2 deletions(-) diff --git a/conf/dnsmasq_regenconf_hook b/conf/dnsmasq_regenconf_hook index be9d1fa..bc8fd2a 100755 --- a/conf/dnsmasq_regenconf_hook +++ b/conf/dnsmasq_regenconf_hook @@ -28,8 +28,6 @@ if [ "$query_logging" = "true" ]; then else ynh_replace_string --match_string="^log-queries" --replace_string="#log-queries" --target_file="$dnsmasq_dir/01-pihole.conf" fi -# Fix a too recent option for our dnsmasq version. -ynh_replace_string --match_string="log-queries=extra" --replace_string="log-queries" --target_file="$dnsmasq_dir/01-pihole.conf" # # Tweak dnsmsasq's general conf cache-size From e67f5f39c0445ab3ada9158be3d556f593f1408c Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 16:51:59 +0200 Subject: [PATCH 8/9] fix remove --- scripts/install | 3 ++- scripts/remove | 13 +++---------- scripts/restore | 3 ++- scripts/upgrade | 3 ++- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/scripts/install b/scripts/install index 3ea3036..0608cd4 100644 --- a/scripts/install +++ b/scripts/install @@ -369,7 +369,8 @@ 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 +systemctl daemon-reload +ynh_exec_warn_less yunohost tools regen-conf dnsmasq #================================================= # START PIHOLE-FTL diff --git a/scripts/remove b/scripts/remove index 4888cfa..dc8cffa 100755 --- a/scripts/remove +++ b/scripts/remove @@ -151,11 +151,8 @@ 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/03-pihole-wildcard.conf" -ynh_replace_string --match_string="#pihole# " --replace_string="" --target_file=/etc/dnsmasq.conf - #================================================= # CLEAN /etc/hosts #================================================= @@ -171,21 +168,17 @@ sed -i "/#Added by pihole#/d" /etc/hosts # REMOVE CONF_REGEN HOOK #================================================= +ynh_systemd_action --action=stop --service_name=dnsmasq + ynh_secure_remove --file=/usr/share/yunohost/hooks/conf_regen/50-dnsmasq_$app -yunohost tools regen-conf dnsmasq +ynh_exec_warn_less yunohost tools regen-conf dnsmasq #================================================= # RESTART DNSMASQ #================================================= 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 #================================================= diff --git a/scripts/restore b/scripts/restore index aba0d0a..68981e9 100644 --- a/scripts/restore +++ b/scripts/restore @@ -196,7 +196,8 @@ ynh_script_progression --message="Restoring Dnsmasq config..." 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" -yunohost tools regen-conf dnsmasq +systemctl daemon-reload +ynh_exec_warn_less yunohost tools regen-conf dnsmasq #================================================= # CONFIGURE DNS FOR THE LOCAL DOMAINS diff --git a/scripts/upgrade b/scripts/upgrade index 427fdbe..17e741e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -368,7 +368,8 @@ 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 +systemctl daemon-reload +ynh_exec_warn_less yunohost tools regen-conf dnsmasq #================================================= # START PIHOLE-FTL From 15726c5bc661c17600c59f2a4aed1015d22afda7 Mon Sep 17 00:00:00 2001 From: Kay0u Date: Tue, 14 Sep 2021 19:39:14 +0200 Subject: [PATCH 9/9] fix 3.x --- scripts/actions/reset_default_app | 1 + scripts/install | 2 ++ scripts/remove | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/scripts/actions/reset_default_app b/scripts/actions/reset_default_app index 301406d..adbebb1 100755 --- a/scripts/actions/reset_default_app +++ b/scripts/actions/reset_default_app @@ -31,6 +31,7 @@ app=$YNH_APP_INSTANCE_NAME path_url=$(ynh_app_setting_get --app=$app --key=path) 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)" #================================================= diff --git a/scripts/install b/scripts/install index 0608cd4..e1197f0 100644 --- a/scripts/install +++ b/scripts/install @@ -347,6 +347,8 @@ then ynh_script_progression --message="Restarting Dnsmasq..." --weight=2 ynh_systemd_action --action=restart --service_name=dnsmasq + + ynh_systemd_action --action=restart --service_name=pihole-FTL fi #================================================= diff --git a/scripts/remove b/scripts/remove index dc8cffa..0870673 100755 --- a/scripts/remove +++ b/scripts/remove @@ -188,6 +188,11 @@ ynh_systemd_action --action=restart --service_name=dnsmasq #================================================= 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 #=================================================