[net.sources] Another Shell Archiver

mn (10/25/82)

The following is an "improved" shell archiver inspired by the archiver
posted to net.sources by James Gosling (I believe). The main difference
is that this one will create lines in the archive to build sub-directories.

Hope this is of some use to someone out there.
Mark Nettleingham
...!ihldt!ll1!mn

# To distribute a program consisting of files foo1.c, foo2.c, and makefile
# type "shar archive foo1.c foo2.c makefile". The result will be saved
# in "archive".
# To retrieve the files simply run archive
# shar -- Shell archiver

SUB="no"; export SUB

set -- `getopt D $*`

if [ $? != 0 -o $# -lt 2 ]; then
	echo "Usage: $0 archive source1 source2 ..."
	exit
fi

for i in $*; do
	case $i in
	-D) SUB="yes"; shift;;
	--) shift; break;;
	esac
done

AR=$1
shift

if [ "$SUB" != "yes" -a -s $AR ]; then
	echo "$0: File $AR exists, choose another."
	exit
fi

expr $AR : '^/.*' > /dev/null 
if [ $? -ne 0 ]; then
	AR=`pwd`/$AR
fi

for i do
	if [ ! -r $i ]; then
		echo "$0: File $AR Can't open"
		rm -f $AR
		exit
	fi

#If the file is a directory creat mkdir and start another archiver
	if [ -d $i ]; then
		echo "a - $i (directory)"
		echo "mkdir $i" >> $AR
		echo "cd $i" >> $AR
		cd $i
		eval $0 -D $AR *
		cd ..
	else
		echo a - $i
		echo "echo x - $i" >>$AR
		echo "cat >$i <<'!E!O!F!'" >>$AR
		cat $i >>$AR
		echo "!E!O!F!" >>$AR
	fi
done

if [ "$SUB" = "yes" ]; then
	echo "cd .." >> $AR
fi