#!/bin/sh
QUEUE=/var/lib/register-module
MODFILE=/target/etc/modules
MODUTILSDIR=/target/etc/modprobe.d/

create () {
	if [ ! -e $1 ]; then
		echo "# Local module settings" > $1
		echo "# Created by the Debian installer" >> $1
		echo "" >> $1
	fi
}

for QUEUEFILE in $QUEUE/*.load; do
	[ ! -e $QUEUEFILE ] && break
	MODULE=$(basename $QUEUEFILE ".load")

	create $MODFILE
	echo "$MODULE" >> $MODFILE
	rm $QUEUEFILE
done

OLDIFS=$IFS
for QUEUEFILE in $QUEUE/*.params; do
	[ ! -e $QUEUEFILE ] && break
	MODULE=$(basename $QUEUEFILE ".params")
	
	IFS=":"
	while read TYPE PARAMS; do
		case $TYPE in
		    options)
			FILE=$MODUTILSDIR/local.conf
			create $FILE
			echo "options $MODULE $PARAMS" >> $FILE
			;;
		esac
	done < $QUEUEFILE
	IFS=$OLDIFS
	rm $QUEUEFILE
done

FILE=$MODUTILSDIR/blacklist.local.conf
for QUEUEFILE in $QUEUE/*.blacklist; do
	[ ! -e $QUEUEFILE ] && break
	MODULE=$(basename $QUEUEFILE ".blacklist")

	create $FILE
	echo "blacklist $MODULE" >> $FILE
	rm $QUEUEFILE
done
