Shar program needed

Dennis G. Rears FSAC drears at pica.army.mil
Tue May 9 02:59:17 AEST 1989


Deryk C. Marien writes:
 
>Hi,
>
>	I am looking for a program which will "shar" (pack) a large program for
>posting to the net. At the moment I am only able to unshar using "sh."
>
   This is a short script so I am posting it to the net.  This was
given to me by a friend.  

Dennis



----------------------------------------------------------------------
#!/bin/sh
# @(#)shar.sh	1.6 8/15/86 - make a shell archive of specified files
#
# This is useful for preparing files for transfer to another site.
#
# Usage:  shar file [file ...] >outfile
#
# Files may also contain directory pathnames.
#
#  Informative messages will be written to stderr.
#
# Jack Moskowitz    <jackm at qa1.pica.army.mil>
#
# check for at least one file specified
if [ $# -lt 1 ]
then
	echo "Usage: shar file [file ...] >outfile" 1>&2
	exit
fi
# set up the beginning commands in the output file
echo "#!/bin/sh"
echo "#"
echo "# This is a shell archive.  To extract its contents,"
echo "# execute this file with /bin/sh to create the files:"
echo "`ls $* | pr -4 -t -w80 | sed \"s/^/# /\"`"
echo "#"
echo "# This shell archive created: `date`"
echo "#"
#
for arg in $*
do
	arg=`echo $arg | sed "s/^\.\///"`
	path=$arg
	if [ ! -f $path ]
	then
		if [ ! -d $path ]
		then
			echo "File $path does not exist. Skipping..." 1>&2
		fi
		continue
	fi
	len=`wc -c <$path`
	echo "Archiving file $path, length $len" 1>&2
	dir=.
	for file in `echo $path | tr '/' ' '`
	do
		if [ $file = . ]
		then
			continue
		fi
		dir=$dir/$file
		if [ -d $dir ]
		then
			echo "if [ ! -d $dir ]"
			echo "then"
			echo "echo \"Making directory $dir\""
			echo "mkdir $dir"
			echo "fi"
		else
			echo "echo \"extracting file $path\""
			echo "sed -e 's/^X//' <<\*EOF > $path"
			sed -e "s/^/X/" $path
			echo "*EOF"
			echo "if [ \`wc -c <$path\` -ne $len ]"
			echo "then"
			echo "	echo \"lengths do not match -- Bad Copy of $path\""
			echo "fi"
		fi
	done
done
echo "echo \"Done.\""
echo "Done." 1>&2
----------------------------------------------------------------------



More information about the Comp.unix.questions mailing list