#!/bin/sh
#
# Toolkit for building distributed control systems or any other distributed system.
#
# Copyright (c) 1990-2005 ESRF, www.esrf.fr
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# File:		db_fillup2
#
# Description:  This script fills the TACO database with the content of the 
#		resource files found in the directory pointed by $RES_BASE_DIR 
#		and its subdirs
#
# 		It may substitute the current db_fillup program, which may only 
#		used with the GDBM.
#
# 		The database server has to been started.
#
# Author(s):	Jens Krueger
#		$Author: jkrueger1 $
#
# Date:		$Date: 2008/04/06 09:07:47 $
#
# Version:	$Revision: 1.4 $
#
# Copyright (c) 2004, FRM-II, TU Munich, Germany
#

if test -z "$RES_BASE_DIR" ; then
	echo "RES_BASE_DIR environment variable is not set"
	exit 1
fi
for i in `ls -R1p $RES_BASE_DIR | grep -v '/$' | grep -v '^$'`; do
	if echo $i | grep ':$' >/dev/null ; then
		dir=`echo ${i} | sed -e 's/:$//'`
		dir=`basename ${dir}`
		continue
	fi
	if { db_update $dir/$i ; } ; then
		echo Resources sucessfully imported from : $RES_BASE_DIR/$dir/$i 
	else
		echo ERROR during update the $RES_BASE_DIR/$dir/$i resource file.
	fi
	sleep 2
done
