PageRenderTime 246ms CodeModel.GetById 239ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/rc6.d/S31umountnfs.sh

http://github.com/brinkman83/bashrc
Shell | 104 lines | 73 code | 12 blank | 19 comment | 4 complexity | b824a44ff24087eb2bf6780db7dfd9dc MD5 | raw file
  1#! /bin/sh
  2### BEGIN INIT INFO
  3# Provides:          umountnfs
  4# Required-Start:
  5# Required-Stop:     umountfs
  6# Should-Stop:       $network $portmap nfs-common
  7# Default-Start:
  8# Default-Stop:      0 6
  9# Short-Description: Unmount all network filesystems except the root fs.
 10# Description:       Also unmounts all virtual filesystems (proc, devfs,
 11#                    devpts, usbfs, sysfs) that are not mounted at the
 12#                    top level.
 13### END INIT INFO
 14
 15PATH=/sbin:/usr/sbin:/bin:/usr/bin
 16KERNEL="$(uname -s)"
 17RELEASE="$(uname -r)"
 18. /lib/init/vars.sh
 19
 20. /lib/lsb/init-functions
 21
 22case "${KERNEL}:${RELEASE}" in
 23  Linux:[01].*|Linux:2.[01].*)
 24	FLAGS=""
 25	;;
 26  Linux:2.[23].*|Linux:2.4.?|Linux:2.4.?-*|Linux:2.4.10|Linux:2.4.10-*)
 27	FLAGS="-f"
 28	;;
 29  *)
 30	FLAGS="-f -l"
 31	;;
 32esac
 33
 34do_stop () {
 35	# Write a reboot record to /var/log/wtmp before unmounting
 36	halt -w
 37
 38	# Remove bootclean flag files (precaution against symlink attacks)
 39	rm -f /tmp/.clean /var/lock/.clean /var/run/.clean
 40
 41	#
 42	# Make list of points to unmount in reverse order of their creation
 43	#
 44
 45	exec 9<&0 </etc/mtab
 46
 47	DIRS=""
 48	while read -r DEV MTPT FSTYPE OPTS REST
 49	do
 50		case "$MTPT" in
 51		  /|/proc|/dev|/dev/pts|/dev/shm|/proc/*|/sys|/lib/init/rw)
 52			continue
 53			;;
 54		  /var/run)
 55			continue
 56			;;
 57		  /var/lock)
 58			continue
 59			;;
 60		esac
 61		case "$FSTYPE" in
 62		  nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs)
 63			DIRS="$MTPT $DIRS"
 64			;;
 65		  proc|procfs|linprocfs|devfs|devpts|usbfs|usbdevfs|sysfs)
 66			DIRS="$MTPT $DIRS"
 67			;;
 68		esac
 69		case "$OPTS" in
 70		  _netdev|*,_netdev|_netdev,*|*,_netdev,*)
 71			DIRS="$MTPT $DIRS"
 72			;;
 73		esac
 74	done
 75
 76	exec 0<&9 9<&-
 77
 78	if [ "$DIRS" ]
 79	then
 80		[ "$VERBOSE" = no ] || log_action_begin_msg "Unmounting remote and non-toplevel virtual filesystems"
 81		fstab-decode umount $FLAGS $DIRS
 82		ES=$?
 83		[ "$VERBOSE" = no ] || log_action_end_msg $ES
 84	fi
 85}
 86
 87case "$1" in
 88  start)
 89	# No-op
 90	;;
 91  restart|reload|force-reload)
 92	echo "Error: argument '$1' not supported" >&2
 93	exit 3
 94	;;
 95  stop|"")
 96	do_stop
 97	;;
 98  *)
 99	echo "Usage: umountnfs.sh [start|stop]" >&2
100	exit 3
101	;;
102esac
103
104: