rc.subr revision 1.10
1#	$NetBSD: rc.subr,v 1.10 1999/07/07 21:24:56 drochner Exp $
2# functions used by various rc scripts
3
4#
5# checkyesno
6#	Test $1 variable, and warn if not set to YES or NO.
7#	return 0 if it's "yes" (et al), nonzero otherwise
8#
9checkyesno() {
10	eval value=\$${1}
11	case $value in
12
13		#	"yes", "true", "on", or "1"
14	[Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
15		return 0
16		;;
17
18		#	"no", "false", "off", or "0"
19	[Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0)
20		return 1
21		;;
22
23	*)
24		logger -s "WARNING: \$${1} is not set properly."
25		return 1
26		;;
27	esac
28}
29
30#
31# mount_critical_filesystems
32#	Go through the list of critical filesystems, checking each one
33#	to see if it is mounted, and if it is not, mounting it.
34#
35fstab=/etc/fstab
36mount_critical_filesystems() {
37	if [ $1 = local ]; then
38		_fslist=$critical_filesystems_beforenet
39	else
40		_fslist=$critical_filesystems
41	fi
42	for fs in $_fslist; do
43		mount | (
44			ismounted=no
45			while read what _on on _type type; do
46				if [ $on = $fs ]; then
47					ismounted=yes
48				fi
49			done
50			if [ $ismounted = no ]; then 
51				mount $fs >/dev/null 2>&1
52			fi
53		)  
54	done
55}
56
57islocalfs() {
58	if [ -z "$1" ]; then
59		echo 'islocalfs() called with no fs argument: aborting.'
60		exit 3
61	fi
62	while read dev dir type opts; do
63		if [ "$1" = "$dir" ]; then
64			case $type in
65				# Local filesystems.
66				ados|cd9660|ext2fs|fdesc|ffs) return 0;;
67				filecore|kernfs|lfs|mfs|msdos|null) return 0;;
68				portal|procfs|ufs|umap|union) return 0;;
69				# Network filesystems
70				nfs) return 1;;
71				# If we don't know, err on the safe side
72				# and assume it's a network FS.
73				*) return 1;;
74			esac
75		fi
76	done < $fstab
77	# Quietly ignore not-found filesystems.
78	return 1;
79}
80