rc.subr revision 1.9
1# $NetBSD: rc.subr,v 1.9 1999/04/28 23:32:29 nathanw 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 for fs in $critical_filesystems; do 38 if [ $1 = local ] && ! islocalfs $fs; then 39 continue 40 fi 41 mount | ( 42 ismounted=no 43 while read what _on on _type type; do 44 if [ $on = $fs ]; then 45 ismounted=yes 46 fi 47 done 48 if [ $ismounted = no ]; then 49 mount $fs >/dev/null 2>&1 50 fi 51 ) 52 done 53} 54 55islocalfs() { 56 if [ -z "$1" ]; then 57 echo 'islocalfs() called with no fs argument: aborting.' 58 exit 3 59 fi 60 while read dev dir type opts; do 61 if [ "$1" = "$dir" ]; then 62 case $type in 63 # Local filesystems. 64 ados|cd9660|ext2fs|fdesc|ffs) return 0;; 65 filecore|kernfs|lfs|mfs|msdos|null) return 0;; 66 portal|procfs|ufs|umap|union) return 0;; 67 # Network filesystems 68 nfs) return 1;; 69 # If we don't know, err on the safe side 70 # and assume it's a network FS. 71 *) return 1;; 72 esac 73 fi 74 done < $fstab 75 # Quietly ignore not-found filesystems. 76 return 1; 77} 78