update-dnsmasq 917 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. logger -t dhcpd "Refresh dnsmasq config request"
  3. force=$1
  4. /usr/local/scripts/print-dnsmasq.pl >/tmp/mac-all
  5. ret=$?
  6. if [ ${ret} -ne 0 ]; then
  7. logger -t dhcpd "Config generate error! Bye."
  8. exit
  9. fi
  10. touch /etc/dnsmasq.d/mac-all
  11. diff -aqbBfi /tmp/mac-all /etc/dnsmasq.d/mac-all >/dev/null
  12. ret=$?
  13. if [ ${ret} -ne 0 -o -n "${force}" ]; then
  14. logger -t dhcpd "Update dnsmasq config"
  15. cat /etc/dnsmasq.d/mac-all >/tmp/mac.old
  16. cat /tmp/mac-all >/etc/dnsmasq.d/mac-all
  17. /usr/sbin/dnsmasq --test >/dev/null 2>&1
  18. ret=$?
  19. if [ ${ret} -eq 0 ]; then
  20. systemctl stop dnsmasq>/dev/null
  21. >/var/lib/misc/dnsmasq.leases
  22. systemctl start dnsmasq>/dev/null
  23. else
  24. logger -t dhcpd "Config error! Rollback changes."
  25. cat /tmp/mac.old >/etc/dnsmasq.d/mac-all
  26. fi
  27. else
  28. logger -t dhcpd "Config not changed. Skip restart"
  29. fi
  30. logger -t dhcpd "done"
  31. exit