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.

126 lines
3.5 KiB

  1. #!/bin/sh
  2. ##############################################################################
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License version 2 as
  6. # published by the Free Software Foundation.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # Copyright (C) 2016 Eric Luehrsen
  14. #
  15. ##############################################################################
  16. #
  17. # TODO: This file will build the UCI for Unbound. This iteration only puts
  18. # our default unbound configuration and root.key into /var/lib/unbound.
  19. #
  20. ##############################################################################
  21. # TODO: Just default definitions versus real UCI coming soon.
  22. UNBOUND_B_MAN_CONF=1
  23. UNBOUND_B_DNSSEC=1
  24. UNBOUND_N_ROOT_AGE=7
  25. ##############################################################################
  26. UNBOUND_ANCHOR=/usr/bin/unbound-anchor
  27. UNBOUND_CONTROL=/usr/bin/unbound-control
  28. UNBOUND_LIBDIR=/usr/lib/unbound
  29. UNBOUND_PIDFILE=/var/run/unbound.pid
  30. UNBOUND_VARDIR=/var/lib/unbound
  31. UNBOUND_CONFFILE=$UNBOUND_VARDIR/unbound.conf
  32. UNBOUND_KEYFILE=$UNBOUND_VARDIR/root.key
  33. UNBOUND_HINTFILE=$UNBOUND_VARDIR/root.hints
  34. UNBOUND_CHECKFILE=$UNBOUND_VARDIR/unbound.check
  35. ##############################################################################
  36. . /lib/functions.sh
  37. . /lib/functions/network.sh
  38. . $UNBOUND_LIBDIR/rootzone.sh
  39. ##############################################################################
  40. unbound_mkdir() {
  41. mkdir -p $UNBOUND_VARDIR
  42. if [ -f /etc/unbound/root.hints ] ; then
  43. # Your own local copy of root.hints
  44. cp -p /etc/unbound/root.hints $UNBOUND_HINTFILE
  45. elif [ -f /usr/share/dns/root.hints ] ; then
  46. # Debian-like package dns-root-data
  47. cp -p /usr/share/dns/root.hints $UNBOUND_HINTFILE
  48. else
  49. logger -t unbound -s "iterator will use built-in root hints"
  50. fi
  51. if [ -f /etc/unbound/root.key ] ; then
  52. # Your own local copy of a root.key
  53. cp -p /etc/unbound/root.key $UNBOUND_KEYFILE
  54. elif [ -f /usr/share/dns/root.key ] ; then
  55. # Debian-like package dns-root-data
  56. cp -p /usr/share/dns/root.key $UNBOUND_KEYFILE
  57. elif [ -x "$UNBOUND_ANCHOR" ] ; then
  58. $UNBOUND_ANCHOR -a $UNBOUND_KEYFILE
  59. else
  60. logger -t unbound -s "validator will use built-in trust anchor"
  61. fi
  62. }
  63. ##############################################################################
  64. unbound_conf() {
  65. # TODO: Just structure to real UCI coming soon.
  66. if [ "$UNBOUND_B_MAN_CONF" -gt 0 -a -f /etc/unbound/unbound.conf ] ; then
  67. # You don't want UCI and use your own manual configuration
  68. cp -p /etc/unbound/unbound.conf $UNBOUND_CONFFILE
  69. fi
  70. }
  71. ##############################################################################
  72. unbound_own() {
  73. # Debug UCI
  74. {
  75. echo "# $UNBOUND_CHECKFILE generated by UCI $( date )"
  76. echo
  77. set | grep ^UNBOUND_
  78. } > $UNBOUND_CHECKFILE
  79. if [ ! -f "$UNBOUND_CONFFILE" ] ; then
  80. # if somehow this happened
  81. touch $UNBOUND_CONFFILE
  82. fi
  83. # Ensure Access
  84. chown -R unbound:unbound $UNBOUND_VARDIR
  85. chmod 775 $UNBOUND_VARDIR
  86. chmod 664 $UNBOUND_VARDIR/*
  87. }
  88. ##############################################################################
  89. unbound_prepare() {
  90. unbound_mkdir
  91. unbound_conf
  92. unbound_own
  93. }
  94. ##############################################################################