#!/bin/sh
### This script generates a new disklist for Amanda on the fly using the
### automounter maps.  The resultant DLEs have a dumptype which matches
### their config in name.  There is no way to distribute dumptype
### information with automount maps.  If you require more than one 
### dumptype within a given Amanda config you will have to modify this
### script or maintain your disklist manually.  Your amanda.conf should
### have skeleton dumptypes for each config name which include the
### appropriate dumptype for that config.

### This script requires that awk, ypcat, mv, and rm are in the
### Amanda user's path.  The awk is minimal and should work in any awk
### derivative.

### Run this script from cron each night shortly before you run amdump.

### Copyright 2003, Brandon D. Valentine <brandon@dvalentine.com>
### This file released under the terms of the BSD license as available
### here: http://www.opensource.org/licenses/bsd-license.php.
### Contact the author for any licensing questions.

# Configuration

# configs should contain the list of Amanda configs in use at your site.
configs="Daily Monthly"

# maps should contain the list of automounter maps for Amanda to backup
maps="auto.home auto.backup"

# amdir should contain the path to Amanda's configuration directory
amdir="/usr/local/etc/amanda"

# diskfile should be the name of the disklist file your Amanda config
# uses.  For most people the default of disklist is fine.
diskfile="disklist"

for DIR in $configs
do
	# set the disklist location for this config
	disklist="$amdir/$DIR/$diskfile"

	# hope you didn't want to keep that
	if ( test -w $disklist.new ) then
		rm $disklist.new
	fi
	
	# add each map to the new disklist
	for MAP in $maps
	do
		# check to make sure yp is up
		if ( ypcat $MAP > /dev/null ) then 
			ypcat $MAP | \
			awk -F: "{ printf(\"%s %s $DIR\n\",\$1,\$2) }" \
			>> $disklist.new
		fi
	done

	# make a backup of the old disklist and move the new one into place
	mv -f $disklist $disklist.bak
	mv -f $disklist.new $disklist

done
