add patch for 99_ftbfs_define_enoioctlcmd.patch
[external/sysvinit.git] / debian / src / initscripts / etc / init.d / umountnfs.sh
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
15 PATH=/sbin:/usr/sbin:/bin:/usr/bin
16 KERNEL="$(uname -s)"
17 RELEASE="$(uname -r)"
18 . /lib/init/vars.sh
19
20 . /lib/lsb/init-functions
21
22 case "${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         ;;
32 esac
33
34 do_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                         if [ yes = "$RAMRUN" ] ; then
56                                 continue
57                         fi
58                         ;;
59                   /var/lock)
60                         if [ yes = "$RAMLOCK" ] ; then
61                                 continue
62                         fi
63                         ;;
64                 esac
65                 case "$FSTYPE" in
66                   nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs)
67                         DIRS="$MTPT $DIRS"
68                         ;;
69                   proc|procfs|linprocfs|devfs|devpts|usbfs|usbdevfs|sysfs)
70                         DIRS="$MTPT $DIRS"
71                         ;;
72                 esac
73                 case "$OPTS" in
74                   _netdev|*,_netdev|_netdev,*|*,_netdev,*)
75                         DIRS="$MTPT $DIRS"
76                         ;;
77                 esac
78         done
79
80         exec 0<&9 9<&-
81
82         if [ "$DIRS" ]
83         then
84                 [ "$VERBOSE" = no ] || log_action_begin_msg "Unmounting remote and non-toplevel virtual filesystems"
85                 fstab-decode umount $FLAGS $DIRS
86                 ES=$?
87                 [ "$VERBOSE" = no ] || log_action_end_msg $ES
88         fi
89
90         # emit unmounted-remote-filesystems hook point so any upstart jobs
91         # that support remote filesystems can be stopped
92         initctl --quiet emit unmounted-remote-filesystems
93 }
94
95 case "$1" in
96   start)
97         # No-op
98         ;;
99   restart|reload|force-reload)
100         echo "Error: argument '$1' not supported" >&2
101         exit 3
102         ;;
103   stop|"")
104         do_stop
105         ;;
106   *)
107         echo "Usage: umountnfs.sh [start|stop]" >&2
108         exit 3
109         ;;
110 esac
111
112 :