#!/bb/ash
# getDeps is based on concepts from tce-tree.sh - Copyright 2010 Brian Smith
# Licensed under GPLv2 License
# getDeps morphed from tree.sh by Robert Shingledecker - Nov 2012
. /etc/init.d/tc-functions



TCEDIR="/etc/sysconfig/tcedir"
#BUILD=`getBuild`


getDeps()
{
        PKG=${1}
	[ -e /tmp/work/"$PKG" ] && return
	if grep -wq "^$PKG$" /tmp/PKGEXCLUDELIST > /dev/null 2>&1; then
		echo "$PKG" >> /tmp/.blocked
		return
	fi
	
	echo "$PKG"
	touch /tmp/work/"$PKG"
	if grep "^Package: $PKG$" "$TCEDIR"/debinx.* > /dev/null 2>&1 ; then
		DEPLIST=`debGetPkgList $PKG 2>/dev/null`
		[ -s /tmp/PKGEXTRAREPODEP ] &&  DEPLIST="$DEPLIST `grep "^$PKG:" /tmp/PKGEXTRAREPODEP | cut -f2 -d:`"
	elif grep "^$PKG:" /tmp/PKGPREBUILTDEP > /dev/null 2>&1; then
		DEPLIST="$DEPLIST `grep "^$PKG:" /tmp/PKGPREBUILTDEP | cut -f2 -d:`"
	else
		DEPLIST=`debGetPkgList $PKG 2>/dev/null`
		[ -s /tmp/PKGADDDEP ] &&  DEPLIST="$DEPLIST `grep "^$PKG:" /tmp/PKGADDDEP | cut -f2 -d:`"
	fi
	for D in $DEPLIST; do getDeps $D; done
}

TARGET="$1"
if [ -n "$TARGET" ]; then
	[ -d /tmp/work ] || mkdir /tmp/work
        getDeps "$TARGET"
        echo
else
        echo ""
        echo "Specify package in command line:"
        echo ""
fi
