dnsmasq_regenconf_hook 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #!/bin/bash
  2. force=${2:-0} # 0/1 --force argument
  3. dryrun=${3:-0} # 0/1 --dry-run argument
  4. pending_conf=$4 # Path of the pending conf file
  5. temp_dir=/tmp/pi-hole.bck
  6. do_pre_regen() {
  7. if [ $dryrun -eq 0 ]
  8. then
  9. # Créer une sauvegarde des config dnsmasq de pi-hole. Que la regen-conf va sauvagement supprimer
  10. mkdir $temp_dir
  11. cp -a "/etc/dnsmasq.d/01-pihole.conf" "$temp_dir"
  12. test -e "/etc/dnsmasq.d/02-pihole-dhcp.conf" && cp -a "/etc/dnsmasq.d/02-pihole-dhcp.conf" "$temp_dir"
  13. test -e "/etc/dnsmasq.d/03-pihole-wildcard.conf" && cp -a "/etc/dnsmasq.d/03-pihole-wildcard.conf" "$temp_dir"
  14. # Décommente le cache-size de la config par défaut
  15. sed --in-place "s/^#pihole# cache-size=/cache-size=/g" /etc/dnsmasq.conf
  16. # Et commente celui de pi-hole
  17. sed --in-place "s/^cache-size=/#cache-size=/g" /etc/dnsmasq.d/01-pihole.conf
  18. fi
  19. }
  20. do_post_regen() {
  21. # Restaure la config dnsmasq de pi-hole
  22. cp -a "$temp_dir/01-pihole.conf" "/etc/dnsmasq.d/"
  23. test -e "$temp_dir/02-pihole-dhcp.conf" && cp -a "$temp_dir/02-pihole-dhcp.conf" "/etc/dnsmasq.d/"
  24. test -e "$temp_dir/03-pihole-wildcard.conf" && cp -a "$temp_dir/03-pihole-wildcard.conf" "/etc/dnsmasq.d/"
  25. # Supprime le dossier temporaire
  26. test -n $temp_dir && rm -r $temp_dir
  27. # Commente le cache-size de la config par défaut
  28. sed --in-place "s/^cache-size=/#pihole# cache-size=/g" /etc/dnsmasq.conf
  29. # Reload dnsmasq
  30. systemctl reload dnsmasq
  31. }
  32. case "$1" in
  33. pre)
  34. do_pre_regen
  35. ;;
  36. post)
  37. do_post_regen
  38. ;;
  39. *)
  40. echo "Hook called with unknown argument \`$1'" >&2
  41. exit 1
  42. ;;
  43. esac
  44. exit 0