#!/bin/sh
#
#installdb: version 1.0
#
#a script to install a tgz and retrive its dependency list.
#
#usage:
#
#./installdb packagename
#


#--------------------------------------------------------------
#aux. functions - useful stuff for the tracing of dependencies


. $INSTDIR/core-functions
#--------------------------------------------------------------


#--------------------------------------------------------------
#main body


echo ""

#we install all packages (so that possible dependencies will be installed
#_BEFORE_ we launch the builddb script)
#j=0;
k=0;
for i in $@; do
	BASE=`basename $i .tgz`
	#check if the package is already installed preventing its reinstall...
	#this is not done automatically by installpkg, so why not add this function to the script?
	if [ -f  $PKGDIR/$BASE ]; then
	#if the file is found we jump to the next given package
		echo "  --> $BASE is already installed: if you want to reinstall it use the '--reinstall' option"
	else
		installpkg $i && {
			noarchTest $PKGDIR/$BASE;
			[ $? -eq 0 ] && {
				PASSARG[$k]=$PKGDIR/$BASE;
				(( k++ ));
			}
		}
	fi
done

#we build dependency list for new packages
for (( j=0; j<$k; j++ )); do
	$INSTDIR/builddb ${PASSARG[$j]}
done

#run dependency check and update old informations adding new installed files
[ ! $k -eq 0 ] && {
	echo -e "\nupdating data"
	updateData ${PASSARG[@]};
}
echo "...done"
#--------------------------------------------------------------

#EOF
