#!/bin/sh
# We need CDROM and FLOPPY

VERSION=##BOOTCD.VERSION##

mydiscover1()
{
	discover --format="%m\n" --disable-all \
		--enable=pci,ide,scsi,pcmcia scsi cdrom 
}

mydiscover2()
{
	dpath=linux/module/name
	dver=`uname -r|cut -d. -f1,2` # Kernel version (e.g. 2.4)
	dflags="-d all -e ata -e pci -e pcmcia -e scsi -e usb \
		bridge broadband fixeddisk humaninput modem \
		network optical removabledisk"
	discover --data-path=$dpath --data-version=$dver $dflags |
		grep -v "^$"
}

mydiscover()
{
	if [ "$(discover --version 2>/dev/null | grep "discover 2\..*")" ]
	then
		echo "bootcdmodprobe uses discover v2" >&2
		mydiscover2
	else
		echo "bootcdmodprobe uses discover v1" >&2
		mydiscover1
	fi
}

manual()
{
        MANUAL_MODULES="scsi_mod usb-storage floppy ide-detect ide-generic ide-floppy ide-cd isofs ide-disk ehci-hcd ohci-hcd uhci-hcd usb-uhci uhci usb-ohci ehci-hcd sr_mod"
        for i in $MANUAL_MODULES; do
                echo "$i"
        done
}


# set LD_LIBRARY_PATH
for i in $(find /usr/lib -type d); do
  export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$i
done

for i in $(mydiscover; manual); do
	echo "bootcdmodprobe $i" >&2
	modprobe $i
done
