dhesi@bsu-cs.bsu.edu (Rahul Dhesi) (03/24/89)
Checksum: 2160170143 (Verify with "brik -cv") Submitted-by: Rahul Dhesi <dhesi@bsu-cs.bsu.edu> Archive-name: rap This is not a shar archive! Cut at the cut line, store in a file called "rap", and make it executable. The documentation for this shell script is at its end. This shell script contains exactly two hard tabs (ASCII 9) and exactly two hard backspaces (ASCII 8). Without these it won't work. --cut here-- #! /bin/sh # Beta version -- tested only on 4.3BSD. # # Creates rap archives. A full description is at the end of this # script, so too many comment lines won't slow down the shell. # This script needs sed, awk, wc, and brik to be available. # # -- Rahul Dhesi 1989/03/23 if test $# -lt 1 then echo 'usage: rap file ...' exit 1 fi echo '#! /bin/sh' echo '# This is a rap archive. Feed it to "unrap" for extraction with' echo '# some protection against malicious archives or feed to /bin/sh' echo '# for extraction without any such protection. If /bin/sh is used' echo '# to extract the archive, it will try to invoke "brik" to verify' echo '# CRC values. If "brik" is not available, extraction will' echo '# still work but CRC values will not be verified. If "unrap"' echo '# is used, it will check CRC values itself and "brik" is not needed.' echo '#' echo '# If this archive arrived in multiple parts, concatenate all in order' echo '# without editing, and feed to sh. E.g., "cat part[12345] | sh"' echo '#' echo '# This archive includes the files listed below.' echo '#' for f in $* do echo $f done | awk ' BEGIN { rec = "# " } \ { if (length(rec $0) > 65) { print rec; rec = "# " $0 } \ else { rec = rec " " $0 } } \ END { print rec } ' echo '#' echo '#RAP archive follows.' echo '#VERSION 0 0' echo "hardtab=' ' # Must be hard tab within quotes" echo "bksp='' # Must be backspace within quotes" for f in $* do length=`wc -c < $f` echo '#BEGIN' echo '#FMARK' echo "# $f" echo "echo Extracting '$f', should be $length characters" echo "sed -e 's/^X//' -e \"s/@t/\$hardtab/g\" -e '/^#EOPART/,/#BOPART/d' \\" echo " -e \"s/@h/\$bksp/g\" -e 's/@a/@/g' > $f << \#EOF" sed < $f -e 's/^/X/' -e 's/@/@a/g' -e 's/ /@t/g' -e 's//@h/g' echo '#EOF' echo 'cat >/dev/null << \#FMARK' done echo '#FMARK' echo '#EOR' echo 'echo Checking CRC codes for errors...' echo 'brik -C << \#EOCRC' echo '#BOCRC' if brik -G $* then cat /dev/null else echo 1>&2 "Warning: CRC generation failed, don't use this archive" fi echo '#EOCRC' echo 'if test $? -eq 0' echo 'then' echo ' echo "No errors"' echo ' exit 0' echo 'else' echo " echo 'Oops! Errors occurred'" echo ' exit 1' echo 'fi' exit 0 RAP ARCHIVES The shell script above creates rap archives. Such archives are archives of text files similar to shar archives, but they have the following advantages over shar archives. 1. Rap archives can be extracted by feeding them to /bin/sh just like shar archive. But rap archives are formatted to be easily extractable by a program (called "unrap") written for this purpose. Extracting rap archives on non-UNIX systems does not require emulating sh, sed, etc. If unrap is used to extract the archive, it eliminates the possiblity of Trojan archives such as those that execute "rm -rf *" or create files with relative paths like "../../../...". Unrap written in portable C will be shortly released. 2. Rap archives can be split into multiple parts very easily. Make as many pieces of the archive as you wish, always cutting between two lines each of which begins with an X. To the end of each part, add this line (# is in first column): #EOPART To the beginning of each part, add this line (# is in first column): #BOPART The different parts can now be mailed or posted to Usenet separately. The recipient needs only to concatenate them in order (no editing of headers, signatures etc. is required) and feed the result to /bin/sh. 3. Rap archives contain the CRC-32 value of all files. These are checked at extraction time by invoking brik. I posted brik (including portable C source and MS-DOS executable) to comp.binaries.ibm.pc recently. I can post the C source to comp.sources.misc or alt.sources if there are many people who get these newsgroups but don't get comp.binaries.ibm.pc. If brik is not available at extraction time CRCs are not checked but files are still correctly extracted extracted. (The "unrap" program will do CRC checks itself at extraction time, so brik will not be needed at extraction time. The CRCs stored by brik are for text files and are independent of the file format of the underlying operating system provided the usual ASCII code is used. The current rap script requires brik to be present. The portable C implementation of rap will generate CRCs itself without requiring brik to be available. 4. Tab characters and backspaces are encoded using a printable escape sequence, so they are not likely to be lost during transmission through strange networks (e.g. BITNET). PROGRAM LIMITATIONS The rap script above does not handle pathnames at all. Specify only pure filenames without a path prefix, else unexpected things will happen. This will be fixed in a future version of rap that will be written in C. File protections are not preserved. These will be preserved in a future release. Rahul Dhesi 1989/03/23 Rahul Dhesi UUCP: <backbones>!{iuvax,pur-ee}!bsu-cs!dhesi ARPA: dhesi@bsu-cs.bsu.edu