home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / 3b2 / optparttn < prev    next >
Text File  |  1985-07-02  |  5KB  |  232 lines

  1. #
  2. # optparttn
  3. #
  4. # Allocate any disk free space into user partitions.
  5. #
  6.  
  7. set -ue
  8. myname=${0}
  9. args="${*:-}"
  10.  
  11. dir=/usr
  12. seq=2
  13.  
  14. p_0=0    p_1=1    p_2=2    p_3=3    p_4=4    p_5=5    p_6=6    p_7=7
  15. p_8=8    p_9=9    p_a=10    p_b=11    p_c=12    p_d=13    p_e=14    p_f=15
  16.  
  17. cylsize=1
  18. drive=
  19. rel=unk
  20. root=/
  21. SAflag=n
  22.  
  23. fstab=
  24. mountdir=
  25.  
  26. Again()
  27. {
  28.     Undo $*
  29.     exec ${myname} ${args}
  30. }
  31.  
  32. Cleanup()
  33. {
  34.     Undo $*
  35.     exit 1
  36. }
  37.  
  38. Undo()
  39. {
  40.     level=0
  41.     while [ $# -ge 2 ]
  42.     do
  43.         eval dev_${level}=\${1} dir_${level}=\${2}
  44.         level=`ignore expr ${level} + 1`
  45.         shift 2
  46.     done
  47.     while [ ${level} -ne 0 ]
  48.     do
  49.         level=`ignore expr ${level} - 1`
  50.         eval dev=\${dev_${level}} dir=\${dir_${level}}
  51.         unmnt ${dev}
  52.         part=`ignore expr ${dev} : '.*\(.\)$'`
  53.         eval partno=\${p_${part}}
  54.         eval fmthard -d ${partno}:0:1:0:0 ${devraw}${part} > /dev/null
  55.         rrmdir -r ${root} ${dir}
  56.     done
  57. }
  58.  
  59. while [ $# -ne 0 ]
  60. do
  61.     case "${1}" in
  62.     -c)
  63.         cylsize="${2}" ; shift 2 ;;
  64.     -d)
  65.         drive="${2}" ; shift 2 ;;
  66.     -g)
  67.         rel="${2}" ; shift 2 ;;
  68.     -r)
  69.         root="${2}" ; shift 2 ;;
  70.     -S)
  71.         SAflag=y ; shift 1 ;;
  72.     -*)
  73.         echo "${myname}: \"${2}\": Unknown option" >&2 ; exit 1 ;;
  74.     *)
  75.         break ;;
  76.     esac
  77. done
  78.  
  79. if [ $# -ne 1 ]
  80. then
  81.     echo "\
  82. Usage:    ${myname} [ -c cylsize ] [ -d drivename ] [ -g release ]
  83.     [ -r rootdir ] devprefix" >&2
  84.     exit 1
  85. fi
  86.  
  87. if expr ${1} : /dev/r > /dev/null
  88. then
  89.     devraw=${1}
  90.     devblk=/dev/`ignore expr ${1} : '/dev/r\(.*\)'`
  91. else
  92.     echo "${myname}: ${1}: Device name must begin with \"/dev/r\"" >&2
  93.     exit 1
  94. fi
  95.  
  96. if [ ${SAflag} = y ]
  97. then
  98.     mnt()    { /etc/mount ${1} ${2} && chmod 775 ${2} ; }
  99.     unmnt()    { /etc/umount ${1} ; }
  100. else
  101.     mnt()    { fsys -m ${2} -c 775 ${1} ; }
  102.     unmnt()    { fsys -u ${1} ; }
  103. fi
  104.  
  105. while true
  106. do
  107.     #
  108.     # "prtvtoc -f" prints several shell variable assignments:
  109.     #    FREE_PART    Concanentaion of free partition names (0-f)
  110.     #    FREE_START    Initial block of first chunk of free space
  111.     #    FREE_SIZE    Size of first chunk of free space
  112.     #    FREE_COUNT    Number of chunks of free space
  113.     #
  114.     eval `prtvtoc -f ${devraw}6`
  115.     if [ ${FREE_COUNT} -eq 0 ]
  116.     then
  117.         break
  118.     fi
  119.     echo "
  120. There are ${FREE_SIZE} blocks remaining${drive:+ on disk ${drive}}." >&2
  121.     FREE_PART=`ignore expr "${FREE_PART}" : '[0-7]*\(.*\)'`
  122.     while [ ${FREE_SIZE} -ne 0 ]
  123.     do
  124.         use_part=`ignore expr "${FREE_PART}" : '\(.\)'`
  125.         eval use_partno=\${p_${use_part}}
  126.         use_have=`ignore expr "${FREE_PART}" : '.*'`
  127.         case ${use_have} in
  128.         0)
  129.             echo "${myname}: ${devraw}?: Out of partitions!" >&2
  130.             exit 1
  131.             ;;
  132.         ${FREE_COUNT})
  133.             echo "
  134. Allocating ${FREE_SIZE} blocks to${drive:+ disk ${drive}} partition ${use_partno}." >&2
  135.             use_size=${FREE_SIZE}
  136.             ;;
  137.         *)
  138.             use_size=`askx -s -q "\
  139. How many blocks for${drive:+ disk ${drive}} partition ${use_partno}?" \
  140.                 -h "\
  141. There are ${FREE_SIZE} blocks remaining${drive:+ on disk ${drive}}. \
  142. They may be distributed amongst
  143. one or more of the ${use_have} remaining partitions. Enter the \
  144. number of blocks to be
  145. allocated to partition ${use_partno}, \"again\" to reallocate the \
  146. optional partitions
  147. ${drive:+on disk ${drive} }or \"quit\" to quit." \
  148.                 -c again -c quit -n 0:${FREE_SIZE} -d ${FREE_SIZE}`
  149.             if [ "${use_size}" = again ]
  150.             then
  151.                 Again ${fstab}
  152.             elif [ "${use_size}" = quit ]
  153.             then
  154.                 if [ -n "${fstab}" ]
  155.                 then
  156.                     Cleanup ${fstab}
  157.                 else
  158.                     exit 1
  159.                 fi
  160.             fi
  161.             use_size=`ignore expr \( ${use_size} + ${cylsize} - 1 \) / ${cylsize} \* ${cylsize}`
  162.             if [ ${use_size} -gt ${FREE_SIZE} ]
  163.             then
  164.                 use_size=${FREE_SIZE}
  165.             fi
  166.             ;;
  167.         esac
  168.         FREE_PART=`ignore expr "${FREE_PART}" : '.\(.*\)'`
  169.         if [ ${use_size} -eq 0 ]
  170.         then
  171.             continue
  172.         fi
  173.         while true
  174.         do
  175.             while [ -r ${root}/${dir}${seq} ]
  176.             do
  177.                 seq=`ignore expr ${seq} + 1`
  178.             done
  179.             use_dir=`askx -q "\
  180. Upon what directory should the file system within ${drive:+ disk ${drive}} partition ${use_partno} 
  181. be mounted?" \
  182.                 -h "\
  183. Enter the absolute directory name upon which this ${use_size}-block file system
  184. should be mounted. If you just hit <RETURN>, the file system will be mounted
  185. as \"${dir}${seq}\". See the \"3B2 System Owner/Operator Manual\" for more
  186. information about directory and file names.
  187.  
  188. You may also enter \"again\" to reallocate the optional partitions
  189. ${drive:+on disk ${drive} }or \"quit\" to quit." \
  190.                 -c again -c quit -p -d ${dir}${seq}`
  191.             if [ "${use_dir}" = again ]
  192.             then
  193.                 Again ${fstab}
  194.             elif [ "${use_dir}" = quit ]
  195.             then
  196.                 if [ -n "${fstab}" ]
  197.                 then
  198.                     Cleanup ${fstab}
  199.                 else
  200.                     exit 1
  201.                 fi
  202.             elif [ ! -r ${root}${use_dir} ]
  203.             then
  204.                 if (umask 022 ; exec rmkdir ${root}${use_dir})
  205.                 then
  206.                     break
  207.                 fi
  208.             fi
  209.             echo "
  210. ${use_dir} already exists; please choose a new directory name." >&2
  211.         done
  212.         fmthard -d ${use_partno}:0:0:${FREE_START}:${use_size} ${devraw}${use_part} > /dev/null
  213.         FREE_START=`ignore expr ${FREE_START} + ${use_size}`
  214.         FREE_SIZE=`ignore expr ${FREE_SIZE} - ${use_size}`
  215.         vmkfs ${devraw}${use_part} > /dev/null
  216.         labelit ${devraw}${use_part} `ignore expr ${use_dir} : '.*/\(.*\)$' \| ${use_dir}` ${rel} > /dev/null
  217.         mountdir=`ignore expr "${root}${use_dir}" : "/*\(/.*\)"`
  218.         mnt ${devblk}${use_part} ${mountdir}
  219.         mklost+found ${root}/${use_dir} ${devblk}${use_part}
  220.         fstab="${fstab} ${devblk}${use_part} ${use_dir}"
  221.     done
  222. done
  223. if [ -n "${fstab}" ]
  224. then
  225.     set -- ${fstab}
  226.     while [ $# -ne 0 ]
  227.     do
  228.         echo "${1}\t${2}"
  229.         shift 2
  230.     done
  231. fi
  232.