Looking for SYS V r3 shar/unshar

Robert Felps felps at convex.com
Tue Dec 18 00:24:23 AEST 1990


In <104414 at cc.utah.edu> SJBACKUS at cc.utah.edu writes:

>Does anyone know of a version of shar/unshar for SYS V r 3?

Here is a Bourne shell script [un]shar and the man page.
It's not the lastest [un]shar.c, but it works.

--------------------------------- cut here ----------------------------------
#!/bin/sh
# @(#) shar 1.0 - create a shell archive file
# AUTHOR: Robert Felps
# DATE  : Aug 27 16:23:50 CDT 1989
# SYNTAX: shar files
# OPTS  :
# ARGS  : files  - list of files to be archived
# FILES :
# UPDATED BY:
# ON        :
# CHANGES   :
#
# vi/ex: set ts=4
#
# check for existing $SHAR_FILE
#
SHAR_FILE=sharfile
TMP=/tmp/shar.$$
case "$0" in
 *unshar*)	if [ $# -gt 0 ]
			then
				while [ -n "$1" ]
				 do
					if [ -f "$1" ]
					then awk '/^#!/,/^SOME-NON-EXISTENT-STR/ {
							 print }' $1 > $TMP
						 sh $TMP
						 rm -f $TMP
					else echo "No file $1 to unarchive!"
						 EXIT=9
					fi
					shift
				 done
			else 
				if [ -f "$SHAR_FILE" ]
				then sh "$SHAR_FILE"
				else echo "No file($1 or $SHAR_FILE) to unarchive!"
					 exit 1
				fi
			fi
			exit $EXIT ;;
   *shar*)	while [ -n "$1" ]
			 do
			  case "$1" in
				-o) shift ; SHAR_FILE=$1 ;;
				-o*) SHAR_FILE=`expr $1 : '..\(.*\)'` ;;
				 *) break ;;
			  esac
			  shift
			 done ;;
esac
if [ -f "$SHAR_FILE" ]
then echo "Sorry, will not overwrite existing \"$SHAR_FILE\""
     exit 2
fi

if [ $# -eq 0 ]
then echo "Must specify files to archive!"
	 exit 3
fi

 # create the header in the $SHAR_FILE
  cat > $SHAR_FILE <<\HDR_EOF
#!/bin/sh
# This is a SHell ARchive(shar), meaning:
# 1. Remove everything above the #!/bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#
# List of Archived Files:
#
HDR_EOF

 # list the files to be archived
for A
 do
  if [ -d "$A" ]
  then echo "#      $A (dir)"              >> $SHAR_FILE
  else echo "#      $A"                    >> $SHAR_FILE
  fi
 done
echo "#"                              >> $SHAR_FILE
echo "# This archive created: `date`" >> $SHAR_FILE
echo "#"                              >> $SHAR_FILE

 # Do the archiving
for A
 do
  if [ -d "$A" ]
  then
       cat >> $SHAR_FILE <<EXTRACT_EOF
echo "d - $A (Making Directory)"
mkdir $A
EXTRACT_EOF
       echo "d - $A (Making Directory)"
  else
  CHARS=`wc -c < $A`
  CHARS=`echo $CHARS`
  if [ "$CHARS" = "0" ]
  then echo "The archive file is empty!"
  else

   # insert extracting script for beginning of archived file
  cat >> $SHAR_FILE <<EXTRACT_EOF
echo "x - $A ($CHARS characters)"
if [ -f "$A" ]
then echo "\$0: will not over-write existing file '$A'"
else
sed 's/^X\./\./' <<\SHARC_EOF > $A
EXTRACT_EOF

   # ARCHIVE THE FILE!
  sed 's/^/X\./' $A >> $SHAR_FILE

   # insert extracting script for end of archived file
  cat >> $SHAR_FILE <<EXTRACT_EOF
SHARC_EOF
if [ $CHARS -ne \`wc -c < $A\` ]
then echo "\$0: transmit error '$A' (should have been $CHARS chars)"
fi
fi # end of overwriting check
EXTRACT_EOF
  echo "a - $A ($CHARS characters)"
  fi # [ "$CHARS" = "0" ]
  fi # [ -d "$A" ]
done
--------------------------------- cut here ----------------------------------
TH shar 1L "" "Local Commands"
SH NAME
shar - shell archive program
SH SYNOPSIS
B shar
[\fB -f \fIfile\fR ] \fIfile_list\fR
SH DESCRIPTION
The \fBshar\fR command archives multiple files to a single archive file.
It combines the files using shell commands. Thus to extract the files all
you have to do is run the /bin/sh (Bourne Shell) on the sharfile.
sp
It is advisable to use the \fBncp\fR command before using the \fRftpcp\fR
command.
SH OPTIONS
RS
PD 1
TP 10
B -f \fIfile\fR
Use \fIfile\fR as the filename for the archive file.
The default filename is \fIsharfile\fR.
RE
SS ARGUMENTS
RS
PD 1
TP 15
\fIfile_list\fR
A list of files you wish to archive.
The files should all be in the present working directory.
RE
SH EXAMPLES
To archive files from present directory to the sharfile,
sp
\fBshar *\fR
sp
To unarchive files from the sharfile,
sp
\fBsh sharfile\fR
sp
SH FILES
/share/bin/shar
SH SEE ALSO
tar(1), cpio(1)
SH WARNING
Beta version.



More information about the Comp.unix.questions mailing list