1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/pihole_ynh.git synced 2024-09-03 20:05:58 +02:00

Trying to fix regenconf

This commit is contained in:
Kay0u 2021-09-14 14:01:46 +02:00
parent c6c05e10de
commit 82ae8d433a
No known key found for this signature in database
GPG key ID: AAFEEB16CFA2AE2D
6 changed files with 57 additions and 25 deletions

View file

@ -1,38 +1,64 @@
#!/bin/bash #!/bin/bash
source /usr/share/yunohost/helpers
force=${2:-0} # 0/1 --force argument force=${2:-0} # 0/1 --force argument
dryrun=${3:-0} # 0/1 --dry-run argument dryrun=${3:-0} # 0/1 --dry-run argument
pending_conf=$4 # Path of the pending conf file pending_conf=$4 # Path of the pending conf file
app="__APP__"
temp_dir=/tmp/pi-hole.bck
do_pre_regen() { do_pre_regen() {
if [ $dryrun -eq 0 ] if [ $dryrun -eq 0 ]
then 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 # 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" "$dnsmasq_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 ynh_replace_string --match_string="^cache-size=" --replace_string="#pihole# cache-size=" --target_file="${pending_conf}/etc/dnsmasq.conf"
sed --in-place "s/^#pihole# cache-size=/cache-size=/g" /etc/dnsmasq.conf
# Et commente celui de pi-hole enable_dhcp=$(ynh_app_setting_get --app=$app --key=enable_dhcp)
sed --in-place "s/^cache-size=/#cache-size=/g" /etc/dnsmasq.d/01-pihole.conf 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 fi
} }
do_post_regen() { 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 # Reload dnsmasq
systemctl reload dnsmasq systemctl reload dnsmasq
} }

View file

@ -228,7 +228,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

View file

@ -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
@ -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 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 # GENERIC FINALISATION

View file

@ -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

View file

@ -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

View file

@ -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
@ -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 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 # RELOAD NGINX