Common utilities
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
1.4 KiB

  1. #!/bin/bash
  2. #
  3. # Put this script in the same directory as your djbdns data file, usually /etc/tinydns/root
  4. #
  5. # Break up your monolithic data file into one-file per domain, and put them in the "domains" subdirectory.
  6. #
  7. # When this script runs, it concatenates all files in the "domains" subdirectory into a monolithic data
  8. # file and tried to build it via make. If that fails, the old file is kept.
  9. #
  10. # Note that you may still want to restart the tinydns service (svc -h /path/to/tinydns)
  11. #
  12. function die () {
  13. echo "${1}"
  14. exit 1
  15. }
  16. BASE=$(cd $(dirname $0) && pwd)
  17. if [ ! -f data ] ; then
  18. echo "No data file found!"
  19. exit 1
  20. fi
  21. if [ ! -d ${BASE}/domains ] ; then
  22. echo "No domains dir found!"
  23. exit 1
  24. fi
  25. mkdir -p ${BASE}/backups || die "Error creating backups dir"
  26. TODAY=$(date +%Y-%m-%d)
  27. BACKUP=$(mktemp ${BASE}/backups/data.backup.${TODAY}.XXXXXXX)
  28. cp data ${BACKUP} || die "Error backing up data file"
  29. CHANGED=$(mktemp data.tried.${TODAY}.XXXXXX)
  30. for domain in $(find ${BASE}/domains -type f) ; do
  31. echo "" >> ${CHANGED}
  32. echo "####################" >> ${CHANGED}
  33. echo "# $(basename ${domain})" >> ${CHANGED}
  34. echo "####################" >> ${CHANGED}
  35. cat ${domain} >> ${CHANGED}
  36. echo "" >> ${CHANGED}
  37. done
  38. mv ${CHANGED} data
  39. make
  40. if [ $? -ne 0 ] ; then
  41. echo "Error rebuilding data file, rolling back. Failed data file is in ${CHANGED}"
  42. mv data ${CHANGED}
  43. mv ${BACKUP} data
  44. fi