#!/bin/bash

# VIA Technologies, Inc.
# DriverDisk script. By Dolpher Du
#				2003/07/03

# Create a RedHat driver disk for viaraid.  Expects you to have two
# versions of the module compiled against the relevant RedHat source
# tree.  The modules are
#
#	viaraid.o-2.4.7-10BOOT		build with boot kernel config
#	viaraid.o-2.4.7-10			build with i386 kernel config
#
# "2.4.7-10" is the base kernel version,should be set appropriately
# below.
# Assume dd.sh is in the same directory with sourcecode.

MODNAME=viamraid
MKFILE=Makefile

BOOTPARA="-e BOOT=1"
#uncomment this line for mandrake linux
#BOOTPARA="-e NOMODVER=1"

#Get linux version information
BASE=`uname -r`
#Try to patch RH7.2
if !(echo ${BASE} |grep "2.4.7-10") ; then
	echo -e "Not redhat 7.2."
else
	echo "RedHat7.2, patch.."
	BOOTPARA="${BOOTPARA} RH72=1"
fi
#patch ends

#BASE=2.4.7-10
#BASE=2.4.20-8
#prepare the .o file
rm -rf driverdisk
mkdir driverdisk
make -f ${MKFILE} clean
make -f ${MKFILE} ${BOOTPARA}
cp ${MODNAME}.o driverdisk/${MODNAME}.o-${BASE}BOOT
make -f ${MKFILE} clean
make -f ${MKFILE} 
cp ${MODNAME}.o driverdisk/${MODNAME}.o-${BASE}
cd driverdisk

#make the driverdisk image
mkdir mountpoint
mkdir workdir
dd if=/dev/zero of=${MODNAME}.img bs=1k count=512
echo y |mkdosfs ${MODNAME}.img
mount -o loop ${MODNAME}.img mountpoint
cd mountpoint
#rm -rf lost+found
echo "${MODNAME}.o:scsi_mod.o sd_mod.o" >modules.dep
echo "0x1106	0x3249	\"${MODNAME}\"	\"VIATECH|VIA VT6421 RAID Controller\"" >pcitable
echo "0x1106	0x3149	\"${MODNAME}\"	\"VIATECH|VIA VT6420 RAID Controller\"" >>pcitable
echo "0x1106	0x3164	\"${MODNAME}\"	\"VIATECH|VIA VT6410 RAID Controller\"" >>pcitable
echo "Version 0" > modinfo
echo "${MODNAME}" >> modinfo
echo "    scsi" >> modinfo
echo "    \"Raid controller,VIA technologies.\"" >> modinfo
echo "1" > rhdd-6.1
cd ../workdir
mkdir ${BASE}BOOT
#mkdir ${BASE}smp
#mkdir ${BASE}debug
#mkdir ${BASE}enterprise
mkdir ${BASE}
cp ../${MODNAME}.o-${BASE}BOOT ${BASE}BOOT/${MODNAME}.o
cp ../${MODNAME}.o-${BASE} ${BASE}/${MODNAME}.o
find -name "*.o" -type f | cpio -o --format=crc | gzip -9 > ../mountpoint/modules.cgz
cd ..

#Patch for RH7.2, update disk
if (echo ${BASE} |grep "2.4.7-10") ; then
cp ../PACKAGES.PY mountpoint/PACKAGES.PY
fi
#end patch

umount ${MODNAME}.img
