home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume30
/
bintools
/
part01
next >
Wrap
Text File
|
1992-05-30
|
45KB
|
1,533 lines
Newsgroups: comp.sources.misc
From: rthomson@dsd.es.com (Rich Thomson)
Subject: v30i023: bintools - binary mail/post tools, Part01/01
Message-ID: <1992May29.203930.973@sparky.imd.sterling.com>
X-Md4-Signature: 7ce6601c5dc6ee2bb5f00a40393183c2
Date: Fri, 29 May 1992 20:39:30 GMT
Approved: kent@sparky.imd.sterling.com
Submitted-by: rthomson@dsd.es.com (Rich Thomson)
Posting-number: Volume 30, Issue 23
Archive-name: bintools/part01
Environment: UNIX
Supersedes: bintools: Volume 26, Issue 73
Trading binary files (i.e. images) has become quite popular on the net.
These are a couple of tools I wrote to sanely post/mail binary
files. The files are uuencoded and split into pieces. Each piece is
packaged as a self-extracting shell archive. Simple BEGIN/END
markers delineating the end/beginning of header/footer material,
respectively, are inserted for those without unshar capabilities.
This gives a way of posting images that is backward compatible with
the current convention (using BEGIN/END markers to delineate
header/footers), while giving those with 'unshar' capabilities
automatic decoding. Further, decoding with the shell archive allows
the pieces to be processed in any order.
This the first major revision of these scripts based on user feedback
after an initial distribution on alt.sources. New features of the
2.0 release of these scripts are:
Man pages
The first release was the scripts only. Troff-source for man pages
is now included.
New flags:
-N count Specify size of uuencoded chunks
-S sleep Sleep between messages (useful for sluggish transport
systems)
-F file Specify the name of the decoded file when processing
standard input.
-sysv
-bsd Specify convention of your mail program
-k Allows a copy of constructed messages to be stashed away
-nosend Doesn't actually deliver the constructed messages
(useful for testing when combined with -k)
Improved shar header
Better instructions for decoding the shell archives is put into
the archive header prepended to each piece. This includes
instructions for this without /bin/sh (or unix) capabilities.
-- Rich
---------------- Cut Here --------------
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: post-bin mail-bin post-bin.1 mail-bin.1
# Wrapped by rthomson@mesa on Sat May 2 17:53:48 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'post-bin' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'post-bin'\"
else
echo shar: Extracting \"'post-bin'\" \(13494 characters\)
sed "s/^X//" >'post-bin' <<'END_OF_FILE'
X#!/bin/sh
X#
X# post-bin -- post a binary file to news
X#
X# $Header: post-bin,v 2.2 92/05/02 17:35:07 rthomson Exp $
X#
X# post-bin [options] [file...]
X#
X# Valid options are:
X#
X# -n newsgroup
X# Post the binary image to the named newsgroup. If no newsgroup is
X# named, the default is alt.binaries.pictures.misc.
X#
X# -f follow-up
X# Set the "Followup-to:" field in the article to the named
X# newsgroup. If none is specified, the default is
X# alt.binaries.pictures.d
X#
X# -D distribution
X# Set the "Distribution:" field in the articles to the named value.
X# The default distribution is world.
X#
X# -d descfile
X# Use the named file as the description of the image, to be placed
X# before each piece of the uuencoded file. If no description file is
X# named, the user is placed into $EDITOR on a description file. If
X# $EDITOR is undefined, vi is used. Use '-d /dev/null' for no
X# description (not recommended!)
X#
X# -t append_text
X# Append the supplied text to the end of the generated subject
X# strings. This allows the articles' subjects to be annotated,
X# e.g. "[640x480, 256-color GIF]".
X# -T prepend_text
X# Prepend the given text onto the generated subject line.
X#
X# -N count
X# Specify the size of the uuencoded pieces. If count is zero, then
X# a single article will be posted (only recommended for small files).
X# Default: 1000
X#
X# -k prefix
X# Keep the constructed messages after delivery. This is useful
X# for reposting/resending a single piece that was not delivered.
X# The constructed messages are placed in the file given by
X# "prefix" with .# appended, where "#" is the sequence number of the
X# message.
X#
X# -nosend
X# Do not actually deliver the messages. This is useful for recreating a
X# particular piece of a large number of pieces without sending them all.
X# It is also useful in testing out the script.
X#
X# -F filename
X# Decode to specified filename when reading from standard input.
X#
X# -S sleeptime
X# Sleep the specified number of seconds between articles.
X#
X# -v Operate verbosely
X# -q Operate quietly
X#
X# Post-bin reads the named file(s), uuencodes them, and splits the files
X# into pieces, usually 1000 lines or less in length. Each piece is then
X# posted as a news article containing a shell archive to the named
X# newsgroup(s). The sleep option is given because some transport
X# mechanisms (notably, sendmail) can become overwhelmed with the number
X# of articles that post-bin can produce for large files. By sleeping
X# between articles (say 5 seconds per 1000 lines) sent, post-bin allows
X# the transport mechanism to catch up on processing the articles.
X#
X# If each shell archive is fed to the shell, the uuencoded pieces will
X# be extracted from the archive and a rudimentary file lengthe check
X# will be performed on each piece. Once all the pieces have been
X# extracted, the pieces will be concatenated in their proper order and
X# fed to uudecode. If the uudecode operation is successful, the pieces
X# will be removed.
X#
X# If you do not have /bin/sh or run unix, decoding may also be performed
X# by concatenating the pieces (in the proper order) and feeding the result
X# to the command:
X#
X# sed -e '/^END/,/^BEGIN/d' | uudecode
X#
X# A description of the file, from the named description file or an
X# editing session if none is named, is placed at the beginning of each
X# article.
X#
X# Please send bugs/comments to rthomson@dsd.es.com
X#
X# Rich Thomson, June 3rd, 1991
X#
X# Copyright 1991 by Evans & Sutherland Computer Corporation,
X# Salt Lake City, Utah
X#
X# All Rights Reserved
X#
X# Permission to use, copy, modify, and distribute this software and its
X# documentation for any purpose and without fee is hereby granted,
X# provided that the above copyright notice appear in all copies and that
X# both that copyright notice and this permission notice appear in
X# supporting documentation, and that the names of Evans & Sutherland not be
X# used in advertising or publicity pertaining to distribution of the
X# software without specific, written prior permission.
X#
X# EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
X# EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
X# PERFORMANCE OF THIS SOFTWARE.
X#
X
X# remove temporary files upon encountering interrupt or quit signal
Xcleanup()
X{
X rm -f /tmp/xx-$$-* /tmp/$$-description
X exit 1
X}
Xtrap cleanup 2 3
X
X# Print a stupid usage message and exit with non-zero status.
Xusage()
X{
X echo
X echo "Usage (revision $revision):"
X echo
X echo "`basename $0` [options] [file ...]"
X echo
X echo Valid options are:
X echo
X echo " [-help] Get this help message"
X echo " [-n newsgroup] Specify destination newsgroup"
X echo " Default: $newsgroup"
X echo " [-f followup-to] Specify followup-to newsgroup"
X echo " Default: $followup"
X echo " [-d descfile] Specify prepared description file"
X echo " Default is to invoke the editor."
X echo " [-D distribution] Specify distribution value"
X echo " Default: $dist"
X echo " [-t append_text] Append the extra text onto the subject line"
X echo " [-T prepend_text] Prepend the extra text onto the subject line"
X echo " [-N count] Split uuencoded file into count size chunks"
X echo " Default: $count"
X echo " [-F filename] Decode to specified file when using stdin"
X echo " Default: $filename"
X echo " [-S sleeptime] Sleep sleeptime seconds between articles."
X echo " Default: $sleeptime"
X echo " [-k prefix] Keep the constructed messages in files whose"
X echo " names are constructed from the given prefix."
X echo " [-nosend] Do not actually deliver the messages."
X if [ $verbosity = True ]; then
X echo " [-v] Operate verbosely (default)"
X echo " [-q] Operate quietly"
X else
X echo " [-v] Operate verbosely"
X echo " [-q] Operate quietly (default)"
X fi
X echo
X
X exit 1
X}
X
X# print a message if the verbose flag is on.
Xverbose()
X{
X if [ $verbosity = True ]; then
X echo $*
X fi
X}
X
X# This produces leading zeros for the part numbers. NN users are
X# anal-retentive about the subject lines being lexicographically ordered.
Xzeros()
X{
X case $1 in
X 1 | 2 )
X echo $part
X ;;
X 3 )
X echo 0$part | sed 's/^.*\(..\)$/\1/'
X ;;
X 4 )
X echo 00$part | sed 's/^.*\(...\)$/\1/'
X ;;
X 5 )
X echo 000$part | sed 's/^.*\(....\)$/\1/'
X ;;
X esac
X}
X
X# put the header on the piece. This includes a little /bin/sh preamble
X# so that the file can be unpacked on the remote end with /bin/sh.
X#
Xheader()
X{
X cat << _End_of_Header
X#!/bin/sh
X#
X# This is a self-extracting shell archive of the binary file "$file".
X# Created on `date` by `basename $0`, revision $revision.
X#
X# To decode with /bin/sh, remove everything before the /bin/sh and feed
X# each piece as input to /bin/sh. When all the pieces have been
X# processed, the archive will automatically concatenate the pieces and
X# uudecode them to produce $file. If successful, it will remove all
X# uuencoded pieces. Alternatively, the archive(s) may be processed with
X# no editing by the unshar program.
X#
X# If you do not have /bin/sh or unix, you may decode by removing
X# everthing before/after the lines beginning with the word BEGIN/END,
X# respectively, in each piece. Then concatenate the pieces in the proper
X# order and uudecode.
X#
Xpart=$print_part
Xpfile=`echo $file | sed 's/^\(..........\).*$/\1/'`
Xfile=$file
Xpsize=`wc -c < $1 | sed 's/ //g'`
Xsed -e '/^BEGIN/d' -e '/^END/d' << \End_of_Section > \$pfile.\$part
XBEGIN------------ $file ------------ part $print_part/$num_parts ---
X_End_of_Header
X}
X
X# The /bin/sh trailer. It does a rudimentary check on the length of
X# the uuencoded piece extracted. When all the pieces are present, it
X# concatenates them into uudecode. There is alot of creative shell
X# quoting here.
X#
Xtrailer()
X{
X echo END-------------- $file ------------ part $print_part/$num_parts ---
X cat << _End_of_Trailer
XEnd_of_Section
Xsize=\`wc -c \$pfile.\$part | awk '{ print \$1 }'\`
Xif [ \$size != \$psize ]; then
X echo Length mismatch for uuencoded part \$part \(\$size != \$psize\).
X exit 1
Xfi
Xecho \$file, part \$part extracted.
X
Xif [ \`echo \$pfile.[0-9]* | wc -w\` = $num_parts ]; then
X echo All uuencoded parts of \$file extracted, uudecoding...
X cat \$pfile.* | uudecode
X if [ \$? -gt 0 ]; then
X echo Error encountered when uudecoding pieces...
X exit 1
X fi
X
X echo \$file successfully uudecoded. Removing uuencoded pieces.
X rm \$pfile.[0-9]*
Xfi
Xexit 0
X_End_of_Trailer
X}
X
X# Construct each message to be posted on stdout.
Xmessage()
X{
X echo Newsgroups: $newsgroup
X echo Subject: $prepend$file, part $print_part/$num_parts$append
X echo Followup-to: $followup
X echo Distribution: $dist
X echo ''
X cat $descfile
X echo ''
X header $1
X cat $1
X trailer
X}
X
X# Post each chunk of the file with appropriate header lines, description
X# and header/footer pairs.
Xpost_parts()
X{
X file=$1
X shift
X num_parts=$#
X part=1
X num_zeros=`echo $num_parts | wc -c`
X while [ X$1 != X ]; do
X print_part=`zeros $num_zeros $part`
X message $1 > /tmp/xx-$$-article
X if [ $noSend = True ]; then
X verbose Preparing $file, part $print_part of $num_parts...
X else
X verbose Posting $file, part $print_part of $num_parts...
X inews -h /tmp/xx-$$-article
X if [ X$1 != X ]; then
X sleep $sleeptime
X fi
X fi
X if [ $keep = True ]; then
X mv /tmp/xx-$$-article $prefix.$print_part
X fi
X part=`expr $part + 1`
X shift
X done
X}
X
X# uuencode each file, splitting into $count line chunks. Then post each chunk.
Xsplit_and_post_files()
X{
X while [ X$1 != X ]; do
X rm -f /tmp/xx-$$-*
X file=`basename $1`
X if [ $count -eq 0 ]; then
X verbose UUencoding $file...
X uuencode $1 $file > /tmp/xx-$$-aa
X else
X verbose UUencoding and splitting $file...
X uuencode $1 $file | split -$count - /tmp/xx-$$-
X fi
X post_parts $file /tmp/xx-$$-*
X rm /tmp/xx-$$-*
X shift
X done
X}
X
X# make sure we have descfile setup. If it is not set, then invoke editor
X# on temporary file
Xget_desc_file()
X{
X if [ X$descfile = X ]; then
X descfile=/tmp/$$-description
X touch $descfile
X $editor $descfile < /dev/tty
X fi
X}
X
X# make sure description file created by get_desc_file is removed
Xclean_desc_file()
X{
X if [ $descfile = /tmp/$$-description ]; then
X rm $descfile
X fi
X}
X
X# Check for blank or empty specification for required arguments.
Xblank_arg()
X{
X if [ "X$1" = X ]; then
X usage
X fi
X}
X
X# initialize some variables
X# Default newsgroup
Xnewsgroup="alt.binaries.pictures.misc"
X# Default followup newsgroup; default value is set after argument parsing
Xfollowup=""
X# Default distribution
Xdist=world
X# Default description file (none; invoke editor)
Xdescfile=""
X# Default file list (none; use stdin)
Xfiles=""
X# Chunk size
Xcount=1000
X# Don't keep the messages by default
Xkeep=False
Xprefix=""
X# Deliver the messages by default
XnoSend=False
X# Filename to use for uuencoding stdin
Xfilename="binary.data"
X# Initial extra text is empty
Xappend=""
Xprepend=""
X# Operate verbosely by default
Xverbosity=True
X# Don't sleep between parts by default
Xsleeptime=0
X# Revision of this script.
Xrevision=`echo $Revision: 2.2 $ | sed 's%[^0-9.]%%g'`
Xif [ "X$EDITOR" = "X" ]; then
X editor=vi
Xelse
X editor="$EDITOR"
Xfi
X
X# parse the command line arguments
Xwhile [ "X$1" != X ]; do
X case $1 in
X -h* )
X usage
X ;;
X
X -t* )
X append=" $2"
X blank_arg $2
X shift
X ;;
X
X -T* )
X prepend="$2 "
X blank_arg $2
X shift
X ;;
X
X -k* )
X keep=True
X prefix=$2
X blank_arg $prefix
X shift
X ;;
X
X -nosend* )
X noSend=True
X ;;
X
X -n* )
X newsgroup=$2
X blank_arg $newsgroup
X shift
X ;;
X
X -f* )
X followup=$2
X blank_arg $followup
X shift
X ;;
X
X -D*)
X dist=$2
X blank_arg $dist
X shift
X ;;
X
X -d* )
X descfile=$2
X blank_arg $descfile
X shift
X ;;
X
X -N* )
X count=$2
X blank_arg $count
X shift
X ;;
X
X -F* )
X filename="$2"
X blank_arg $filename
X shift
X ;;
X
X -q* )
X verbosity=False
X ;;
X
X -v* )
X verbosity=True
X ;;
X
X * )
X if [ -r $1 ]; then
X if [ "X$files" = X ]; then
X files=$1
X else
X files="$files $1"
X fi
X else
X echo `basename $0`: can\'t read file $1.
X usage
X fi
X ;;
X esac
X shift
Xdone
X
X# make sure followup is set to something decent if not yet specified
Xif [ "X$followup" = "X" ]; then
X followup="alt.binaries.pictures.d"
Xfi
X
X# uuencode and split stdin, then post; or split and post file list
Xif [ "X$files" = X ]; then
X if [ $count -eq 0 ]; then
X verbose UUencoding standard input as $filename...
X uuencode $filename > /tmp/xx-$$-aa
X else
X verbose UUencoding and splitting standard input as $filename...
X uuencode $filename | split -$count - /tmp/xx-$$-
X fi
X get_desc_file
X post_parts $filename /tmp/xx-$$-*
X clean_desc_file
Xelse
X get_desc_file
X split_and_post_files $files
X clean_desc_file
Xfi
X
Xexit 0
END_OF_FILE
if test 13494 -ne `wc -c <'post-bin'`; then
echo shar: \"'post-bin'\" unpacked with wrong size!
fi
chmod +x 'post-bin'
# end of 'post-bin'
fi
if test -f 'mail-bin' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mail-bin'\"
else
echo shar: Extracting \"'mail-bin'\" \(12762 characters\)
sed "s/^X//" >'mail-bin' <<'END_OF_FILE'
X#!/bin/sh
X#
X# mail-bin -- mail a binary file to someone
X#
X# $Header: mail-bin,v 2.5 92/05/02 17:53:02 rthomson Exp $
X#
X# mail-bin [options] address [file ...]
X#
X# Valid options are:
X#
X# -d descfile
X# Use the named file as the description of the image, to be placed
X# before each piece of the uuencoded file. If no description file is
X# named, the user is placed into $EDITOR on a description file. If
X# $EDITOR is undefined, vi is used.
X#
X# -t append_text
X# Append the given text onto the Subject: line.
X# -T prepend_text
X# Prepend the given text onto the Subject: line.
X#
X# -sysv
X# Use System V style mailer where Subject: line is the first line in
X# the body of the message instead of being specified with "-s"
X# -bsd
X# Use BSD style mailer where Subject: line is given via "-s" switch.
X#
X# -N count
X# Split file into uuencoded pieces count lines long.
X#
X# -k prefix
X# Keep the constructed messages after delivery. This is useful
X# for reposting/resending a single piece that was not delivered.
X# The constructed messages are placed in the file given by
X# "prefix" with .# appended, where "#" is the sequence number of the
X# message.
X#
X# -nosend
X# Do not actually deliver the messages. This is useful for recreating a
X# particular piece of a large number of pieces without sending them all.
X# It is also useful in testing out the script.
X#
X# -F filename
X# Decode to specified filename when reading from standard input.
X#
X# -S sleeptime
X# Sleep the specified number of seconds between messages.
X#
X# address
X# The mailing address of the person to receive the binary file.
X#
X# Mail-bin reads the named files, or the standard input if no files are
X# named, and splits the files into 1000 line pieces. Each piece is then
X# mailed as a to the named recipient as a shell archive. The sleep
X# option is given because some mailers (notably, sendmail) can become
X# overwhelmed with the number of mail messages that mail-bin can produce
X# for large files. By sleeping between messages (say 5 seconds per 1000
X# lines) sent, mail-bin allows the mailer to catch up on processing then
X# messages.
X#
X# If each shell archive is fed to the shell, the uuencoded pieces will
X# be extracted from the archive and a rudimentary file length check will
X# be performed on each piece. Once all the pieces have been extracted,
X# the pieces will be concatenated in their proper order and fed to
X# uudecode. If the uudecode operation is successful, the pieces will be
X# removed. Decoding may also be performed by concatenating the pieces
X# (in the proper order) and feeding the result to the command:
X#
X# sed -e '/^END/,/^BEGIN/d' | uudecode
X#
X# A description of the file, from the named description file or an
X# editing session if none is named, is placed at the beginning of each
X# message.
X#
X# Please send bugs/comments to rthomson@dsd.es.com
X#
X# Rich Thomson, June 28th, 1991
X#
X# Copyright 1991 by Evans & Sutherland Computer Corporation,
X# Salt Lake City, Utah
X#
X# All Rights Reserved
X#
X# Permission to use, copy, modify, and distribute this software and its
X# documentation for any purpose and without fee is hereby granted,
X# provided that the above copyright notice appear in all copies and that
X# both that copyright notice and this permission notice appear in
X# supporting documentation, and that the names of Evans & Sutherland not be
X# used in advertising or publicity pertaining to distribution of the
X# software without specific, written prior permission.
X#
X# EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X# INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
X# EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
X# PERFORMANCE OF THIS SOFTWARE.
X#
X
X# remove temporary files upon encountering interrupt or quit signal
Xcleanup()
X{
X rm -f /tmp/xx-$$-* /tmp/$$-description
X exit 1
X}
Xtrap cleanup 2 3
X
X# Stupid usage message
Xusage()
X{
X echo
X echo "Usage (revision $revision):"
X echo
X echo `basename $0` [options] address [file ...]
X echo
X echo Valid options are:
X echo
X echo " [-help] Get this help message"
X echo " [-d descfile] Specify prepared description file"
X echo " Default is to invoke the editor."
X echo " [-t append_text] Append the extra text onto the subject line"
X echo " [-T prepend_text] Prepend the extra text onto the subject line"
X echo " [-N count] Split file into pieces of count lines"
X echo " Default: $count"
X echo " [-F filename] Decode to specified file when using stdin"
X echo " Default: $filename"
X echo " [-S sleeptime] Sleep sleeptime seconds between messages."
X echo " Default: $sleeptime"
X echo " [-k prefix] Keep the constructed messages in files whose"
X echo " names are constructed from the given prefix."
X echo " [-nosend] Do not actually deliver the messages."
X if [ $systemV = True ]; then
X echo " [-sysv] mail program is System V style (default)"
X echo " [-bsd] mail program is BSD style"
X else
X echo " [-sysv] mail program is System V style"
X echo " [-bsd] mail program is BSD style (default)"
X fi
X if [ $verbosity = True ]; then
X echo " [-v] Operate verbosely (default)"
X echo " [-q] Operate quietly"
X else
X echo " [-v] Operate verbosely"
X echo " [-q] Operate quietly (default)"
X fi
X echo
X exit 1
X}
X
X# print a message if the verbose flag is on.
Xverbose()
X{
X if [ $verbosity = True ]; then
X echo $*
X fi
X}
X
X# This produces leading zeros for the part numbers. NN users are
X# anal-retentive about the subject lines being lexicographically ordered.
Xzeros()
X{
X case $1 in
X 1 | 2 )
X echo $part
X ;;
X 3 )
X echo 0$part | sed 's/^.*\(..\)$/\1/'
X ;;
X 4 )
X echo 00$part | sed 's/^.*\(...\)$/\1/'
X ;;
X esac
X}
X
X# put the header on the piece. This includes a little /bin/sh preamble
X# so that the file can be unpacked on the remote end with /bin/sh.
X#
Xheader()
X{
X cat << _End_of_Header
X#!/bin/sh
X#
X# This is a self-extracting shell archive of the binary file "$file".
X# Created on `date` by `basename $0`, revision $revision.
X#
X# To decode with /bin/sh, remove everything before the /bin/sh and feed
X# each piece as input to /bin/sh. When all the pieces have been
X# processed, the archive will automatically concatenate the pieces and
X# uudecode them to produce $file. If successful, it will remove all
X# uuencoded pieces. Alternatively, the archive(s) may be processed with
X# no editing by the unshar program.
X#
X# If you do not have /bin/sh or unix, you may decode by removing
X# everthing before/after the lines beginning with the word BEGIN/END,
X# respectively, in each piece. Then concatenate the pieces in the proper
X# order and uudecode.
X#
Xpart=$print_part
Xpfile=`echo $file | sed 's/^\(..........\).*$/\1/'`
Xfile=$file
Xpsize=`wc -c < $1 | sed 's/ //g'`
Xsed -e '/^BEGIN/d' -e '/^END/d' << \End_of_Section > \$pfile.\$part
XBEGIN------------ $file ------------ part $print_part/$num_parts ---
X_End_of_Header
X}
X
X# The /bin/sh trailer. It does a rudimentary check on the length of
X# the uuencoded piece extracted. When all the pieces are present, it
X# concatenates them into uudecode. There is alot of creative shell
X# quoting here.
X#
Xtrailer()
X{
X echo END-------------- $file ------------ part $print_part/$num_parts ---
X cat << _End_of_Trailer
XEnd_of_Section
Xsize=\`wc -c \$pfile.\$part | awk '{ print \$1 }'\`
Xif [ \$size != \$psize ]; then
X echo Length mismatch for uuencoded part \$part \(\$size != \$psize\).
X exit 1
Xfi
Xecho \$file, part \$part extracted.
X
Xif [ \`echo \$pfile.[0-9]* | wc -w\` = $num_parts ]; then
X echo All uuencoded parts of \$file extracted, uudecoding...
X cat \$pfile.* | uudecode
X if [ \$? -gt 0 ]; then
X echo Error encountered when uudecoding pieces...
X exit 1
X fi
X
X echo \$file successfully uudecoded. Removing uuencoded pieces.
X rm \$pfile.[0-9]*
Xfi
Xexit 0
X_End_of_Trailer
X}
X
X# Create the body of each message
Xbody()
X{
X if [ $systemV = True ]; then
X echo To: $address
X echo Subject: $prepend$file, part $print_part/$num_parts$append
X echo ''
X fi
X cat $descfile
X echo ''
X header $1
X cat $1
X trailer
X}
X
X# Post each chunk of the file with appropriate header lines, description
X# and header/footer pairs.
Xmail_parts()
X{
X file=$1
X shift
X num_parts=$#
X part=1
X num_zeros=`echo $num_parts | wc -c`
X while [ X$1 != X ]; do
X print_part=`zeros $num_zeros $part`
X verbose Mailing $file, part $print_part of $num_parts...
X if [ $keep = True ]; then
X body $1 \
X | tee $prefix.$print_part
X else
X body $1
X fi \
X | if [ $noSend = True ]; then
X cat > /dev/null
X else
X if [ $systemV = True ]; then
X mail $address
X else
X mail -s "$prepend$file, part $print_part/$num_parts$append" \
X $address
X fi
X if [ X$1 != X ]; then
X sleep $sleeptime
X fi
X fi
X part=`expr $part + 1`
X shift
X done
X}
X
X# uuencode each file, splitting into $count line chunks. Then mail each chunk.
Xsplit_and_mail_files()
X{
X while [ X$1 != X ]; do
X rm -f /tmp/xx-$$-*
X file=`basename $1`
X if [ $count -eq 0 ]; then
X verbose UUencoding $file...
X uuencode $1 $file > /tmp/xx-$$-aa
X else
X verbose UUencoding and splitting $file...
X uuencode $1 $file | split -$count - /tmp/xx-$$-
X fi
X mail_parts $file /tmp/xx-$$-*
X rm /tmp/xx-$$-*
X shift
X done
X}
X
X# make sure we have descfile setup. If it is not set, then invoke editor
X# on temporary file
Xget_desc_file()
X{
X if [ X$descfile = X ]; then
X descfile=/tmp/$$-description
X touch $descfile
X $editor $descfile < /dev/tty
X fi
X}
X
X# make sure description file created by get_desc_file is removed
Xclean_desc_file()
X{
X if [ $descfile = /tmp/$$-description ]; then
X rm $descfile
X fi
X}
X
X# Check for blank or empty specification for required arguments.
Xblank_arg()
X{
X if [ "X$1" = X ]; then
X usage
X fi
X}
X
X# initialize some variables
X# No address by default; must be specified.
Xaddress=""
X# Invoke editor for description by default
Xdescfile=""
X# Default to stdin.
Xfiles=""
X# Decode into this file when using stdin.
Xfilename="binary.data"
X# No extra text by default
Xappend=""
Xprepend=""
X# Be verbose by default
Xverbosity=True
X# Use 1000 line chunks by default
Xcount=1000
X# Don't keep the messages by default
Xkeep=False
Xprefix=""
X# Deliver the messages by default
XnoSend=False
X# Don't use System V style mailing by default
XsystemV=False
X# Don't sleep between parts by default
Xsleeptime=0
X# Revision of this script
Xrevision=`echo $Revision: 2.5 $ | sed 's%[^0-9.]%%g'`
Xif [ "X$EDITOR" = "X" ]; then
X editor=vi
Xelse
X editor="$EDITOR"
Xfi
X
X# parse the command line arguments
Xwhile [ X$1 != X ]; do
X case $1 in
X -h* )
X usage
X ;;
X
X -d* )
X descfile=$2;
X blank_arg $descfile
X shift
X ;;
X
X -t* )
X append=" $2"
X blank_arg $2
X shift
X ;;
X
X -T* )
X prepend="$2 "
X blank_arg $2
X shift
X ;;
X
X -N* )
X count=$2
X blank_arg $count
X shift
X ;;
X
X -k* )
X keep=True
X prefix=$2
X blank_arg $prefix
X shift
X ;;
X
X -nosend* )
X noSend=True
X ;;
X
X -sysv* )
X systemV=True
X ;;
X
X -bsd* )
X systemV=False
X ;;
X
X -F* )
X filename="$2"
X blank_arg $filename
X shift
X ;;
X
X -S* )
X sleeptime="$2";
X blank_arg $sleeptime
X shift
X ;;
X
X -q* )
X verbosity=False
X ;;
X
X -v* )
X verbosity=True
X ;;
X
X * )
X if [ "X$address" = X ]; then
X address=$1
X else
X if [ -r $1 ]; then
X if [ "X$files" = X ]; then
X files=$1
X else
X files="$files $1"
X fi
X else
X echo `basename $0`: can\'t read file $1.
X usage
X fi
X fi
X ;;
X esac
X shift
Xdone
X
X# Must have a mail address before continuing
Xif [ "X$address" = X ]; then
X echo Required address argument missing!
X echo
X usage
Xfi
X
X# uuencode and split stdin, then mail; or split and mail file list
Xif [ "X$files" = X ]; then
X if [ $count -eq 0 ]; then
X verbose UUencoding standard input as $filename...
X uuencode $filename > /tmp/xx-$$-aa
X else
X verbose UUencoding and splitting standard input as $filename...
X uuencode $filename | split -$count - /tmp/xx-$$-
X fi
X get_desc_file;
X mail_parts $filename /tmp/xx-$$-*;
X clean_desc_file;
Xelse
X get_desc_file;
X split_and_mail_files $files;
X clean_desc_file;
Xfi
X
Xexit 0
END_OF_FILE
if test 12762 -ne `wc -c <'mail-bin'`; then
echo shar: \"'mail-bin'\" unpacked with wrong size!
fi
chmod +x 'mail-bin'
# end of 'mail-bin'
fi
if test -f 'post-bin.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'post-bin.1'\"
else
echo shar: Extracting \"'post-bin.1'\" \(6273 characters\)
sed "s/^X//" >'post-bin.1' <<'END_OF_FILE'
X.TH POST-BIN 1 "2 May 1992" "" "Binary Tools"
X.\"
X.\" Copyright 1991 by Evans & Sutherland Computer Corporation,
X.\" Salt Lake City, Utah
X.\"
X.\" All Rights Reserved
X.\"
X.\" Permission to use, copy, modify, and distribute this software and its
X.\" documentation for any purpose and without fee is hereby granted,
X.\" provided that the above copyright notice appear in all copies and that
X.\" both that copyright notice and this permission notice appear in
X.\" supporting documentation, and that the names of Evans & Sutherland not be
X.\" used in advertising or publicity pertaining to distribution of the
X.\" software without specific, written prior permission.
X.\"
X.\" EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X.\" INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
X.\" EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X.\" CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X.\" DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X.\" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
X.\" PERFORMANCE OF THIS SOFTWARE.
X.\"
X.SH NAME
Xpost-bin \- sanely post a binary file to a newsgroup
X.SH SYNOPSIS
X.B post-bin
X[
X.BI \-n\ newsgroup
X]
X[
X.BI \-f\ follow-up
X]
X[
X.BI \-D\ distribution
X]
X[
X.BI \-d\ descfile
X]
X[
X.BI \-t\ append_text
X]
X[
X.BI \-T\ prepend_text
X]
X[
X.BI \-N\ count
X]
X[
X.BI \-F\ filename
X]
X[
X.BI \-S\ sleeptime
X]
X[
X.BI \-k\ prefix
X]
X[
X.B \-nosend
X]
X[
X.B \-v
X]
X[
X.B \-q
X]
X[
X.B \-help
X]
X[
X.IR filename .\|.\|.
X]
X.LP
X.SH DESCRIPTION
X.LP
X.B Post-bin
Xreads the named files, or the standard input if no files are named,
Xuuencodes them, and splits the uuencoded files into pieces.
XEach piece is then posted as to the named newsgroup as a self-extracting
Xshell archive.
X.LP
XThe reader then feeds the body of each article (the portion beginning
Xat the #!/bin/sh line) as the standard input to /bin/sh.
XIf the unshar program is available, it may be used to process each
Xarticle without any editing. Some newsreaders (i.e. rn 4.4) also
Xprovide an "unshar" command that may also be used.
XThe received articles may be processed in any order (typically
Xthey do not arrive in the order sent). Once all pieces of a binary file
Xhave been processed, the shell archive automatically concatenates the
Xpieces in their proper order and uudecodes them. If the file was
Xsuccessfully uudecoded, the individual pieces are removed.
X.LP
XFor those readers without /bin/sh (or not running unix),
Xdecoding may be performed by removing the all text before/after the
Xlines beginning with the words BEGIN/END, respectively, in each
Xpiece. Then concatenate the pieces in the proper order and uudecode.
X.LP
XA description of the file, from the named description file or an
Xediting session if none is named, is placed at the beginning of each
Xarticle.
X.SH OPTIONS
X.TP
X.BI \-n\ newsgroup
XPost the binary file to the named newsgroup. Default:
Xalt.binaries.pictures.misc.
X.TP
X.BI \-f\ follow-up
XSet the Followup-To field in the header to the named newsgroup. Default:
Xalt.binaries.pictures.d
X.TP
X.BI \-D\ distribution
XSet the Distribution field in the header to the named distribution.
XDefault: world
X.TP
X.BI \-d\ descfile
XSpecifies a prepared description file. Use /dev/null for no description.
XIf
X.B \-d
Xis not specified, the user will be placed into the editor specified by the
XEDITOR evironment variable. If EDITOR is undefined, vi(1) will be used.
X.TP
X.BI \-t\ append_text
XAppends the given text to the subject line of each
Xarticle generated. Be sure to quote the text if it includes spaces.
X.TP
X.BI \-T\ prepend_text
XPrepends the given text to the subject line of each
Xarticle generated. Be sure to quote the text if it includes spaces.
X.TP
X.BI \-N\ count
XSpecifies the size, in lines, of the uuencoded pieces. If the
Xspecified count is zero, a single article containing the entire
Xuuencoded file will be sent. The default is 1000.
X.TP
X.BI \-F\ filename
XWhen uuencoding the standard input, use the specified filename as the
Xname the file should have when decoded. The default is the name
Xbinary.data. This option is ignored when not processing the standard
Xinput.
X.TP
X.BI \-S\ sleeptime
XSleep for the given number of seconds between each each posted article
Xto allow for sluggish article transport systems.
X.TP
X.BI \-k\ prefix
XSpecifies that the constructed messages are to be kept, one per file.
XThe file name is constructed from the given prefix, a dot, and the
Xsequence number. This is useful for keeping the constructed messages
Xshould a single message from the group need to be reposted.
X.TP
X.B \-nosend
XSpecifies that the constructed messages are not to be delivered. This
Xis useful for testing the script in combination with the "keep" option.
X.TP
X.B \-v
XOperate verbosely, printing out progress of the uuencoding and posting of
Xthe piece. This is the default.
X.TP
X.B \-q
XOperate quietly.
X.TP
X.B \-help
XPrint out a short summary of options.
X.SH EXAMPLES
X.LP
XWhen testing, it is often useful to post the image to a local newsgroup
Xwith a limited distribution. In this example the description file is
Xgiven as /dev/null, which results in no descriptive text at the
Xbeginning of each article (not recommended for wide distribution):
X.IP
Xpost-bin \-D utah -n utah.test -f utah.test \-d \\
X/dev/null \-t 'JPEG file of tree bark' bark.jpeg
X.LP
X.SH ENVIRONMENT
X.TP 20
X.B EDITOR
XThe name of the editor to use on the description file; defaults to vi.
X.SH FILES
X.TP 20
X.B /tmp/xx-$$-
XThe name of the split uuencoded pieces, appended with aa, ab, ac, etc.
X$$ refers to the process id of the shell script.
X.TP 20
X.B /tmp/xx-$$-article
XTemporary file for constructing the article.
X.TP 20
X.B /tmp/$$-description
XTemporary file used to contain the descriptive text.
X.SH SEE ALSO
X.BR mail-bin (1),
X.BR sh (1),
X.BR uuencode (1),
X.BR uudecode (1),
X.BR split (1),
X.BR unshar (1)
X.SH AUTHOR
XRich Thomson <rthomson@dsd.es.com>
X.br
XSoftware Engineer
X.br
XDesign Systems Division
X.br
XEvans & Sutherland Computer Corporation
X.SH COPYRIGHT
XCopyright (C) 1991, Evans & Sutherland Computer Corporation
X.SH DIAGNOSTICS
X.B Post-bin
Xwill complain about missing files and perform no action.
X.SH BUGS
XNone known.
END_OF_FILE
if test 6273 -ne `wc -c <'post-bin.1'`; then
echo shar: \"'post-bin.1'\" unpacked with wrong size!
fi
# end of 'post-bin.1'
fi
if test -f 'mail-bin.1' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'mail-bin.1'\"
else
echo shar: Extracting \"'mail-bin.1'\" \(6632 characters\)
sed "s/^X//" >'mail-bin.1' <<'END_OF_FILE'
X.TH MAIL-BIN 1 "2 May 1992" "" "Binary Tools"
X.\"
X.\" Copyright 1991 by Evans & Sutherland Computer Corporation,
X.\" Salt Lake City, Utah
X.\"
X.\" All Rights Reserved
X.\"
X.\" Permission to use, copy, modify, and distribute this software and its
X.\" documentation for any purpose and without fee is hereby granted,
X.\" provided that the above copyright notice appear in all copies and that
X.\" both that copyright notice and this permission notice appear in
X.\" supporting documentation, and that the names of Evans & Sutherland not be
X.\" used in advertising or publicity pertaining to distribution of the
X.\" software without specific, written prior permission.
X.\"
X.\" EVANS & SUTHERLAND DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
X.\" INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
X.\" EVENT SHALL EVANS & SUTHERLAND BE LIABLE FOR ANY SPECIAL, INDIRECT OR
X.\" CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
X.\" DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
X.\" TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
X.\" PERFORMANCE OF THIS SOFTWARE.
X.\"
X.SH NAME
Xmail-bin \- sanely mail a binary file to someone
X.SH SYNOPSIS
X.B mail-bin
X[
X.BI \-d\ descfile
X]
X[
X.BI \-t\ append_text
X]
X[
X.BI \-T\ prepend_text
X]
X[
X.B \-sysv
X]
X[
X.B \-bsd
X]
X[
X.BI \-N\ count
X]
X[
X.BI \-F\ filename
X]
X[
X.BI \-S\ sleeptime
X]
X[
X.BI \-k\ prefix
X]
X[
X.B \-nosend
X]
X[
X.B \-v
X]
X[
X.B \-q
X]
X[
X.B \-help
X]
X.I address
X[
X.IR filename .\|.\|.
X]
X.LP
X.SH DESCRIPTION
X.LP
X.B Mail-bin
Xreads the named files, or the standard input if no files are named,
Xuuencodes them, and splits the uuencoded files into pieces.
XEach piece is then mailed as a to the named recipient as a self-extracting
Xshell archive.
X.LP
XThe recipient then feeds the body of each message (the portion beginning
Xat the #!/bin/sh line) as the standard input to /bin/sh.
XIf the unshar program is available, it may be used to process each
Xmessage without any editing.
XThe received messages may be processed in any order (typically
Xthey do not arrive in the order sent). Once all pieces of a binary file
Xhave been processed, the shell archive automatically concatenates the
Xpieces in their proper order and uudecodes them. If the file was
Xsuccessfully uudecoded, the individual pieces are removed.
X.LP
XFor those without /bin/sh (or not running unix),
Xdecoding may be performed by removing the all text before/after the
Xlines beginning with the words BEGIN/END, respectively, in each
Xpiece. Then concatenate the pieces in the proper order and uudecode.
X.LP
XA description of the file, from the named description file or an
Xediting session if none is named, is placed at the beginning of each
Xmessage.
X.LP
XWhen sending large amounts of data, it is possible to overwhelm the
Xlocal mail delivery system (most notably sendmail). To accomodate for
Xthis,
X.B mail-bin
Xprovides an option to sleep between messages to allow for a sluggish
Xtransport system.
X.SH OPTIONS
X.TP
X.BI \-d\ descfile
XSpecifies a prepared description file. Use /dev/null for no description.
XIf
X.B \-d
Xis not specified, the user will be placed into the editor specified by the
XEDITOR evironment variable. If EDITOR is undefined, vi(1) will be used.
X.TP
X.BI \-t\ append_text
XAppends the given text to the subject line of each
Xarticle generated. Be sure to quote the text if it includes spaces.
X.TP
X.BI \-T\ prepend_text
XPrepends the given text to the subject line of each
Xarticle generated. Be sure to quote the text if it includes spaces.
X.TP
X.B \-sysv
XThis option tells
X.B mail-bin
Xthat
X.BR mail (1)
Xis a System V style mail program that expects To: and Subject: lines
Xon its standard input followed by a blank line and then the body of
Xthe message.
X.TP
X.B \-bsd
XThis option tells
X.B mail-bin
Xthat
X.BR mail (1)
Xis a BSD style mail program that expects the body of the message on
Xits standard input with the subject of the message specified with the
X-s option to
X.BR mail (1).
X.B Mail-bin
Xassumes a BSD style mailer by default.
X.TP
X.BI \-N\ count
XSpecifies the size, in lines, of the uuencoded pieces. If the
Xspecified count is zero, a single message containing the entire
Xuuencoded file will be sent. The default is 1000.
X.TP
X.BI \-F\ filename
XWhen uuencoding the standard input, use the specified filename as the
Xname the file should have when decoded. The default is the name
Xbinary.data. This option is ignored when not processing the standard
Xinput.
X.TP
X.BI \-S\ sleeptime
XSleep for the given number of seconds between each message
Xto allow for sluggish message transport systems (notably sendmail).
X.TP
X.BI \-k\ prefix
XSpecifies that the constructed messages are to be kept, one per file.
XThe file name is constructed from the given prefix, a dot, and the
Xsequence number. This is useful for keeping the constructed messages
Xshould a single message from the group need to be reposted.
X.TP
X.B \-nosend
XSpecifies that the constructed messages are not to be delivered. This
Xis useful for testing the script in combination with the "keep" option.
X.TP
X.B \-v
XOperate verbosely, printing out progress of the uuencoding and mailing of
Xthe piece. This is the default.
X.TP
X.B \-q
XOperate quietly.
X.TP
X.B \-help
XPrint out a short summary of options.
X.SH EXAMPLES
X.LP
XTo mail the binary file bark.jpeg to user baz@frobozz.com with the
Xannotation subject line "JPEG file of tree bark" and no descriptive text in
Xthe body of the message:
X.IP
Xmail-bin \-d /dev/null \-t 'JPEG file of tree bark' \\
Xbaz@frobozz.com bark.jpeg
X.LP
XTo mail a compressed tar archive of the directory foo to user
Xbaz@frobozz.com, sleeping 5 seconds between messages:
X.IP
Xtar cvf - foo | compress | mail-bin \-d /dev/null -F \\
Xfoo.tar.Z -S 5 baz@frobozz.com
X.SH ENVIRONMENT
X.TP 20
X.B EDITOR
XThe name of the editor to use on the description file; defaults to vi.
X.SH FILES
X.TP 20
X.B /tmp/xx-$$-
XThe name of the split uuencoded pieces, appended with aa, ab, ac, etc.
X$$ refers to the process id of the shell script.
X.TP 20
X.B /tmp/xx-$$-message
XTemporary file for constructing the message body.
X.TP 20
X.B /tmp/$$-description
XTemporary file used to contain the descriptive text.
X.SH SEE ALSO
X.BR post-bin (1),
X.BR sh (1),
X.BR uuencode (1),
X.BR uudecode (1),
X.BR split (1),
X.BR unshar (1)
X.SH AUTHOR
XRich Thomson <rthomson@dsd.es.com>
X.br
XSoftware Engineer
X.br
XDesign Systems Division
X.br
XEvans & Sutherland Computer Corporation
X.SH COPYRIGHT
XCopyright (C) 1991, Evans & Sutherland Computer Corporation
X.SH DIAGNOSTICS
X.B Mail-bin
Xwill complain about missing files and perform no action.
X.SH BUGS
XNone known.
END_OF_FILE
if test 6632 -ne `wc -c <'mail-bin.1'`; then
echo shar: \"'mail-bin.1'\" unpacked with wrong size!
fi
# end of 'mail-bin.1'
fi
echo shar: End of shell archive.
exit 0
exit 0 # Just in case...