#!/bin/sh

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


[ -z "$RG" ] && RG="kdb"
[ -z "$ROOT" ] && ROOT="system"

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

cat /etc/inittab | sed -e "s/\#.*\$//g; s/\"/\'/g;" | grep -v '^$' |
		awk -F : '{
			if (seq) seq=seq","$1;
			else seq=$1;
			
			printf "   <key basename=\"%s/runlevels\" value=\"%s\"><comment>Active runlevels</comment></key>\n", $1,$2;
			
			printf "   <key basename=\"%s/action\" value=\"%s\"><comment>Approach</comment></key>\n", $1, $3;
			
			printf "   <key basename=\"%s/process\" value=\"%s\"><comment>Program to execute</comment></key>\n", $1, $4;

			printf "\n";
		} END {
			printf "   <key basename=\"sequence\" value=\"%s\"><comment>Sequence the entries will run</comment></key>\n", seq;
		}'

echo
echo "</keyset>"
