#!/bin/csh -fb ############################################################################### ## uufiles (tar-compress and uuencode files for email (PG, 11/92, 10/94)) r## ############################################################################### # 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 [-gz] [-9] # 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 [.gz] uuencoded as name.uu) name: figures # specifying -gz -9 uses the slowest compression method (optimal compression) # single files are not tarred, just compressed and uuencoded ############################################################################### # if ("$1" != "-gz") then set gz=Z unc=uncompress gunzip=zcat gzip=(compress -f -c) echo "will use Z-compression (for gz-compression, specify uufiles -gz [-9])" else set gz=gz unc=gunzip gunzip="gunzip -c" gzip=(gzip $2 -f -c) echo will use gzip $2 to compress endif 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=$< set files=`cd $dir; glob $files` if (`echo $dir/$files | wc -w` == 1 && ! -d `echo $dir/$files`) then set dtar="" tar=cat name=$files:t set pname=$name:r echo single file. will create $name.$gz uuencoded as $pname.uu else echo -n "output file (will create name.tar.$gz uuencoded as name.uu) name: " set pname=$< set name=$pname:t dtar=".tar" tar="tar cf -" endif cat > $pname.uu << EOF #!/bin/csh -f # this uuencoded $gz-compressed $dtar file created by csh script uufiles # for more information, see e.g. http://xxx.lanl.gov/faq/uufaq.html # if you are on a unix machine this file will unpack itself: # strip off any mail header and call resulting file, e.g., $pname:t.uu # (uudecode ignores these header lines and starts at begin line below) # then say csh $pname:t.uu # or explicitly execute the commands (generally more secure): # uudecode $pname:t.uu ; $unc $name$dtar.$gz ; EOF if ("$dtar" != "") echo "# tar -xvf $name.tar" >> $pname.uu cat << EOF >> $pname.uu # on some non-unix (e.g. VAX/VMS), first use an editor to change the # filename in "begin" line below to $name${dtar}_$gz , then execute # uudecode $pname:t.uu # $gzip[1] -d $name${dtar}_$gz EOF if ("$dtar" != "") echo "# tar -xvf $name.tar" >> $pname.uu echo \# >> $pname.uu echo uudecode \$0 >> $pname.uu echo chmod 644 $name$dtar.$gz >> $pname.uu if ("$dtar" != "") then echo "$gunzip $name$dtar.$gz | tar -xvf -" >> $pname.uu echo rm \$0 $name$dtar.$gz >> $pname.uu else echo $unc $name$dtar.$gz >> $pname.uu echo rm \$0 >> $pname.uu endif echo exit >> $pname.uu echo "" >> $pname.uu echo "" echo " Switching to directory $dir and creating file $pname.uu from" (cd $dir; ls $files) (cd $dir; $tar $files) | $gzip | uuencode $name$dtar.$gz \ | sed -e '1s/^begin [0-7][0-7]* /begin 644 /' -e '2,$s/ /`/g' >> $pname.uu chmod 755 $pname.uu echo "" echo "finished. to invert: uudecode $pname.uu" if ( "$dtar" != "" ) then echo " $gunzip $name$dtar.$gz | tar -xvf - (or gnutar zxvf $name$dtar.$gz)" else echo " $unc $name$dtar.$gz " endif echo "or execute $pname.uu (which removes $pname.uu and $name$dtar.$gz)" exit