#!/bin/sh

########################################################################
##
## This script will read /etc/hosts and create an
## equivalent registry tree under $ROOT.
##
## The correct way to run it is:
##
## # kdb hosts-convert | sh -e
##
##
## To make tests you can do:
##
## $ ROOT=user/test kdb hosts-convert | sh -e
##
## Vladimir Shabanov <virl@mail.ru>
## June 2004
##
## $Id$
##
########################################################################


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


cat /etc/hosts | sed /"#"/d | while read -a hosts; do

	echo $RG set -c \"Hostname\" $ROOT/${hosts[0]}/hostname \'${hosts[1]}\'
	
	total_words=`echo ${hosts[*]} | wc -w`
	for (( i=2; $((i < $total_words)); i++ )); do
	num=$((i-2))
	echo $RG set -c \"Hostname alias\" $ROOT/${hosts[0]}/host_alias$num \'${hosts[$i]}\'
	done
	
done
