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