#!/bin/sh
# pre install script for the Debian GNU/Linux modutils package

# Divert kerneld.h from the libc6-dev package
dpkg-divert --package modutils --add --rename \
		--divert /usr/include/linux/kerneld.h.libc6 \
			/usr/include/linux/kerneld.h

# maybe an old kerneld is still running?
if [ -f /sbin/kerneld ]; then
  start-stop-daemon --stop --quiet --oknodo --exec /sbin/kerneld
fi

# Be nice and remember the configuration..
if [ -f /etc/init.d/kerneld ]; then 
	echo "Saving KDOPT setting from /etc/init.d/kerneld .."
	OPTLINE="`grep '^KDOPT=' /etc/init.d/kerneld`"
	if [ "$OPTLINE" != 'KDOPT=""' ]; then
		echo "$OPTLINE" > /var/run/kerneld.OPT
	fi
fi

# Check for symlinked /etc/conf.modules and replace it by a real file
if [ -f /etc/conf.modules -a -L /etc/conf.modules ]; then
	echo "Your /etc/conf.modules is a symlink. I will replace this by"
	echo "a real file so update-modules can do it's work later."
	mv /etc/conf.modules /etc/conf.modules.DPKG-UPGRADE
	cat /etc/conf.modules.DPKG-UPGRADE > /etc/conf.modules
	rm /etc/conf.modules.DPKG-UPGRADE
fi

# Remove any architecture-specifics in /etc/modutils. This is safe since
# we already copied the used file (see above).
echo -n "Removing obsoleted files: "
for i in conf.generic conf.i386 conf.m68k conf.m68k.amiga conf.m68k.atari \
		conf.m68k.amiga conf.m68k.mac ; do
	if [ -f /etc/modutils/$i ]; then
		echo -n "$i "
		rm -f /etc/modutils/$i
	fi
done
echo

cat <<EOF

Dpkg might ask you if you want the new configuration files in /etc/init.d.
This is generally a good idea, unless you have really changed any of these
files. The KDOPT setting in /etc/init.d/kerneld will be saved even if you
install a new version of this file.

EOF

