jvdias 66f2cc4
#!/bin/bash
jvdias 66f2cc4
#
jvdias 66f2cc4
#  This script uses the named D-BUS support, which must be enabled in
jvdias 66f2cc4
#  the running named with the named '-D' option, to set the forwarding zones
jvdias 66f2cc4
#  in the running server.
jvdias 66f2cc4
#  
jvdias 66f2cc4
#  One zone argument is required, followed by any number of server IP (v4 or v6)
jvdias 66f2cc4
#  addresses. If the server IP address list is empty, any forwarders for the zone
jvdias 66f2cc4
#  will be removed.
jvdias 66f2cc4
#
jvdias 66f2cc4
#  Usage:
jvdias 66f2cc4
#        SetForwarders [ -t <'first' | 'only'> ] <zone> [ <server IP> [...<server IP>] ] 
jvdias 66f2cc4
#
jvdias 66f2cc4
#  Copyright(C) Jason Vas Dias<jvdias@redhat.com> Red Hat Inc. 2005
jvdias 66f2cc4
#
jvdias 66f2cc4
#  This program is free software; you can redistribute it and/or modify
jvdias 66f2cc4
#  it under the terms of the GNU General Public License as published by
jvdias 66f2cc4
#  the Free Software Foundation at 
jvdias 66f2cc4
#           http://www.fsf.org/licensing/licenses/gpl.txt
jvdias 66f2cc4
#  and included in this software distribution as the "LICENSE" file.
jvdias 66f2cc4
#
jvdias 66f2cc4
#  This program is distributed in the hope that it will be useful,
jvdias 66f2cc4
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
jvdias 66f2cc4
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jvdias 66f2cc4
#  GNU General Public License for more details.
jvdias 66f2cc4
#
jvdias 66f2cc4
usage() { echo "Usage: SetForwarders [ -t <'first' | 'only'> ] <zone> [ <server> [...<server>] ]"; }
jvdias 66f2cc4
type=''
jvdias 66f2cc4
if [ $# -eq 0 ]; then
jvdias 66f2cc4
   usage;
jvdias 66f2cc4
   exit 1;
jvdias 66f2cc4
elif [ "$1" = "-t" ]; then
jvdias 66f2cc4
   if [ $# -lt 2 ]; then
jvdias 66f2cc4
      echo '-t option requires an argument.'
jvdias 66f2cc4
      exit 1;
jvdias 66f2cc4
   fi;
jvdias 66f2cc4
   type=$2;
jvdias 66f2cc4
   shift 2;
jvdias 66f2cc4
fi;
jvdias 66f2cc4
if [ $# -lt 1 ]; then
jvdias 66f2cc4
   echo '<zone> first argument required.'
jvdias 66f2cc4
   exit 1;
jvdias 66f2cc4
fi; 
jvdias 66f2cc4
zone='string:'"$1";
jvdias 66f2cc4
shift;
jvdias 66f2cc4
servers='';
jvdias 66f2cc4
if [ $# -gt 0 ]; then
jvdias 66f2cc4
  for svr in $*; do
jvdias 66f2cc4
    servers="$servers string:$svr";
jvdias 66f2cc4
  done
jvdias 66f2cc4
fi;
jvdias 66f2cc4
dbus-send --system --type=method_call --print-reply --reply-timeout=20000 --dest=com.redhat.named /com/redhat/named com.redhat.named.text.SetForwarders $zone $type $servers;