#!/bin/sh # to split a large file into parts # Bill Bynum, December 1995 sysbin=/usr/local/bin:/usr/local/gnu/bin:/bin:/usr/bin:/usr/lib otherbin=$HOME/bin:/home/f85/bynum/bin PATH=$sysbin:$otherbin:. # The space available on a 1440K floppy after "mformat a:" is # 1457764 bytes = 1423K. The combined sizes of the two scripts # is around 3K, more or less, depending on the number of pieces # of the file being saved. If bsize=1418k, then there should be # around 2K free on the fullest disks. bsize=1418k case $1 in "") echo The prefix of the filename of the file to be split is required echo "usage: "`basename $0`" [ -b binary_size -p new_prefix ] file_prefix" echo " splits a file into $bsize byte pieces, then constructs two scripts," echo " a save script and a restore script. The save script guides you through" echo " the sequence of disk insertions to save the pieces of the file to floppies." echo " The restore script guides you through the sequence of disk insertions" echo " to copy the pieces of the file from floppies to hard disk, and then" echo " reconstitutes the file. The save script is named file_prefix.sav and" echo " the restore script is named file_prefix.rst. Both scripts are copied to" echo " each floppy." echo "" echo " 'binary_size' is the max size of each disk. default: $bsize" echo " 'new_prefix' is the prefix to use in creating the storage files" echo " 'file_prefix' is the root of the filename of the file to be split" echo " for the file 'goo.tar.gz', file_prefix is 'goo'" echo " If the suffix of the file is neither '.tgz' nor '.tar.gz'," echo " then you will be prompted for the file suffix." exit;; esac while true do case $1 in -p) shift prefix=$1 shift;; -b) shift bsize=$1 shift;; *) case $prefix in "") prefix=$1;; esac break;; esac done if (test ! -f $1.tgz) then if (test ! -f $1.tar.gz) then echo -n "Enter file suffix (no period): " read suffix if (test ! -f $1.$suffix) then echo "The file \"$1.$suffix\" does not exist!" exit fi else suffix=tar.gz fi else suffix=tgz fi # Split the file to be saved echo "Splitting $1.$suffix in pieces no larger than $bsize ..." split -b $bsize $1.$suffix $prefix. # create the save and restore scripts rstf=$prefix.rst savf=$prefix.sav rm -f $rstf $savf echo "Creating shell script $rstf to use to restore $1.$suffix ..." echo '#!/bin/sh' > $rstf echo "# shell script to use to restore $1.$suffix" >> $rstf echo "# Created by `basename $0` `date`" >> $rstf echo '# '`ls -l $1.$suffix` >> $rstf line= glob=$prefix.* disk_cnt=0 for i in `ls $glob` do if (test $1.$suffix = $i) then continue fi if (test $rstf = $i) then continue fi if (test $savf = $i) then continue fi disk_cnt=`expr $disk_cnt + 1` line="$line $i" echo "# "`ls -l $i` >> $rstf done echo 'sysbin=/usr/local/bin:/usr/local/gnu/bin:/bin:/usr/bin:/usr/lib' >> $rstf echo 'otherbin=$HOME/bin:/home/f85/bynum/bin' >> $rstf echo 'PATH=$sysbin:$otherbin:.' >> $rstf echo 'readfile() {' >> $rstf echo ' while (true)' >> $rstf echo ' do' >> $rstf echo ' echo -n "Insert floppy containing $i and press \"x\", then RETURN "' >> $rstf echo ' read ans2' >> $rstf echo ' case $ans2 in' >> $rstf echo ' x) mdir a:$i >& /dev/null' >> $rstf echo ' if (test $? != 0) then' >> $rstf echo ' echo "File $i is not on the floppy"' >> $rstf echo ' else' >> $rstf echo ' break' >> $rstf echo ' fi;;' >> $rstf echo ' esac' >> $rstf echo ' done' >> $rstf echo '}' >> $rstf echo 'OS=`uname -s`' >> $rstf echo "echo \"Restoring the file $1.$suffix from floppies\"" >> $rstf echo "if (test -f $1.$suffix) then" >> $rstf echo ' while (true)' >> $rstf echo ' do' >> $rstf echo " echo -n \"The file $1.$suffix exists. OK to overwrite? (y or n) \"" >> $rstf echo ' read ans' >> $rstf echo ' case $ans in' >> $rstf echo ' Y*|y*) break;;' >> $rstf echo " N*|n*) echo \"File $1.$suffix not modified\"" >> $rstf echo ' exit 0;;' >> $rstf echo ' esac' >> $rstf echo ' done' >> $rstf echo 'fi' >> $rstf echo "echo \"You will need $disk_cnt floppies containing the files\"" >> $rstf echo "echo \" $line\"" >> $rstf echo 'echo -n "Press RETURN when you have them "' >> $rstf echo 'read dummy' >> $rstf echo 'firsttime=T' >> $rstf echo "for i in $line" >> $rstf echo 'do' >> $rstf echo ' case $OS in' >> $rstf echo ' Sun*) eject;;'>> $rstf echo ' *) case $firsttime in' >> $rstf echo ' T) firsttime=F ;;' >> $rstf echo ' F) echo "Remove floppy from drive" ;;' >> $rstf echo ' esac' >>$rstf echo ' esac' >> $rstf echo ' if (test -f $i) then' >> $rstf echo ' while (true)' >> $rstf echo ' do' >> $rstf echo ' echo -n "File $i exists. OK to overwrite? (y or n) "' >> $rstf echo ' read ans' >> $rstf echo ' case $ans in' >> $rstf echo ' y*|Y*)' >> $rstf echo ' readfile' >> $rstf echo ' rm -f $i' >> $rstf echo ' mcopy a:/$i . ' >> $rstf echo ' break ;;' >> $rstf echo ' n*|N*) echo "File $i was not overwritten"' >> $rstf echo ' break;;' >> $rstf echo ' *) ;;' >> $rstf echo ' esac' >> $rstf echo ' done' >> $rstf echo ' else' >> $rstf echo ' readfile' >> $rstf echo ' mcopy a:$i .' >> $rstf echo ' fi' >> $rstf echo 'done' >> $rstf echo 'case $OS in'>> $rstf echo 'Sun*) eject;;'>> $rstf echo ' *) echo "Remove floppy from drive" ;;' >> $rstf echo 'esac' >> $rstf echo "cat $line "'>'" $1.$suffix" >> $rstf echo 'echo Original file size:' >> $rstf echo "echo \"`ls -l $1.$suffix`\"" >> $rstf echo 'echo Restored file size:' >> $rstf echo "ls -l $1.$suffix" >> $rstf chmod 700 $rstf # echo "Creating shell script $savf to use to save $1.$suffix to floppies ..." echo '#!/bin/sh' > $savf echo "# shell script to use to save $1.$suffix to floppies" >> $savf echo "# Created by `basename $0` `date`" >> $savf echo 'sysbin=/usr/local/bin:/usr/local/gnu/bin:/bin:/usr/bin:/usr/lib' >> $savf echo 'otherbin=$HOME/bin:/home/f85/bynum/bin' >> $savf echo 'PATH=$sysbin:$otherbin:.' >> $savf echo '# '`ls -l $1.$suffix` >> $savf for i in $line do echo "# "`ls -l $i` >> $savf done echo '# Original file size :' >> $savf echo "# "`ls -l $1.$suffix` >> $savf echo "echo \"Saving the file $1.$suffix to floppies\"" >> $savf echo "echo \"You will need $disk_cnt floppies\"" >> $savf echo 'echo -n "Press RETURN when you have them "' >> $savf echo 'read dummy' >> $savf echo 'firsttime=T' >> $savf echo "for i in $line" >> $savf echo 'do' >> $savf echo ' if (test ! -f $i) then' >> $savf echo ' echo "Can'"'"'t continue -- the file $i is missing"' >>$savf echo ' exit' >> $savf echo ' fi' >> $savf echo ' case $OS in' >> $savf echo ' Sun*) eject;;' >> $savf echo ' *) case $firsttime in' >> $savf echo ' T) firsttime=F ;;' >> $savf echo ' F) echo "Remove floppy from drive" ;;' >> $savf echo ' esac' >>$savf echo ' esac' >>$savf echo ' while (true)' >> $savf echo ' do' >> $savf echo ' echo -n "Insert floppy to receive $i and press \"x\", then RETURN "' >>$savf echo ' read ans' >>$savf echo ' case $ans in' >>$savf echo ' x) break;;' >> $savf echo ' esac' >> $savf echo ' done' >> $savf echo ' mformat a: || exit' >> $savf echo ' mcopy $i a: || exit ' >>$savf echo " mcopy $rstf a: || exit" >>$savf echo " mcopy $savf a: || exit" >>$savf echo ' mdir a: || exit' >> $savf echo "done" >> $savf echo 'case $OS in' >> $savf echo 'Sun*) eject;;'>> $savf echo ' *) echo "Remove floppy from drive" ;;' >> $savf echo 'esac' >> $savf echo "echo done" >> $savf chmod 700 $savf echo done # # $Log: fdsplit,v $ # Revision 1.3 1999/08/01 18:49:20 bynum # change protection of save & restore scripts from 755 to 700 # # Revision 1.2 1999/08/01 18:47:34 bynum # add robutsness to save and restore scripts, minor tweaks to echo strings # # Revision 1.1 1999/07/30 10:56:37 bynum # Initial revision # #