#!/bin/sh
#
# (C) Copyright 1993, 1994 Mike Jagdis (jaggy@purplet.demon.co.uk)
#
#
# Boot time system setup

# Load the general library functions and find some programs.
. /etc/init.d/LIB
mount=`pathof mount`
bdflush=`pathof bdflush`
update=`pathof update`

# If there are one or more update or bdflush lines in the inittab then
# we assume they are there because this init handles periodic syncs and
# buffer flushing itself, otherwise we start a bdflush or update daemon
# to do it.
if [ X`awk '/^[^:]*:[^:]*:(update|bdflush):/ { print "Y"; exit 0 }' /etc/inittab` != XY ]; then
	if [ -n "$bdflush" ]; then
		$bdflush &
	elif [ -n "$update" ]; then
		$update &
	else
		echo "IMPORTANT: Inittab contains no update or bdflush lines and no update or"
		echo "IMPORTANT: bdflush program was found."
		echo "IMPORTANT: MODIFIED DATA WILL BUILD UP IN CACHE AND NEVER DRAIN!"
	fi
fi

# Clean temporary directories, lock files etc. in preparation for the
# system going multiuser. Do *not* delete /fastboot or /etc/fastboot
# here. They are deleted after mounting filesystems.

echo $use_escapes "Cleaning system...\c"

# If we can see an elvprsv out there run it to pick up any files that
# were being editted when the system crashed. Do it *before* we wipe
# the temporary directories!
it=`pathof elvprsv`
if [ -n "$it" ]; then
	$it
fi

rm -f /usr/spool/uucp/LCK*
rm -rf /tmp/.??* /tmp/* /usr/tmp/.??* /usr/tmp/*
rm -f /etc/nologin
> /etc/utmp

# Permissions fixing. Shutdowns tend to be violent and don't necessarily
# give processes time to reset permissions. Xdm is one culprit leaving
# the console owned by the wrong user.
chown root /dev/console
chmod 622 /dev/console

echo " done"

# Run any other configuration scripts we may have.
if [ -d /etc/brc.d ]; then
	for i in /etc/brc.d/*
	do
		if [ -s $i ]; then
			/bin/sh $i
		fi
	done
fi

# Announce that the system is multiuser.
msg notice "System now running multiuser"
