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

# 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

# If /etc/modutils doesn't exist we are upgrading from an older system.
# Move conf.modules to the new location.
if [ -f /etc/conf.modules -a ! -L /etc/conf.modules ]; then
	echo "You still have /etc/conf.modules, moving it to /etc/modutils"
	MODEL=`dpkg --print-installation-architecture`
	CONF="/etc/modutils/conf.${MODEL}"
	if [ $MODEL = "m68k" ]; then
		if [ -f /proc/hardware ]; then
			case `awk '$1 == "Model:" { print $2 }' /proc/hardware` in
				Atari)
					CONF="${CONF}.atari"
					;;
				Amiga)
					CONF="${CONF}.amiga"
					;;
				Macintosh)
					CONF="${CONF}.mac"
					;;
				Motorola)
					CONF="${CONF}.MVME"
					;;
			esac
		else
			echo "/proc not mounted, assuming generic m68k machine"
		fi
	fi

	if [ ! -d /etc/modutils ]; then
		echo "You have no /etc/modutils directory, creating it"
		mkdir /etc/modutils
		chmod 755 /etc/modutils
	fi

	echo "Moving /etc/conf.modules to $CONF"
	mv /etc/conf.modules $CONF
fi

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

