1587392a5SHajimu UMEMOTO#!/bin/sh 23f2a60a1SPedro F. Giffuni# Copyright (c) 2009-2016 Roy Marples 3587392a5SHajimu UMEMOTO# All rights reserved 4587392a5SHajimu UMEMOTO 5587392a5SHajimu UMEMOTO# unbound subscriber for resolvconf 6587392a5SHajimu UMEMOTO 7587392a5SHajimu UMEMOTO# Redistribution and use in source and binary forms, with or without 8587392a5SHajimu UMEMOTO# modification, are permitted provided that the following conditions 9587392a5SHajimu UMEMOTO# are met: 10587392a5SHajimu UMEMOTO# * Redistributions of source code must retain the above copyright 11587392a5SHajimu UMEMOTO# notice, this list of conditions and the following disclaimer. 12587392a5SHajimu UMEMOTO# * Redistributions in binary form must reproduce the above 13587392a5SHajimu UMEMOTO# copyright notice, this list of conditions and the following 14587392a5SHajimu UMEMOTO# disclaimer in the documentation and/or other materials provided 15587392a5SHajimu UMEMOTO# with the distribution. 16587392a5SHajimu UMEMOTO# 17587392a5SHajimu UMEMOTO# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18587392a5SHajimu UMEMOTO# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19587392a5SHajimu UMEMOTO# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20587392a5SHajimu UMEMOTO# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21587392a5SHajimu UMEMOTO# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22587392a5SHajimu UMEMOTO# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23587392a5SHajimu UMEMOTO# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24587392a5SHajimu UMEMOTO# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25587392a5SHajimu UMEMOTO# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26587392a5SHajimu UMEMOTO# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27587392a5SHajimu UMEMOTO# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28587392a5SHajimu UMEMOTO 29d7149f4eSGlen Barberunbound_insecure= 30d7149f4eSGlen Barber 31587392a5SHajimu UMEMOTO[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0 32587392a5SHajimu UMEMOTO. "@SYSCONFDIR@/resolvconf.conf" || exit 1 33587392a5SHajimu UMEMOTO[ -z "$unbound_conf" ] && exit 0 34d7149f4eSGlen Barber[ -z "$RESOLVCONF" ] && eval "$(@SBINDIR@/resolvconf -v)" 35a02aba5fSHiroki SatoNL=" 36a02aba5fSHiroki Sato" 37587392a5SHajimu UMEMOTO 38587392a5SHajimu UMEMOTO: ${unbound_pid:=/var/run/unbound.pid} 39587392a5SHajimu UMEMOTO: ${unbound_service:=unbound} 40a02aba5fSHiroki Satonewconf="# Generated by resolvconf$NL" 41587392a5SHajimu UMEMOTO 42587392a5SHajimu UMEMOTOfor d in $DOMAINS; do 43587392a5SHajimu UMEMOTO dn="${d%%:*}" 44587392a5SHajimu UMEMOTO ns="${d#*:}" 45d7149f4eSGlen Barber case "$unbound_insecure" in 46d7149f4eSGlen Barber [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) 472d004dd5SPedro F. Giffuni newconf="$newconf${NL}server:$NL" 482d004dd5SPedro F. Giffuni newconf="$newconf domain-insecure: \"$dn\"$NL" 49d7149f4eSGlen Barber ;; 50d7149f4eSGlen Barber esac 51a02aba5fSHiroki Sato newconf="$newconf${NL}forward-zone:$NL name: \"$dn\"$NL" 52587392a5SHajimu UMEMOTO while [ -n "$ns" ]; do 53a02aba5fSHiroki Sato newconf="$newconf forward-addr: ${ns%%,*}$NL" 54587392a5SHajimu UMEMOTO [ "$ns" = "${ns#*,}" ] && break 55587392a5SHajimu UMEMOTO ns="${ns#*,}" 56587392a5SHajimu UMEMOTO done 57587392a5SHajimu UMEMOTOdone 58587392a5SHajimu UMEMOTO 59587392a5SHajimu UMEMOTOif [ -n "$NAMESERVERS" ]; then 60a02aba5fSHiroki Sato newconf="$newconf${NL}forward-zone:$NL name: \".\"$NL" 61587392a5SHajimu UMEMOTO for n in $NAMESERVERS; do 62a02aba5fSHiroki Sato newconf="$newconf forward-addr: $n$NL" 63587392a5SHajimu UMEMOTO done 64587392a5SHajimu UMEMOTOfi 65587392a5SHajimu UMEMOTO 66d7149f4eSGlen Barber# Try to ensure that config dirs exist 67d7149f4eSGlen Barberif type config_mkdirs >/dev/null 2>&1; then 68d7149f4eSGlen Barber config_mkdirs "$unbound_conf" 69d7149f4eSGlen Barberelse 70d7149f4eSGlen Barber @SBINDIR@/resolvconf -D "$unbound_conf" 71d7149f4eSGlen Barberfi 72d7149f4eSGlen Barber 733f2a60a1SPedro F. Giffunirestart_unbound() 743f2a60a1SPedro F. Giffuni{ 753f2a60a1SPedro F. Giffuni if [ -n "$unbound_restart" ]; then 763f2a60a1SPedro F. Giffuni eval $unbound_restart 773f2a60a1SPedro F. Giffuni elif [ -n "$RESTARTCMD" ]; then 783f2a60a1SPedro F. Giffuni set -- ${unbound_service} 79*9af6c78cSPedro F. Giffuni eval "$RESTARTCMD" 803f2a60a1SPedro F. Giffuni else 813f2a60a1SPedro F. Giffuni @SBINDIR@/resolvconf -r ${unbound_service} 823f2a60a1SPedro F. Giffuni fi 833f2a60a1SPedro F. Giffuni} 843f2a60a1SPedro F. Giffuni 85587392a5SHajimu UMEMOTOif [ ! -f "$unbound_conf" ] || \ 86a02aba5fSHiroki Sato [ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ] 87587392a5SHajimu UMEMOTOthen 88a02aba5fSHiroki Sato printf %s "$newconf" >"$unbound_conf" 89587392a5SHajimu UMEMOTO # If we can't sent a HUP then force a restart 90587392a5SHajimu UMEMOTO if [ -s "$unbound_pid" ]; then 91587392a5SHajimu UMEMOTO if ! kill -HUP $(cat "$unbound_pid") 2>/dev/null; then 923f2a60a1SPedro F. Giffuni restart_unbound 93587392a5SHajimu UMEMOTO fi 94587392a5SHajimu UMEMOTO else 953f2a60a1SPedro F. Giffuni restart_unbound 96587392a5SHajimu UMEMOTO fi 97587392a5SHajimu UMEMOTOfi 98