# # This shell script will "fill" a floppy with files from # another floppy until the destination floppy is full. # then it will ask for a second destination floppy and # continue to fill that floppy until it is full as well. # This process will continue until the all the file have been copied to # the destination floppies or the user asks to quit the procedure # # # functions used in this script : # function gettxt { read text?"Please enter the $* " echo $text ; } typeset -xf gettxt function getyesno { noans=t while [ $noans = t ] ; do read text?"$* ( Must use y for yes, n for no )" if [ "x$text" = xy ] ; then echo y noans=f elif [ "x$text" = xn ] ; then echo n noans=f fi done ; } typeset -xf getyesno function verifytxt { desc=$1 name=$2 read ans?" $desc : $name Corrections ? ( enter for none ) >> " if [ "x$ans" != x ] ; then ans=`verifytxt "$desc" "$ans"` echo $ans else echo $name fi ; } typeset -xf verifytxt if [ "x$DEBUG" = "xT" ] ; then set -vx fi # # Begin main section of script # # # get the name of the source directory/floppy read src?"Fill FROM what floppy drive/directory ? " src=`verifytxt "Verify: Fill FROM what floppy drive/directory ? " $src` echo "\n\n" # # get the name of the destination directory/floppy read target?"Fill TO what floppy drive ? " target=`verifytxt "Verify: Fill TO what floppy drive ? " $target` echo "\n\n" # # get the size of the destination directory/floppy read ans?"What is the size of the floppy drive ( 1440 kbytes is default)" ans=`verifytxt "Verify: size of the floppy drive " $ans` if [ "x$ans" = x ] ; then ans=1440000 fi typeset -i size=$ans if [ $size -le 0 ] ; then size=1440000 fi print "size is $size" # # get the list and sizes of file from the source # typeset -i total=`ls -l $src | egrep -v '^d' | egrep -v "total [0-9][0-9]" | awk '{sum=sum+$5} END{print sum}'` print "the total space needed is $total." typeset -i howmanydisks=0 typeset -i sum=0 typeset -i position=0 typeset -i rem=0 typeset -i i=0 typeset -i newroomleft=0 typeset -i roomleft=$size (( howmanydisks= $total / $size )) (( rem= $howmanydisks * $size )) if [ ! $rem -eq $total ] ; then (( howmanydisks= $howmanydisks + 1 )) fi print "$howmanydisks disks will be needed." roomleft=$size for file in `ls $src` ; do if [ ! -d $file ] ; then print "preparing to add file $file." fsize=`ls -l $file | awk '{print $5}'` if [ $fsize -lt $size ] ; then (( newroomleft= $roomleft - $fsize )) echo There is $roomleft space left on the current disk echo File $file needs $fsize space. echo there will be $newroomleft after copying $file to the current disk if [ $newroomleft -lt 1 ] ; then read ans?"Not enough room on this disk, place next disk in drive and press enter." echo setting space left on new disk (( roomleft= $size - $fsize )) else echo setting space left on current disk (( roomleft= $roomleft - $fsize )) fi echo cp $file ${target}/. cp $file ${target}/. else echo "Skipping $file becasuse it is too large to fit on a floppy" fi else echo "Skipping $file because it is a directory." fi done