#!/bin/sh

########################################################################
##
## This script will read /etc/fstab and create an
## equivalent key tree under $ROOT.
##
## The correct way to run it is:
##
## # kdb convert-fstab | kdb import system/filesystems xmltool
##
##
## To make tests you can do:
##
## $ ROOT=user/test kdb convert-fstab
##
## Avi Alkalay <avi@unix.sh>
## April 2004
##
## $Id$
##
########################################################################


[ -z "$ROOT" ] && ROOT="system/filesystems"

num=0

echo "<keyset parent=\"$ROOT\">"

cat /etc/fstab | while read dev mpoint type options dumpfreq passno; do
	
	expr match "$dev" '#.*' > /dev/null && continue
	test $dev || continue

	case "$mpoint" in 
		"none")
			num=$(( $num + 1 ))
			fsname="$type$num"
			;;
		'/')
			fsname="roofs"
			;;
		*)
			fsname=`echo $mpoint | sed -e 's^/^^g'`
			;;
	esac

	
	echo "  <key basename=\"$fsname\">"
	echo "    <key basename=\"device\" value=\"$dev\"><comment>Device or Label</comment></key>"
	echo "    <key basename=\"mpoint\" value=\"$mpoint\"><comment>Mount Point</comment></key>"
	echo "    <key basename=\"type\" value=\"$type\"><comment>Filesystem type. See fs(5)</comment></key>"
	echo "    <key basename=\"options\" value=\"$options\"><comment>Filesystem specific options. See mount(8)</comment></key>"
	echo "    <key basename=\"dumpfreq\" value=\"$dumpfreq\"><comment>Dump frequency in days</comment></key>"
	echo "    <key basename=\"passno\" value=\"$passno\"><comment>Pass number on parallel fsck</comment></key>"
	echo "  </key>"
	echo
done

echo "</keyset>"
