#!/bin/sh -e

DIVERSIONS2="misc/ftape.o \
misc/bpck-fdc.o \
misc/zft-compressor.o \
misc/ftape-internal.o \
misc/trakker.o \
misc/zftape.o"
DIVERSIONS4="kernel/drivers/char/ftape/lowlevel/ftape.o \
kernel/drivers/char/ftape/compressor/zft-compressor.o \
kernel/drivers/char/ftape/zftape/zftape.o"
# these three modules are not build in kernel 2.4
#bpck-fdc.o \
#ftape-internal.o \
#trakker.o \


# kernel 2.4.0 has changed the location of the ftape modules
# linuxversion is defined in prep-modules, that calls this script

case "$linuxversion" in
    2.0*|2.1*|2.2*|2.3*)
	DIVERSIONS=$DIVERSIONS2
	;;
    2.4*)
	DIVERSIONS=$DIVERSIONS4
	;;
    *)  echo "debian/generate-preinstpostrm error: linuxversion=$linuxversion"
	echo "Report to maintainer to fix this"
	exit
	;;
esac


# Now the preinst and postrm generation functions

do_preinst (){
cat <<EOF 
#!/bin/sh -e
if [ "\$1" = "install" ]; then
EOF
#
for i in $DIVERSIONS; do
cat <<EOF
    dpkg-divert --package ftape-module-=KVERS --add --rename \\
                --divert /lib/modules/=KVERS/$i.old \\
			 /lib/modules/=KVERS/$i
EOF
done
#
echo "fi"
}

do_postrm (){
cat <<EOF
#!/bin/sh -e
if [ remove = "\$1" ]; then
EOF
#
for i in $DIVERSIONS; do
cat <<EOF
    dpkg-divert --package ftape-module-=KVERS --remove --rename \\
                --divert /lib/modules/=KVERS/$i.old \\
                         /lib/modules/=KVERS/$i
EOF
done
#
echo "fi"
#
cat <<EOF
if [ "\$1" = "purge" -a -e /usr/share/debconf/confmodule ]; then
        # Source debconf library.
        . /usr/share/debconf/confmodule
        # Remove my changes to the db.
        db_purge
fi
EOF
}

do_preinst > debian/mod.preinst
do_postrm  > debian/mod.postrm