rc.subr revision 1.7
11.7Scjs# $NetBSD: rc.subr,v 1.7 1999/04/01 03:58:44 cjs Exp $ 21.1Scjs# functions used by various rc scripts 31.1Scjs 41.5Slukem# 51.5Slukem# checkyesno 61.5Slukem# Test $1 variable, and warn if not set to YES or NO. 71.5Slukem# return 0 if it's "yes" (et al), nonzero otherwise 81.5Slukem# 91.1Scjscheckyesno() { 101.4Slukem eval value=\$${1} 111.3Slukem case $value in 121.4Slukem 131.4Slukem # "yes", "true", "on", or "1" 141.4Slukem [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) 151.4Slukem return 0 161.3Slukem ;; 171.4Slukem 181.4Slukem # "no", "false", "off", or "0" 191.4Slukem [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) 201.4Slukem return 1 211.3Slukem ;; 221.4Slukem 231.3Slukem *) 241.3Slukem logger -s "WARNING: \$${1} is not set properly." 251.4Slukem return 1 261.3Slukem ;; 271.3Slukem esac 281.6Smellon} 291.6Smellon 301.6Smellon# 311.6Smellon# mount_critical_filesystems 321.6Smellon# Go through the list of critical filesystems, checking each one 331.6Smellon# to see if it is mounted, and if it is not, mounting it. 341.6Smellon# 351.7Scjsfstab=/etc/fstab 361.6Smellonmount_critical_filesystems() { 371.6Smellon for fs in /usr /var $critical_filesystems; do 381.7Scjs if [ $1 = local ] && ! islocalfs $fs; then 391.7Scjs continue 401.7Scjs fi 411.6Smellon mount | ( 421.6Smellon ismounted=no 431.6Smellon while read what _on on _type type; do 441.6Smellon if [ $on = $fs ]; then 451.6Smellon ismounted=yes 461.6Smellon fi 471.6Smellon done 481.6Smellon if [ $ismounted = no ]; then 491.6Smellon mount $fs >/dev/null 2>&1 501.6Smellon fi 511.6Smellon ) 521.6Smellon done 531.7Scjs} 541.7Scjs 551.7Scjsislocalfs() { 561.7Scjs if [ -z "$1" ]; then 571.7Scjs echo 'islocalfs() called with no fs argument: aborting.' 581.7Scjs exit 3 591.7Scjs fi 601.7Scjs while read dev dir type opts; do 611.7Scjs if [ "$1" = "$dir" ]; then 621.7Scjs case $type in 631.7Scjs # Local filesystems. 641.7Scjs ados|cd9660|ext2fs|fdesc|ffs) return 0;; 651.7Scjs filecore|kernfs|lfs|mfs|msdos|null) return 0;; 661.7Scjs portal|procfs|ufs|umap|union) return 0;; 671.7Scjs # Network filesystems 681.7Scjs nfs) return 1;; 691.7Scjs # If we don't know, err on the safe side 701.7Scjs # and assume it's a network FS. 711.7Scjs *) return 1;; 721.7Scjs esac 731.7Scjs fi 741.7Scjs done < $fstab 751.7Scjs # We didn't find the FS. Return local to show error as 761.7Scjs # early in boot sequence as possible. 771.7Scjs echo "WARNING: islocalfs() in rc.subr doesn't recognise fstype $fs" 781.7Scjs return 1; 791.1Scjs} 80