#!/bin/sh

VER=`awk '/version/ {print $3}' /proc/version`
V1=2.0.36
V2=2.2.5

PRINTK=`grep printk /proc/ksyms | awk '{print $2}'`

if grep SMP /proc/version > /dev/null
then
    echo "Error: Kernel must be compiled without SMP support"
    exit 1
fi

if [ "$VER" = "$V1" -o "$VER" = "$V2" ]
then
	MODNAME="sblive.o-$VER"
else
    echo "Error: Linux kernel version $V1 or $V2 is required"
    exit 1
fi

if [ -f /etc/conf.modules ]
then
    OLDSND=`grep "alias sound" /etc/conf.modules | awk '{print $3}'`
    OLDMID=`grep "alias midi" /etc/conf.modules | awk '{print $3}'`

    mv -f /etc/conf.modules /etc/conf.modules.old
    ./mod_conf /etc/conf.modules.old > /etc/conf.modules
    echo "alias sound sblive" >> /etc/conf.modules
    if [ "$PRINTK" != "printk" ]
    then
	echo "pre-install sblive insmod soundcore" >> /etc/conf.modules
	echo "post-remove sblive rmmod soundcore" >> /etc/conf.modules
    fi
fi

if [ -d /lib/modules/preferred ]
then
    VER=preferred
fi

mkdir -p /lib/modules/$VER/misc
if cp -f $MODNAME /lib/modules/$VER/misc/sblive.o
then
    if depmod -a > /dev/null
    then
	if [ "$OLDSND" -o "$OLDMID" ]
	then
       	    echo "Soundblaster Live! driver installed. Please reboot."
        else
	    if modprobe sblive
	    then
	        echo "Soundblaster Live! driver installed."
	    fi
	fi
    fi
fi