#! /bin/bash

if [ -z "$1" ]; then
	echo "Usage: $0 class [directory]"
	exit 1
fi
class=$1
if [ -n "$2" ]; then
	dir=$2
else
	dir=.
fi

for x in `egrep -l "([[:space:]'\"]|^)$class([[:space:]'\"]|\$)" $dir/class/*`; do
	[ -x "$x" ] && echo "Defined in: $x"
done
for x in `ls $dir/basefiles/$class.t* 2>/dev/null`; do
	echo "Found basefile: $x"
done
[ -d $dir/scripts/$class ] && echo "Found script directory: $dir/scripts/$class"
for x in `ls $dir/hooks/*.$class 2>/dev/null`; do
	echo "Found hook: $x"
done
[ -f $dir/package_config/$class ] && echo "Found package configuration: $dir/package_config/$class"
for x in `egrep -l "PACKAGES.+$class" $dir/package_config/*`; do
	echo "Found additional package configuration: $x"
done
[ -f $dir/debconf/$class ] && echo "Found debconf configuration: $dir/debconf/$class"
[ -f $dir/disk_config/$class ] && echo "Found disk configuration: $dir/disk_config/$class"
for x in `find $dir/files -name $class -o -name \'$class.t*\'`; do
	echo "Found file: $x"
done
for x in `egrep -l "ifclass.+$class" $dir/scripts/*/* $dir/hooks/* $(find $dir/files -name postinst)`; do
	echo "Used conditionally in: $x"
done


