home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 5.ddi / sbin / mountall < prev    next >
Encoding:
Text File  |  1990-12-08  |  4.0 KB  |  205 lines

  1. #!/sbin/sh
  2. #    Copyright (c) 1990 UNIX System Laboratories, Inc.
  3. #    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T
  4. #      All Rights Reserved
  5.  
  6. #    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF
  7. #    UNIX System Laboratories, Inc.
  8. #    The copyright notice above does not evidence any
  9. #    actual or intended publication of such source code.
  10.  
  11.  
  12.  
  13. #!/sbin/sh
  14. #ident    "@(#)/sbin/mountall.sl 1.1 4.0 12/08/90 28683 AT&T-USL"
  15. USAGE="Usage:\nmountall [-F FSType] [-l|-r] [file_system_table]"
  16. TYPES="all"
  17. while getopts ?rlF: c
  18. do
  19.     case $c in
  20.     r)    RFLAG="r";;
  21.     l)    LFLAG="l";;
  22.     F)    FSType=$OPTARG;
  23.         if [ "$TYPES" = "one" ]
  24.         then
  25.             echo "mountall: more than one FSType specified"
  26.             exit 2
  27.         else
  28.             TYPES="one"
  29.         fi;
  30.         case $FSType in
  31.         ?????????*) 
  32.             echo "mountall: FSType $FSType exceeds 8 characters"
  33.             exit 2
  34.         esac
  35.         ;;
  36.     \?)    echo "$USAGE" 1>&2; exit 2;;
  37.     esac
  38. done
  39. oi=0
  40. for i in 0 1 2 3 4 5 6 7 8 9
  41. do
  42.     if [ $i = $OPTIND ]
  43.     then
  44.         OPTIND=$oi
  45.         break
  46.     fi
  47.     oj=0
  48.     for j in 0 1 2 3 4 5 6 7 8 9
  49.     do
  50.         if [ $i$j = $OPTIND ]
  51.         then
  52.             if [ $j = 0 ]
  53.             then
  54.                 OPTIND=${oi}9
  55.             else
  56.                 OPTIND=$i$oj
  57.             fi
  58.             break 2
  59.         fi
  60.         oj=$j
  61.     done
  62.     oi=$i
  63. done
  64. shift $OPTIND
  65. if [ "$RFLAG" = "r" -a "$LFLAG" = "l" ]
  66. then
  67.     echo "mountall: options -r and -l incompatible" 1>&2
  68.     echo "$USAGE" 1>&2
  69.     exit 2
  70. fi
  71. if [ $# -gt 1 ]
  72. then
  73.     echo "mountall: multiple arguments not supported" 1>&2
  74.     echo "$USAGE" 1>&2
  75.     exit 2
  76. fi
  77.  
  78. # get file system table name and make sure file exists
  79. case $1 in
  80.     "-")    FSTAB=""
  81.         ;;
  82.     "")    FSTAB=/etc/vfstab
  83.         ;;
  84.     *)    FSTAB=$1
  85.         ;;
  86. esac
  87. if [ "$FSTAB" != ""  -a  ! -s "$FSTAB" ]
  88. then
  89.     echo "mountall: file system table ($FSTAB) not found"
  90.     exit 1
  91. fi
  92.  
  93. if [ \( "$FSType" = "rfs" -o "$FSType" = "nfs" \) -a "$LFLAG" = "l" ]
  94. then
  95.     echo "mountall: option -l and FSType are incompatible" 1>&2
  96.     echo "$USAGE" 1>&2
  97.     exit 2
  98. fi
  99. if [ \( "$FSType" = "s5" -o "$FSType" = "ufs" -o "$FSType" = "bfs" \) -a "$RFLAG" = "r" ]
  100. then
  101.     echo "mountall: option -r and FSType are incompatible" 1>&2
  102.     echo "$USAGE" 1>&2
  103.     exit 2
  104. fi
  105.  
  106. #    file-system-table format:
  107. #
  108. #    column 1:    special- block special device or resource name
  109. #    column 2:     fsckdev- char special device for fsck 
  110. #    column 3:    mountp- mount point
  111. #    column 4:    fstype- File system type
  112. #    column 5:    fsckpass- number if to be checked automatically
  113. #    column 6:    automnt-    yes/no for automatic mount
  114. #    column 7:    mntopts- -o specific mount options
  115.  
  116. #    White-space separates columns.
  117. #    Lines beginning with \"#\" are comments.  Empty lines are ignored.
  118. #    a '-' in any field is a no-op.
  119.  
  120.     exec < $FSTAB
  121.     while  read special fsckdev mountp fstype fsckpass automnt mntopts 
  122.     do
  123.         case $special in
  124.         '#'* | '')    #  Ignore comments, empty lines
  125.                 continue ;;
  126.         '-')        #  Ignore no-action lines
  127.                 continue
  128.         esac 
  129.  
  130.         if i386
  131.         then
  132.             if [ "$special" = "/dev/root" ]
  133.             then continue
  134.             fi
  135.         fi
  136.         
  137.         if  [ "$FSType" ]
  138.         then            # ignore different fstypes
  139.             if [ "$FSType" != "$fstype" ]
  140.             then
  141.                 continue
  142.             fi
  143.         fi
  144.  
  145.         if [ "$LFLAG" ]
  146.         then
  147.             if [ "$fstype" = "rfs"  -o  "$fstype" = "nfs" ]
  148.             then
  149.                 continue
  150.             fi
  151.         fi
  152.         if [ "$RFLAG" ]
  153.         then
  154.             if [ "$fstype" != "rfs" -a  "$fstype" != "nfs" ]
  155.             then
  156.                 continue
  157.             fi
  158.         fi
  159.         if [ "$automnt" != "yes" ]
  160.         then
  161.             continue
  162.         fi
  163.         if [ "$fstype" = "-" ]
  164.         then
  165.             echo "mountall: FSType of $special cannot be identified" 1>&2
  166.             continue
  167.         fi
  168.         #     Use mount options if any
  169.         if  [ "$mntopts" != "-" ]
  170.         then
  171.             OPTIONS="-o $mntopts"
  172.         else
  173.             OPTIONS=""
  174.         fi
  175.  
  176.         #    First check file system state and repair if necessary.
  177.  
  178.         if [ "$fsckdev" = "-" ]
  179.         then
  180.             /sbin/mount "-F" $fstype $OPTIONS $special $mountp
  181.             continue
  182.         fi
  183.  
  184.         msg=`/sbin/fsck "-m" "-F" $fstype $special 2>&1`
  185.         case $? in
  186.         0)    /sbin/mount "-F" $fstype $OPTIONS $special $mountp
  187.             ;;
  188.  
  189.         32)    echo "$msg\n\t $fsckdev is being checked" 1>&2
  190.             if [ "$fstype" != "s5" ]
  191.             then
  192.                 /sbin/fsck "-F" $fstype -y $fsckdev
  193.             else 
  194.                 /sbin/fsck "-F" $fstype -y -t /var/tmp/tmp$$ -D $fsckdev
  195.             fi
  196.             /sbin/mount "-F" $fstype $OPTIONS $special $mountp
  197.             ;;
  198.  
  199.         33)    # already mounted
  200.             #echo "$special already mounted"
  201.             ;;
  202.         esac
  203.  
  204.     done
  205.