#!/bin/csh -f
###############################################################################
#####   uufiles   (tar-compress and uuencode files for email (PG, 11/92)) #####
###############################################################################
# call this file uufiles (remember to chmod +x uufiles) and put it somewhere on
# your path. uuencoded file is executable with self-unpacking csh script at top
###############################################################################
# Usage: cd to directory where you want .uu file to be created, then say e.g.
# uufiles
# directory with files to be archived:  ~/mypaper
# files (e.g. *.ps, file1 file2 file3, or * for all): *.ps
# output file (will create name.tar.Z uuencoded as name.uu) name: figures
###############################################################################
#
echo -n "directory with files to be archived:  "
set dir=$<
if ("$dir" == "") set dir="."
if (! -d $dir) then
 echo no such directory
 exit
endif
echo -n "files (e.g. *.ps, file1 file2 file3, or * for all):  "
set files=$<
echo -n "output file (will create name.tar.Z uuencoded as name.uu) name:  "
set pname=$<
set name=$pname:t
cat > $pname.uu << EOF
#!/bin/csh -f
# Note: this uuencoded compressed tar file created by csh script  uufiles
# if you are on a unix machine this file will unpack itself:
# just strip off any mail header and call resulting file, e.g., $name.uu
# (uudecode will ignore these header lines and search for the begin line below)
# then say        csh $name.uu
# if you are not on a unix machine, you should explicitly execute the commands:
#    uudecode $name.uu;   uncompress $name.tar.Z;   tar -xvf $name.tar
#
uudecode \$0
chmod 644 $name.tar.Z
zcat $name.tar.Z | tar -xvf -
rm \$0 $name.tar.Z
exit

EOF
echo ""
echo " Switching to directory  $dir  and creating file  $pname.uu  from"
(cd $dir; ls $files)
(cd $dir; tar cf - $files) | compress -f -c | uuencode $name.tar.Z >> $pname.uu
chmod 755 $pname.uu
echo ""
echo "finished. to invert:  uudecode $name.uu;  zcat $name.tar.Z | tar -xvf - "
echo "or execute   $name.uu  (which removes $name.uu and $name.tar.Z)"
exit
