/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. PATH=/sbin:/usr/sbin:/bin:/usr/bin
  15. KERNEL="$(uname -s)"
  16. RELEASE="$(uname -r)"
  17. . /lib/init/vars.sh
  18. . /lib/lsb/init-functions
  19. case "${KERNEL}:${RELEASE}" in
  20. Linux:[01].*|Linux:2.[01].*)
  21. FLAGS=""
  22. ;;
  23. Linux:2.[23].*|Linux:2.4.?|Linux:2.4.?-*|Linux:2.4.10|Linux:2.4.10-*)
  24. FLAGS="-f"
  25. ;;
  26. *)
  27. FLAGS="-f -l"
  28. ;;
  29. esac
  30. do_stop () {
  31. # Write a reboot record to /var/log/wtmp before unmounting
  32. halt -w
  33. # Remove bootclean flag files (precaution against symlink attacks)
  34. rm -f /tmp/.clean /var/lock/.clean /var/run/.clean
  35. #
  36. # Make list of points to unmount in reverse order of their creation
  37. #
  38. exec 9<&0 </etc/mtab
  39. DIRS=""
  40. while read -r DEV MTPT FSTYPE OPTS REST
  41. do
  42. case "$MTPT" in
  43. /|/proc|/dev|/dev/pts|/dev/shm|/proc/*|/sys|/lib/init/rw)
  44. continue
  45. ;;
  46. /var/run)
  47. continue
  48. ;;
  49. /var/lock)
  50. continue
  51. ;;
  52. esac
  53. case "$FSTYPE" in
  54. nfs|nfs4|smbfs|ncp|ncpfs|cifs|coda|ocfs2|gfs)
  55. DIRS="$MTPT $DIRS"
  56. ;;
  57. proc|procfs|linprocfs|devfs|devpts|usbfs|usbdevfs|sysfs)
  58. DIRS="$MTPT $DIRS"
  59. ;;
  60. esac
  61. case "$OPTS" in
  62. _netdev|*,_netdev|_netdev,*|*,_netdev,*)
  63. DIRS="$MTPT $DIRS"
  64. ;;
  65. esac
  66. done
  67. exec 0<&9 9<&-
  68. if [ "$DIRS" ]
  69. then
  70. [ "$VERBOSE" = no ] || log_action_begin_msg "Unmounting remote and non-toplevel virtual filesystems"
  71. fstab-decode umount $FLAGS $DIRS
  72. ES=$?
  73. [ "$VERBOSE" = no ] || log_action_end_msg $ES
  74. fi
  75. }
  76. case "$1" in
  77. start)
  78. # No-op
  79. ;;
  80. restart|reload|force-reload)
  81. echo "Error: argument '$1' not supported" >&2
  82. exit 3
  83. ;;
  84. stop|"")
  85. do_stop
  86. ;;
  87. *)
  88. echo "Usage: umountnfs.sh [start|stop]" >&2
  89. exit 3
  90. ;;
  91. esac
  92. :