home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / base / root.15 / sbin / umountall / umountall~
Text File  |  1998-08-19  |  3KB  |  153 lines

  1. #!/sbin/sh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11. #ident    "@(#)initpkg:common/cmd/initpkg/umountall.sh    1.4.20.1"
  12.  
  13. if [ -z "$LC_ALL" -a -z "$LC_MESSAGES" ]
  14. then
  15.     if [ -z "$LANG" ]
  16.     then
  17.         LNG=`defadm locale LANG 2>/dev/null`
  18.         if [ "$?" != 0 ]
  19.         then LANG=C
  20.         else eval $LNG
  21.         fi
  22.     fi
  23.     LC_MESSAGES=/etc/inst/locale/$LANG
  24.     export LANG LC_MESSAGES
  25. fi
  26. LABEL="UX:$0"
  27.  
  28. CAT=uxrc; export CAT
  29.  
  30. usage()
  31. {
  32. FARG=`gettxt $CAT:57 "FSType"`
  33. USAGE="umountall [-F $FARG] [-k] [-l|-r] "
  34. pfmt -l $LABEL -s action -g $CAT:4 "Usage: %s\n" "$USAGE"
  35. exit 2
  36. }
  37. FSTAB=/etc/vfstab
  38. FSType=
  39. kill=
  40. FCNT=0
  41. CNT=0
  42.  
  43. while getopts ?rlkF: c
  44. do
  45.     case $c in
  46.     r)    RFLAG="r" export RFLAG; CNT=`/usr/bin/expr $CNT + 1`;;
  47.     l)    LFLAG="l" export LFLAG; CNT=`/usr/bin/expr $CNT + 1`;;
  48.     k)     kill="yes" export kill;;
  49.     F)    FSType=$OPTARG export FSType
  50.         case $FSType in
  51.         ?????????*) 
  52.             pfmt -l $LABEL -s error -u $CAT:60 "FSType %s exceeds 8 characters\n" $FSType
  53.             exit 2
  54.         esac;
  55.         FCNT=`/usr/bin/expr $FCNT + 1`;;
  56.     \?)    usage
  57.         ;;
  58.     esac
  59. done
  60. shift `/usr/bin/expr $OPTIND - 1`
  61. if test $FCNT -gt 1
  62. then
  63.     pfmt -l $LABEL -s error -g $CAT:59 "more than one FSType specified\n"
  64.     exit 2
  65. fi
  66. if test $CNT -gt 1
  67. then
  68.     pfmt -l $LABEL -s error -g $CAT:61 "options -r and -l incompatible\n"
  69.     usage
  70. fi
  71. if test $# -gt 0
  72. then
  73.     pfmt -l $LABEL -s error -g $CAT:80 "arguments not supported\n"
  74.     usage
  75. fi
  76. if test \( "$FSType" = "rfs" -o "$FSType" = "nfs" -o "$FSType" = "nucfs" \) -a "$LFLAG" = "l"
  77. then
  78.     pfmt -l $LABEL -s error -g $CAT:64 "option -l and FSType are incompatible\n"
  79.     usage
  80. fi
  81. if test \( "$FSType" = "vxfs" -o "$FSType" = "s5" -o "$FSType" = "ufs" -o "$FSType" = "bfs" -o "$FSType" = "sfs" \) -a "$RFLAG" = "r"
  82. then
  83.     pfmt -l $LABEL -s error -g $CAT:65 "option -r and FSType are incompatible\n"
  84.     usage
  85. fi
  86.  
  87. # Undo mounts in reverse order.
  88. awk '{ line[i++] = $0; } END { while (i > 0) print line[--i]; }' </etc/mnttab |
  89.  
  90. (
  91.     PENDING_UMOUNT=
  92.  
  93.     # Make sure that /usr is umounted last, because we need /usr/bin/fuser.
  94.     USRDEV=
  95.     USRTYPE=
  96.  
  97.     umount_one()
  98.     {
  99.         if [ -n "$FSType" -a "$FSType" != $1 ]
  100.         then
  101.             return
  102.         fi
  103.         if [ "$LFLAG" = "l" -a \
  104.              \( $1 = "rfs" -o $1 = "nfs" -o $1 = "nucfs" \) ]
  105.         then
  106.             return
  107.         fi
  108.         if [ "$RFLAG" = "r" -a $1 != "rfs" -a $1 != "nfs" -a \
  109.              $1 != "nucfs" ]
  110.         then
  111.             return
  112.         fi
  113.         if [ ${kill} ]
  114.         then
  115.             /usr/sbin/fuser -k $2 >/dev/null 2>&1
  116.             PENDING_UMOUNT="${PENDING_UMOUNT} $2"
  117.         else
  118.             /sbin/umount $2
  119.         fi
  120.     }
  121.  
  122.     while read dev mountp fstype rest
  123.     do
  124.         case "${mountp}" in
  125.         /usr )
  126.             USRDEV=$dev
  127.             USRTYPE=$fstype
  128.             ;;
  129.         /  | /stand | /proc | /dev/fd | '' )
  130.             continue
  131.             ;;
  132.         * )
  133.             umount_one $fstype $dev
  134.             ;;    
  135.         esac
  136.     done
  137.  
  138.     if [ -n "$USRDEV" ]
  139.     then
  140.         umount_one $USRTYPE $USRDEV
  141.     fi
  142.  
  143.     if [ "${PENDING_UMOUNT}" != "" ]
  144.     then
  145.         # allow time for kills to finish from /usr/sbin/fuser
  146.         sleep 10
  147.         for dev in ${PENDING_UMOUNT}
  148.         do
  149.             /sbin/umount ${dev}
  150.         done
  151.     fi
  152. )
  153.