dnsmasq_regenconf_hook 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. fi
  15. }
  16. do_post_regen() {
  17. # Restaure la config dnsmasq de pi-hole
  18. cp -a "$temp_dir/01-pihole.conf" "/etc/dnsmasq.d/"
  19. test -e "$temp_dir/02-pihole-dhcp.conf" && cp -a "$temp_dir/02-pihole-dhcp.conf" "/etc/dnsmasq.d/"
  20. test -e "$temp_dir/03-pihole-wildcard.conf" && cp -a "$temp_dir/03-pihole-wildcard.conf" "/etc/dnsmasq.d/"
  21. # Supprime le dossier temporaire
  22. test -n $temp_dir && rm -r $temp_dir
  23. # Commente le cache-size de la config par défaut
  24. sed --in-place "s/^cache-size=/#pihole# cache-size=/g" /etc/dnsmasq.conf
  25. # Reload dnsmasq
  26. systemctl reload dnsmasq
  27. }
  28. case "$1" in
  29. pre)
  30. do_pre_regen
  31. ;;
  32. post)
  33. do_post_regen
  34. ;;
  35. *)
  36. echo "Hook called with unknown argument \`$1'" >&2
  37. exit 1
  38. ;;
  39. esac
  40. exit 0