#!/bin/bash
#
#set -x

DEFAULT_MODULES="usb-storage"

KV=`uname -r`
KV_MAJOR=`uname -r | cut -f1 -d "."`
KV_MINOR=`uname -r | cut -f2 -d "."`

ALLMOD_FILE="/lib/modules/$KV/modules.pcimap"
MODCONF="/etc/modules.autoload.d/kernel-${KV_MAJOR}.${KV_MINOR}"

if [ ! -f $MODCONF ] ; then
   for i in $DEFAULT_MODULES ; do
      echo "Adding default $i to $MODCONF"
      echo "$i" >> $MODCONF
   done
fi

rm -f $MODCONF.new

MP=`which modprobe`
rm $MP.gen2vdr > /dev/null 2>&1
if [ -f $MP ] ; then
   rm /tmp/mp > /dev/null 2>&1

   mv $MP $MP.gen2vdr
   echo "#/bin/sh" > $MP
   echo "echo \$* >> /tmp/mp" >> $MP
   chmod +x $MP
fi
/etc/init.d/coldplug stop
/etc/init.d/coldplug start
if [ -f $MP.gen2vdr ] ; then
   rm -f $MP > /dev/null 2>&1
   mv $MP.gen2vdr $MP
fi


AM=`cat /tmp/mp | sed "/-s -q -n.*/d" | sed "s/-[sn] //g" |sed "s/-q //" |sort`

OM=""
for i in $AM ; do
   if [ "$i" != "$OM" ] ; then
      echo "Adding default $i to $MODCONF.gen2vdr"
      echo "$i" >> $MODCONF.gen2vdr
   fi
   OM=$i
done


