update-dnsmasq 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. logger -t dhcpd "Refresh dnsmasq config request"
  3. force=$1
  4. /opt/Eye/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. [ ! -e "/etc/dnsmasq.d/" ] && mkdir -p "/etc/dnsmasq.d/"
  11. touch /etc/dnsmasq.d/mac-all
  12. CHANGES=$(diff -ubBi /tmp/mac-all /etc/dnsmasq.d/mac-all | egrep "^[+-]dhcp" | awk '{ print $1 }' | sed -E 's/(\+|\-)//;s/dhcp-host=//;s/\,//' | sort -u)
  13. if [ -n "${CHANGES}" -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. #clear leases
  21. systemctl stop dnsmasq >/dev/null
  22. echo "${CHANGES}" | while read LEASE; do
  23. logger -t dhcpd "Clear ${LEASE}"
  24. sed -i "/${LEASE}/d" /var/lib/misc/dnsmasq.leases
  25. done
  26. systemctl start dnsmasq >/dev/null
  27. else
  28. logger -t dhcpd "Config error! Rollback changes."
  29. cat /tmp/mac.old >/etc/dnsmasq.d/mac-all
  30. fi
  31. else
  32. logger -t dhcpd "Config not changed. Skip restart"
  33. fi
  34. logger -t dhcpd "done"
  35. exit