178344Sobrien#!/bin/sh
278344Sobrien#
398184Sgordon# $FreeBSD$
478344Sobrien#
578344Sobrien
678344Sobrien# PROVIDE: mountcritremote
7240336Sobrien# REQUIRE: NETWORKING FILESYSTEMS ipsec netwait
8136224Smtm# KEYWORD: nojail
978344Sobrien
1078344Sobrien. /etc/rc.subr
1178344Sobrien
1278344Sobrienname="mountcritremote"
13298514Slmedesc="Mount critical remote filesystems"
1478344Sobrienstop_cmd=":"
15124622Smtmstart_cmd="mountcritremote_start"
16124622Smtmstart_precmd="mountcritremote_precmd"
1778344Sobrien
1898184Sgordon# Mount NFS filesystems if present in /etc/fstab
1998184Sgordon#
2098184Sgordon# XXX When the vfsload() issues with nfsclient support and related sysctls
2198184Sgordon# have been resolved, this block can be removed, and the condition that
2298184Sgordon# skips nfs in the following block (for "other network filesystems") can
2398184Sgordon# be removed.
2498184Sgordon#
2598184Sgordonmountcritremote_precmd()
2698184Sgordon{
2798184Sgordon	case "`mount -d -a -t nfs 2> /dev/null`" in
2898184Sgordon	*mount_nfs*)
2998184Sgordon		# Handle absent nfs client support
30222993Srmacklem		load_kld -m nfs nfscl || return 1
3198184Sgordon		;;
3298184Sgordon	esac
3398184Sgordon	return 0
3498184Sgordon}
3598184Sgordon
3698184Sgordonmountcritremote_start()
3798184Sgordon{
38301004Sngie	local mounted_remote_filesystem=false
39301004Sngie
40124622Smtm	# Mount nfs filesystems.
41124622Smtm	#
42179928Smtm	case "`/sbin/mount -d -a -t nfs`" in
43179928Smtm	'')
44179928Smtm		;;
45179928Smtm	*)
46301004Sngie		mounted_remote_filesystem=true
47298514Slme		echo -n 'Mounting NFS filesystems:'
48179928Smtm		mount -a -t nfs
49179928Smtm		echo '.'
50179928Smtm		;;
51179928Smtm	esac
5298184Sgordon
53124622Smtm	# Mount other network filesystems if present in /etc/fstab.
54124622Smtm	case ${extra_netfs_types} in
55124622Smtm	[Nn][Oo])
56124622Smtm		;;
57124622Smtm	*)
58124622Smtm		netfs_types="${netfs_types} ${extra_netfs_types}"
59124622Smtm		;;
60124622Smtm	esac
61115585Sgordon
62124622Smtm	for i in ${netfs_types}; do
63124622Smtm		fstype=${i%:*}
64124622Smtm		fsdecr=${i#*:}
6598184Sgordon
66124622Smtm		[ "${fstype}" = "nfs" ] && continue
6798184Sgordon
68124622Smtm		case "`mount -d -a -t ${fstype}`" in
69124622Smtm		*mount_${fstype}*)
70301004Sngie			mounted_remote_filesystem=true
71298514Slme			echo -n "Mounting ${fsdecr} filesystems:"
72124622Smtm			mount -a -t ${fstype}
73124622Smtm			echo '.'
74124622Smtm			;;
75124622Smtm		esac
76124622Smtm	done
7798184Sgordon
78301004Sngie	if $mounted_remote_filesystem; then
79301004Sngie		# Cleanup /var again just in case it's a network mount.
80301004Sngie		/etc/rc.d/cleanvar quietreload
81301004Sngie		rm -f /var/run/clean_var /var/spool/lock/clean_var
82301004Sngie
83301004Sngie		# Regenerate the ldconfig hints in case there are additional
84301004Sngie		# library paths on remote file systems
85301004Sngie		/etc/rc.d/ldconfig quietstart
86301004Sngie	fi
8798184Sgordon}
8898184Sgordon
8978344Sobrienload_rc_config $name
9078344Sobrienrun_rc_command "$1"
91