unbound.in revision 225524
1219732Sume#!/bin/sh 2219732Sume# Copyright (c) 2009 Roy Marples 3219732Sume# All rights reserved 4219732Sume 5219732Sume# unbound subscriber for resolvconf 6219732Sume 7219732Sume# Redistribution and use in source and binary forms, with or without 8219732Sume# modification, are permitted provided that the following conditions 9219732Sume# are met: 10219732Sume# * Redistributions of source code must retain the above copyright 11219732Sume# notice, this list of conditions and the following disclaimer. 12219732Sume# * Redistributions in binary form must reproduce the above 13219732Sume# copyright notice, this list of conditions and the following 14219732Sume# disclaimer in the documentation and/or other materials provided 15219732Sume# with the distribution. 16219732Sume# 17219732Sume# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18219732Sume# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19219732Sume# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20219732Sume# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21219732Sume# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22219732Sume# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23219732Sume# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219732Sume# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219732Sume# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219732Sume# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27219732Sume# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28219732Sume 29219732Sume[ -f "@SYSCONFDIR@"/resolvconf.conf ] || exit 0 30219732Sume. "@SYSCONFDIR@/resolvconf.conf" || exit 1 31219732Sume[ -z "$unbound_conf" ] && exit 0 32219732Sume[ -z "$RESOLVCONF" ] && eval "$(@PREFIX@/sbin/resolvconf -v)" 33225524ShrsNL=" 34225524Shrs" 35219732Sume 36219732Sume: ${unbound_pid:=/var/run/unbound.pid} 37219732Sume: ${unbound_service:=unbound} 38219732Sume: ${unbound_restart:=@RESTARTCMD ${unbound_service}@} 39225524Shrsnewconf="# Generated by resolvconf$NL" 40219732Sume 41219732Sumefor d in $DOMAINS; do 42219732Sume dn="${d%%:*}" 43219732Sume ns="${d#*:}" 44225524Shrs newconf="$newconf${NL}forward-zone:$NL name: \"$dn\"$NL" 45219732Sume while [ -n "$ns" ]; do 46225524Shrs newconf="$newconf forward-addr: ${ns%%,*}$NL" 47219732Sume [ "$ns" = "${ns#*,}" ] && break 48219732Sume ns="${ns#*,}" 49219732Sume done 50219732Sumedone 51219732Sume 52219732Sumeif [ -n "$NAMESERVERS" ]; then 53225524Shrs newconf="$newconf${NL}forward-zone:$NL name: \".\"$NL" 54219732Sume for n in $NAMESERVERS; do 55225524Shrs newconf="$newconf forward-addr: $n$NL" 56219732Sume done 57219732Sumefi 58219732Sume 59219732Sumeif [ ! -f "$unbound_conf" ] || \ 60225524Shrs [ "$(cat "$unbound_conf")" != "$(printf %s "$newconf")" ] 61219732Sumethen 62225524Shrs printf %s "$newconf" >"$unbound_conf" 63219732Sume # If we can't sent a HUP then force a restart 64219732Sume if [ -s "$unbound_pid" ]; then 65219732Sume if ! kill -HUP $(cat "$unbound_pid") 2>/dev/null; then 66219732Sume eval $unbound_restart 67219732Sume fi 68219732Sume else 69219732Sume eval $unbound_restart 70219732Sume fi 71219732Sumefi 72