: ########################################################################## # Shellscript: diskcopy - duplicate a 3.5" floppy disk # Version : 0.2 (beta) # Author : Heiner Steven (heiner.steven@odn.de) # Date : 03.06.95 # Category : System Administration # SCCS-Id. : $Id: diskcopy,v 1.1.1.1 1999/06/15 19:29:05 heiner Exp $ ########################################################################## # Description # ########################################################################## PN=`basename $0` # program name VER='0.1 (beta)' : ${FLOPPY:=/dev/rfd0} : ${EJECT:=eject} DiskBS=18k FileBS=18k Tmp=${TMPDIR:=/tmp}/dc$$ Usage () { echo "$PN - duplicate 3.5\" floppy disks, $VER (hs '95) usage: $PN source target The default source device is FLOPPY=$FLOPPY. If no target device is specified, a temporary file is used. If a target device is given, a two-drive-copy is assumed." >&2 exit 1 } Msg () { for i do echo "$i" >&2 done } Fatal () { Msg "$@"; exit 1; } GetYN () { while : do Msg "" "$@" read answer || exit 2 case "$answer" in [yYjJ]*) return 0;; [nN]*) return 1;; [qQ]*) exit 0; esac Msg "" "Enter 'y' for yes or 'n' for no" "Please try again" done } EjectFloppy () { $EJECT || EJECT=; } Out="$Tmp" while [ $# -gt 0 ] do case "$1" in --) shift; break;; -h) Usage;; -*) Usage;; *) break;; # First file name esac shift done if [ $# -gt 2 ] then Usage elif [ $# -ge 2 ] then Out="$2" elif [ $# -ge 1 ] then FLOPPY="$1" fi [ "$FLOPPY" = "$Out" ] && Fatal "cannot read and write to the same device" trap "rm -f $Tmp > /dev/null 2>&1" 0 trap "exit 2" 1 2 3 15 n=1 while GetYN "Copy Disk $n (y/n, q)? \c" do Msg "Reading Disk $n..." if dd if=$FLOPPY of=$Out ibs=$DiskBS obs=$FileBS then EjectFloppy if [ "$Out" = "$Tmp" ] then Copy=1 while GetYN "WRITE new Copy $Copy (y/n, q)? \c" do Msg "Writing copy $Copy..." if dd if=$Out ibs=$FileBS of=$FLOPPY obs=$DiskBS then Msg "Copy $Copy successfully written." Copy=`expr ${Copy:-1} + 1` else Msg "" "Could not write to floppy disk!" \ "Please check the disk drive, and try again" fi EjectFloppy done fi else Msg "" "Cannot read floppy disk!" \ "Please check the disk drive, and try again" EjectFloppy continue fi n=`expr ${n:-1} + 1` done