#!/sbin/sh
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
# All rights reserved.
#
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
# The copyright notice above does not evidence any
# actual or intended publication of such source code.
#
# Copyright (c) 1996-1999 by Sun Microsystems, Inc.
# All rights reserved.
#
#ident	"@(#)rootusr	1.30	99/12/01 SMI"

# Make sure that the libraries essential to this stage of booting can be found.
LD_LIBRARY_PATH=/etc/lib; export LD_LIBRARY_PATH

#
# Root is already mounted (by the kernel), but still needs to be checked,
# possibly remounted and entered into mnttab. First mount /usr read only
# if it is a separate file system. This must be done first to allow
# utilities such as fsck and setmnt to reside on /usr minimizing the space
# required by the root file system.
#
exec < $vfstab; readvfstab "/usr"

if [ -n "$mountp" ]; then
	if [ "$fstype" = cachefs ]; then
		#
		# Mount without the cache initially.  We'll enable it
		# later at remount time.  This lets us avoid
		# teaching the statically linked mount program about
		# cachefs.  Here we determine the backfstype.
		# This is not pretty, but we have no tools for parsing
		# the option string until we get /usr mounted...
		#
		case "$mntopts" in
		*backfstype=nfs*)
			cfsbacktype=nfs
			;;
		*backfstype=hsfs*)
			cfsbacktype=hsfs
			;;
		*)
			echo 'invalid vfstab entry for /usr'
			cfsbacktype=nfs
			;;
		esac
		/sbin/mount -F $cfsbacktype -o ro $special $mountp
	else
		#
		# Must use -o largefiles here to ensure the read-only mount
		# does not fail as a result of having a large file present
		# on /usr. This gives fsck a chance to fix up the largefiles
		# flag before we remount /usr read-write.
		#
		if [ "x$mntopts" = x- ]; then
			mntopts='ro,largefiles'
		else
			checkopt largefiles $mntopts
			if [ "x$option" != xlargefiles ]; then
				mntopts="largefiles,$mntopts"
			fi

			checkopt ro $mntopts
			if [ "x$option" != xro ]; then
				mntopts="ro,$mntopts"
			fi

			#
			# Requesting logging on a read-only mount
			# causes errors to be displayed, so remove
			# "logging" from the list of options for now.
			# The read-write mount performed later will
			# specify the logging option if appropriate.
			#

			checkopt logging $mntopts
			if [ "x$option" = xlogging ]; then
				mntopts="$otherops"
			fi
		fi

		/sbin/mount -o $mntopts /usr
	fi
fi

#
# Also mount /boot now so that things like keymap.sh can access 
# boot properties through eeprom.  Readonly isn't required because
# /boot (and other pcfs filesystems) aren't fsck'ed at boot yet.  
# Also, we don't account for caching /boot as it must be on a local
# disk.  So what's in vfstab is fine as it stands; just look to see 
# if it's there and avoid the mount if not.
#
exec < $vfstab; readvfstab "/boot"

if [ -n "$mountp" ]; then
	/sbin/mount /boot
fi


[ -f /etc/.dynamic_routing ] && /usr/bin/rm -f /etc/.dynamic_routing

# Reset the library path now that we are past the critical stage
LD_LIBRARY_PATH=; export LD_LIBRARY_PATH

# If we need the consadm daemon, start it as soon as /usr/lib becomes available.
[ -x /usr/sbin/consadmd -a -r /etc/consadm.conf ] && /usr/sbin/consadmd &
