home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
-
- ############################################################
- # DESCRIPTION: A shell script to format floppy disks from
- # the commandline.
- #
- # AUTHOR: Timothy J. Luoma <luomat@capitalist.princeton.edu>
- #
- # DATE: 14 March 1996
- #
- # WARNING: USE ENTIRELY AT YOUR OWN RISK
- #
- # TESTED UNDER: NeXTStep 3.2 on my NeXTStation
- #
- # Notes: MUST RUN AS 'root'
- #
- # Usage: ff [dos|next|mac disklabel ]
- #
- # If first argument is 'help', print a usage message and exit.
- # Otherwise, enter into INTERACTIVE MODE.
- #
- #
- # KNOWN BUGS: NONE! If you find any, let me know. I tested this pretty
- # extensively (especially the interactive mode) but I
- # am sure that you could break it if you really tried.
- # Perhaps the only known bug is that it assumes the
- # user knows what they are doing!
- #
- # Possible bug: I know not all disks can be formatted for MAC, but I
- # don't know how to tell which can and which cannot.
- # I don't know what would happen with this script if
- # you tried to use it for force Mac-format on a disk that
- # can't take it.
- #
- # Remember! This is to format FLOPPY DISKS, the 3.5" kind. I don't
- # have any idea if it will work on ZIP drives or
- # anything like that. If you are interested, watch the
- # console.log next time you format one of those disks
- # and see how the command there compares with what is here.
- # I'd be interested to know, so I can (if possible) update
- # this script to work with them also.
-
- # set the name of this script
- name=`basename $0`
-
- # pop a warning if this isn't 'root'
- if [ `whoami` != "root" ]
- then
- echo "$name will only work properly when run as 'root'"
- fi
-
- # get the hostname, needed for NeXT initialization
- hostname=`/bin/hostname`
-
- # this is the RAW device where NeXT floppies are mounted
- # if you think yours is different, check 'df' with a
- # NeXT-formatted floppy disk mounted
- nfmount=/dev/rfd0a
-
- # this is the RAW device where DOS and Mac floppies are mounted.
- # If you think yours might be different, check 'df' with a
- # DOS or Mac-formatted floppy disk mounted
- altmount=/dev/rfd0b
-
-
- # if there is one argument (like 'help' or something)
- # then give them the usage
- if [ "$1" = "help" ]
- then
- echo "$name: A script to format floppy disks for"
- echo " Can be used in line mode or interative mode"
- echo "Line-mode format is:"
- echo " $name filesystem disklabel"
- echo " where 'filesystem' is one of: NeXT, next, dos, DOS, Mac, mac"
- echo " and 'disklabel' is the name you want the disk to be given"
- echo "$name next disk_one"
- echo " would format a floppy disk for NeXT with the label 'disk_one'"
- echo "$name dos dos_01"
- echo " would format a floppy disk for DOS with the label 'dos_01'"
- echo ""
- echo "If $name is given ONE argument, this screen is printed."
- echo ""
- echo "Any other number of arguments makes $name enter interative mode"
- echo ""
- exit 0
-
- # if there are two arguments, then assume they are the desired
- # filesystem and label, in that order. The user will get a chance
- # to verify this later anyway.
- elif [ $# = "2" ]
- then
- filesystem=$1
- rawlabel=$2
- label=`echo $rawlabel | tr -d '/' | tr -s ' ' '_'`
-
- echo " "
- echo "$name: With those arguments, I assume you want me"
- echo " to use the filesystem $filesystem and the label $label."
- echo " "
- else
-
- # if there are not 1 or 2 arguments, push them into interactive format
- echo -n "$name: FORMAT? Press (n) for NeXT, (m) for Mac, (d) for DOS "
-
- # this will take the very first character they enter
- # WITHOUT requiring them to press RETURN
- stty cbreak
- format=`dd if=/dev/tty bs=1 count=1 2>/dev/null`
- stty -cbreak
-
- echo " "
- case $format in
- m) filesystem=mac ;;
- n) filesystem=NeXT ;;
- d) filesystem=DOS ;;
- *) echo "Unknown format chosen, $name exiting ungracefully" && \
- exit 0
- ;;
- esac
-
- # Ask them what label they want.
- echo -n "Label name? (press enter for label 'untitled') "
- read rawlabel
-
- label=`echo $rawlabel | tr -d '/' | tr -s ' ' '_'`
-
- # if they just hit return, use 'untitled'
- if [ "$label" = "" ]
- then
- label=untitled
- fi
-
- fi # end of if/then for # of arguments
-
- ##############################################################
- # OK, now tell them what we think is what they asked for #
- # NOTE: from this point onward it is the same whether they #
- # used line mode or interactive mode" #
-
- echo " "
- echo "$name: Disk will be formatted for the <$filesystem> filesystem"
- echo "with label <$label>."
- echo " "
-
- # FORCE them to confirm the action with FULL KNOWLEDGE of the damage
- # it will do to their floppy disk (that is, it will erase it
- # NOTE: it also makes them press ENTER, rather than just taking the
- # first character they hit. Safety first!
-
- echo " This will irreparable ERASE ALL DATA currently"
- echo -n " on the disk. Continue? [y/N] "
-
- read verify
-
- # if their answer is not exactly 'y' then quit. No sense
- # taking chances on a process that cannot be undone
- if [ "$verify" != "y" ]
- then
- echo "$name: Did not receive confirmation, exiting"
- exit 0
- fi
-
- # ok, check out their selection for filesystem
- # this is especially important for line mode, in case they got the
- # order of the arguments backwards.
- case $filesystem in
- NeXT|next)
- /usr/etc/disk -i -h "$hostname" -l "$label" $nfmount && \
- echo "$name: Format complete, attempting mount" && \
- mount -o rw,removable /dev/fd0a /"$label" && \
- echo "$name: /$label successfully mounted"
- echo "$name: exiting"
- ;;
-
- DOS|dos)
- /usr/filesystems/DOS.fs/DOS.util -i fd0 "$label" removable && \
- echo "$name: Initialization complete, attempting mount..." && \
- mount -t dos -o rw,removable $altmount /"$label" && \
- echo "$name: /$label successfully mounted"
- echo "$name: exiting."
- ;;
-
- MAC|Mac|mac)
-
- /usr/filesystems/mac.fs/mac.util -i fd0 "$label" removable && \
- echo "$name: Initialization complete, attempting mount..." && \
- mount -t macintosh -o rw,removable $altmount /"$label" && \
- echo "$name: /$label successfully mounted" && \
- touch /$label/Desktop
- echo "$name: exiting."
-
- ;;
-
- # if they didn't choose DOS/dos/NeXT/next then exit
- *)
- echo "name: FATAL ERROR, unknown value for variable 'filesystem'"
- echo "Valid filenames are: NeXT next DOS dos Mac mac"
- echo "You had selected: $filesystem"
- exit 0
- ;;
- esac
-
-
-
-
- exit 0
-