#!/bin/bash

#if [ -e /dev/.devfs ] ; then
# echo "You have devfs, nodes will be created automagically"
# exit 0
#fi
#if [ -e /dev/.udev ] || [ -e /dev/.udev.tdb ] ; then
# echo "You have udev, nodes will be created automagically"
# exit 0
#fi
#if [ ! -z "${DESTDIR}" ] ; then
# echo "Creating a package, nodes should be created later"
# exit 0
#fi

# find out cdemu device major number
if [ ! -r /proc/devices ]; then
echo "Can't open /proc/devices, make sure /proc is mounted"
exit 0
fi

modprobe cdemu
if [ -z "$(lsmod | grep ^cdemu)" ]; then
echo "Can't load module"
exit 0
fi
cdemumajor=$(grep "^[[:space:]]*[0-9]\+[[:space:]]\+cdemu$" /proc/devices | grep -o "[0-9]\+")
if [ -z "$cdemumajor" ]; then
echo "Can't find cdemu device number in /proc/devices"
exit 0
fi
#modprobe -r cdemu
#

if [ -e /dev/cdemu ]; then
rm -rf /dev/cdemu
fi
if [ -b /dev/cdemu0 ]; then
rm -f /dev/cdemu*
fi
mkdir /dev/cdemu
for drivenumber in `seq -w 0 7` ; do
mknod /dev/cdemu/${drivenumber} b ${cdemumajor} ${drivenumber}
done

#echo "if no error did show up device files created ;-)"

