# This file performs various system initializations.

umask 022
PATH=/usr/local/bin:/bin:/usr/bin
export PATH

# National keyboard?
test -f /etc/keymap && loadkeys /etc/keymap

# Set timezone.  (If the clock tells GMT then put this after 'date'.)
. /etc/profile

# Try to read the hardware real-time clock, if there is one, to set the date
# date `readclock`    Not on smx 

# Initialize files.
printroot >/etc/mtab			# /etc/mtab keeps track of mounts
>/etc/utmp				# /etc/utmp keeps track of logins

# /etc/fstab lists the root, tmp and usr devices.
. /etc/fstab

# Mount the /usr partition unless it is a single floppy Minix.
if [ ! -f /usr/bin/shutdown ]
then
	case $usrbin in
	unknown)
		# We need to ask what the /usr/bin du jour is.
		echo -n "Finish the name of device to mount as /usr/bin: /dev/"
		read usrbin
		usrbin=/dev/$usrbin
	esac
	mount $usrbin /usr/bin 
fi

# Check if the system crashed.
if shutdown -C
then
	umount $usrbin
	echo
	echo "The system was not properly shut down.  Checking file systems."

	fsck -r $root
	fsck -r $usrbin
	fsck -r $man

	mount $usrbin /usr/bin 
fi

mount $man /usr/man 

case "`printroot -r`" in
/dev/ram)
	# Don't need these things clogging up the RAM disk
	rm -rf /boot /minix
esac

# National font?
test -f /etc/font && loadfont /etc/font

echo -n "Starting standard daemons:"
test -f /usr/lib/crontab && cron=cron
for daemon in update $cron
do
	if [ -f /usr/bin/$daemon ]
	then
		echo -n " $daemon"
		$daemon &
	fi
done
echo .

# Network initialization.  To disable network initialisation, simply
# uncomment out the following line and comment out the line that
# sets net to true
#net=false
(</dev/eth </dev/tcp) 2>/dev/null && net=true	# Is there a TCP/IP server?

if [ "$net" = "true" ] && [ -f /etc/rc.net ]
then
	. /etc/rc.net
else
	echo noname >/etc/hostname.file
fi

# Don't let wtmp grow indefinitely.
find /usr/adm/wtmp -size +100 -exec sh -c \
	"cp /usr/adm/wtmp /usr/adm/wtmp.1; >/usr/adm/wtmp" \; 2>/dev/null

# Cleanup.
test -f /usr/bin/elvprsv && elvprsv /usr/tmp/elv*
rm -rf /tmp/. /usr/tmp/.
