home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Unix / The-Disk-Scripts / ff < prev    next >
Encoding:
Text File  |  1996-03-13  |  6.1 KB  |  207 lines

  1. #!/bin/sh
  2.  
  3. ############################################################
  4. # DESCRIPTION:     A shell script to format floppy disks from
  5. #        the commandline.
  6. #
  7. # AUTHOR:  Timothy J. Luoma <luomat@capitalist.princeton.edu>
  8. #
  9. # DATE:    14 March 1996
  10. #
  11. # WARNING: USE ENTIRELY AT YOUR OWN RISK
  12. #
  13. # TESTED UNDER: NeXTStep 3.2 on my NeXTStation
  14. #
  15. # Notes:    MUST RUN AS 'root'
  16. #
  17. # Usage: ff [dos|next|mac  disklabel ] 
  18. #
  19. # If first argument is 'help', print a usage message and exit.
  20. # Otherwise, enter into INTERACTIVE MODE.
  21. #
  22. #
  23. # KNOWN BUGS: NONE!  If you find any, let me know.  I tested this pretty
  24. #               extensively (especially the interactive mode) but I 
  25. #             am sure that you could break it if you really tried.
  26. #             Perhaps the only known bug is that it assumes the
  27. #             user knows what they are doing!
  28. #
  29. # Possible bug: I know not all disks can be formatted for MAC, but I 
  30. #         don't know how to tell which can and which cannot.
  31. #        I don't know what would happen with this script if
  32. #        you tried to use it for force Mac-format on a disk that
  33. #        can't take it.
  34. #
  35. # Remember!  This is to format FLOPPY DISKS, the 3.5" kind.  I don't
  36. #        have any idea if it will work on ZIP drives or 
  37. #        anything like that.  If you are interested, watch the
  38. #        console.log next time you format one of those disks
  39. #        and see how the command there compares with what is here.
  40. #        I'd be interested to know, so I can (if possible) update
  41. #        this script to work with them also.
  42.  
  43. # set the name of this script
  44. name=`basename $0`
  45.  
  46. # pop a warning if this isn't 'root'
  47. if [ `whoami` != "root" ]
  48. then
  49.     echo "$name will only work properly when run as 'root'"
  50. fi
  51.  
  52. # get the hostname, needed for NeXT initialization
  53. hostname=`/bin/hostname`
  54.  
  55. # this is the RAW device where NeXT floppies are mounted
  56. # if you think yours is different, check 'df' with a
  57. # NeXT-formatted floppy disk mounted
  58. nfmount=/dev/rfd0a
  59.  
  60. # this is the RAW device where DOS and Mac floppies are mounted.
  61. # If you think yours might be different, check 'df' with a
  62. # DOS or Mac-formatted floppy disk mounted
  63. altmount=/dev/rfd0b
  64.  
  65.  
  66. # if there is one argument (like 'help' or something)
  67. # then give them the usage
  68. if [ "$1" = "help" ]
  69. then
  70.     echo "$name: A script to format floppy disks for"
  71.     echo "    Can be used in line mode or interative mode"
  72.     echo "Line-mode format is:"
  73.     echo "    $name filesystem disklabel"
  74.     echo "    where 'filesystem' is one of: NeXT, next, dos, DOS, Mac, mac"
  75.     echo "    and 'disklabel' is the name you want the disk to be given"
  76.     echo "$name next disk_one"
  77.     echo "    would format a floppy disk for NeXT with the label 'disk_one'"
  78.     echo "$name dos dos_01"
  79.     echo "    would format a floppy disk for DOS with the label 'dos_01'"
  80.     echo ""
  81.     echo "If $name is given ONE argument, this screen is printed."
  82.     echo ""
  83.     echo "Any other number of arguments makes $name enter interative mode"
  84.     echo ""
  85.     exit 0
  86.  
  87. # if there are two arguments, then assume they are the desired
  88. # filesystem and label, in that order.  The user will get a chance
  89. # to verify this later anyway.
  90. elif [ $# = "2" ]
  91. then
  92.     filesystem=$1
  93.     rawlabel=$2
  94.     label=`echo $rawlabel | tr -d '/' | tr -s ' ' '_'`
  95.  
  96.     echo " "
  97.     echo "$name: With those arguments, I assume you want me"
  98.     echo "    to use the filesystem $filesystem and the label $label."    
  99.     echo " "
  100. else
  101.  
  102. # if there are not 1 or 2 arguments, push them into interactive format
  103. echo -n "$name: FORMAT? Press (n) for NeXT, (m) for Mac, (d) for DOS " 
  104.  
  105. # this will take the very first character they enter
  106. # WITHOUT requiring them to press RETURN
  107. stty cbreak
  108. format=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
  109. stty -cbreak
  110.  
  111. echo " "
  112. case $format in
  113.     m) filesystem=mac ;;
  114.     n) filesystem=NeXT ;;
  115.     d) filesystem=DOS ;;
  116.     *) echo "Unknown format chosen, $name exiting ungracefully" && \ 
  117.            exit 0 
  118.        ;;
  119. esac
  120.  
  121. # Ask them what label they want. 
  122. echo -n "Label name? (press enter for label 'untitled') "
  123. read rawlabel
  124.  
  125. label=`echo $rawlabel | tr -d '/' | tr -s ' ' '_'`
  126.  
  127. # if they just hit return, use 'untitled'
  128. if [ "$label" = "" ]
  129. then
  130.     label=untitled
  131. fi
  132.  
  133. fi    # end of if/then for # of arguments
  134.  
  135. ##############################################################
  136. # OK, now tell them what we think is what they asked for     #
  137. # NOTE: from this point onward it is the same whether they   #
  138. # used line mode or interactive mode"                        #
  139.  
  140. echo " "
  141. echo "$name: Disk will be formatted for the <$filesystem> filesystem"
  142. echo "with label <$label>."
  143. echo " "
  144.  
  145. # FORCE them to confirm the action with FULL KNOWLEDGE of the damage
  146. # it will do to their floppy disk (that is, it will erase it
  147. # NOTE: it also makes them press ENTER, rather than just taking the
  148. # first character they hit.  Safety first!
  149.  
  150. echo    "    This will irreparable ERASE ALL DATA currently"
  151. echo -n "    on the disk.  Continue? [y/N] "
  152.  
  153. read verify
  154.  
  155. # if their answer is not exactly 'y' then quit.  No sense 
  156. # taking chances on a process that cannot be undone
  157. if [ "$verify" != "y" ]
  158. then
  159.         echo "$name: Did not receive confirmation, exiting"
  160.         exit 0
  161. fi
  162.  
  163. # ok, check out their selection for filesystem
  164. # this is especially important for line mode, in case they got the
  165. # order of the arguments backwards.
  166. case $filesystem in
  167.     NeXT|next)
  168.     /usr/etc/disk -i -h "$hostname" -l "$label"  $nfmount && \
  169.     echo "$name: Format complete, attempting mount" && \
  170.     mount -o rw,removable /dev/fd0a /"$label" && \
  171.     echo "$name: /$label successfully mounted"
  172.     echo "$name: exiting"
  173.     ;;
  174.  
  175.     DOS|dos)
  176.     /usr/filesystems/DOS.fs/DOS.util -i fd0 "$label" removable && \
  177.     echo "$name: Initialization complete, attempting mount..." && \
  178.     mount -t dos -o rw,removable $altmount /"$label" && \
  179.     echo "$name: /$label successfully mounted"
  180.     echo "$name: exiting."
  181.     ;;
  182.  
  183.     MAC|Mac|mac)
  184.     
  185.     /usr/filesystems/mac.fs/mac.util -i fd0 "$label" removable && \
  186.     echo "$name: Initialization complete, attempting mount..." && \
  187.     mount -t macintosh -o rw,removable $altmount /"$label" && \
  188.     echo "$name: /$label successfully mounted" && \
  189.     touch /$label/Desktop
  190.     echo "$name: exiting."
  191.  
  192.     ;;
  193.  
  194. # if they didn't choose DOS/dos/NeXT/next then exit
  195.     *)
  196.     echo "name: FATAL ERROR, unknown value for variable 'filesystem'"
  197.     echo "Valid filenames are: NeXT next DOS dos Mac mac"
  198.     echo "You had selected: $filesystem"
  199.     exit 0
  200.     ;;
  201. esac
  202.  
  203.  
  204.  
  205.  
  206. exit 0
  207.