#! /bin/sh
#
# debian.postinst
#		Creates /dev/initctl if not already there.
#		Also checks /etc/inittab for single user entry.
#
# Version:	debian.postinst  1.01  04-Jan-1996  MvS.
#

# Check /dev/initctl
if [ ! -p /dev/initctl ]
then
	echo "Creating /dev/initctl"
	rm -f /dev/initctl
	mknod -m 600 /dev/initctl p
fi

# Check single user entry in /etc/inittab
if grep -q '^[^:]\{1,4\}:S:' /etc/inittab
then
	if ! grep -q '^[^:]\{1,4\}:S:wait:/sbin/sulogin' /etc/inittab
	then
		cat <<EOF

You have a single user entry in /etc/inittab, but it doesn't call
/sbin/sulogin - consider changing this manually after installation.
(change into "~~:S:wait:/sbin/sulogin").

EOF
		echo -n "Hit Enter key to continue...."
		read junk
	else
		echo "You have a single user entry in /etc/inittab -- good."
	fi
else
	cat <<EOF

You don't have a single user entry in your /etc/inittab file -
do you want me to change your inittab so that the sulogin
program is called in single user mode (prompts you for the
EOF
	echo -n "root password) [y] "
	read res
	case "$res" in
	  ""|y*|Y*)
		# Add single user entry.
		rm -f /tmp/init1.$$ /tmp/init2.$$
		head -2 /etc/inittab > /tmp/init1.$$
		echo >> /tmp/init1.$$
		echo '# What to do in single user mode.' >> /tmp/init1.$$
		echo '~~:S:wait:/sbin/sulogin' >> /tmp/init1.$$
		tail +3 /etc/inittab >> /tmp/init1.$$
		cp -a /etc/inittab /etc/inittab.dpkg-old
		cp /tmp/init1.$$ /etc/inittab	
		rm -f /tmp/init1.$$
		;;
	  *)
		echo "Okay."
		;;
	esac
fi

# See if sulogin is called in /etc/init.d/boot
if ! grep -q /sbin/sulogin /etc/init.d/boot
then
	cat <<EOF

Your system does not call /sbin/sulogin after a failure in
the boot process - this means that a root shell is started on
the console which is insecure. Please edit the file /etc/init.d/boot
and change the line that looks like this:

/bin/sh < /dev/console

into

/sbin/sulogin /dev/console.

An example may be found in /etc/init.d/boot.dpkg-new.
EOF
	echo -n "Hit Enter to continue..."
	read junk
fi

# Reset GMT setting in /etc/init.d/boot.
if [ -f /tmp/boot.GMT ]
then
	echo "Restoring original GMT setting to /etc/init.d/boot.."
	GMTLINE="`cat /tmp/boot.GMT`"
	cp /etc/init.d/boot /etc/init.d/boot.TMP
	sed -e "s/^GMT=.*/$GMTLINE/" < /etc/init.d/boot.TMP > /etc/init.d/boot
	if [ -s /etc/init.d/boot ]
	then
		rm -f /etc/init.d/boot.TMP
	fi
	rm -f /tmp/boot.GMT
fi

