#!/bin/sh

[ "$#" -gt 0 ] && OUT="$1" || OUT="rc-depend.dot"

SERVICE_ROOT="/etc"

need() {
	NEEDS="${NEEDS} $@"
}

use() {
#	echo ${SVCNAME} uses $@
	true
}

after() {
#	echo ${SVCNAME} is after $@
	true
}

before() {
#	echo ${SVCNAME} is before $@
	true
}

provide() {
#	echo ${SVCNAME} provides $@
	true
}

keyword() {
	true
}

config() {
	true
}

echo "digraph need {" > ${OUT}

#for SVCNAME in `ls ${SERVICE_ROOT}/init.d`; do

for SVCNAME in `rc-status | grep -v Runlevel | awk '{print $1;}'`; do
	(
		NEEDS=""
		[ -r ${SERVICE_ROOT}/conf.d/${SVCNAME} ] && . ${SERVICE_ROOT}/conf.d/${SVCNAME}
		. ${SERVICE_ROOT}/init.d/${SVCNAME}
		depend
		for _dep in ${NEEDS}; do
			echo "    \"${SVCNAME}\" -> \"${_dep}\";" >> ${OUT}
		done
	)
done

echo "}" >> ${OUT}
