I run a small network of servers running the OpenNap server. We've been having some issues lately with script kiddies attacking the servers (we have 7 nodes at present), and it has become difficult to maintain homogeneity among the servers. So I decided I needed a good way to get files from the hub server (mine) to the nodes on the network in a uniform fashion. Since I cant assume that all the other server owners will be able to use rsync or cvs or bitkeeper or any of the other source-distribution systems, I began to wonder what the best way to get them these files was. Of course, I thought, use perl! So I thought, well, I can make a tarball, and uuencode it, and then send it out through a CGI program. But that leaves me with the problem that somebody may not be able to use UU(en|de)code or tar very aptly. These things happen, unfortunately. So since the tarball is uuencoded, I can actually stick it IN a perl program and use a heredoc to stuff it into a scalar, which can then be decompressed and everything. So I have created a script that creates a new script with the encoded information in it. It also adds relevent codelets to the new script so that it should be able to decode and detar its files. So Ill give you the code here, and then continue on below it:
#!/usr/bin/perl -w use strict; use IO::Scalar; use Convert::UU qw(uuencode uudecode); use Archive::Tar; sub slurp { local $/; my $fh = shift; open FH, $fh; $fh = <FH>; close +FH; return $fh; } my $textfile = "text"; my $binfile = "binary"; my $generated_code = "archive.pl"; my $tarball_name = "tb.tar"; my $uud_tarball_name = "new.tb.tar"; my $tarball = Archive::Tar -> new($tarball_name); $tarball -> add_files ($textfile, $binfile); $tarball -> write ($tarball_name); my $uu_data = slurp ($tarball_name); my $uue_data = uuencode ($uu_data); ##### ## here we are dealing with the generated file. # open CODE, ">$generated_code" or die "$!"; print CODE << 'CODE_LABEL'; #!/usr/bin/perl -w # automatically created perl code including UUencoded tarball. use strict; use IO::Scalar; use Convert::UU qw(uuencode uudecode); use Archive::Tar; my $encoded_tarball = << 'TARBALL_LABEL'; CODE_LABEL close CODE or die "not proceeding because we couldnt close CODE\n$!"; ##### ## here we have finished writing the initial code segments to # the generated file. { # because we are localizing $/ we dont want this to escape local $/; open CODE, ">>$generated_code" or die "unable to append to $generated_code : $!"; print CODE $uue_data; close CODE or die "error closing CODE\n$!"; } # we're done being foolish ##### ## we are now re-opening our generated code to append more code # to it so it can de-uu and de-tar its file. open CODE, ">>$generated_code" or die "unable to re-open CODE : $!"; print CODE << 'CODE_LABEL'; TARBALL_LABEL # begin decoding sequence... my $decoded_tarball = uudecode ($encoded_tarball); tie *BALL, 'IO::Scalar', \$decoded_tarball; my $uud_tarball_name = "tarball.decode.tar"; my $new_tarball = Archive::Tar -> new($uud_tarball_name); $new_tarball -> extract(\*BALL) or warn "error extract()ing : " . $new_tarball -> error(); CODE_LABEL __END__
Documentation for used modules:
IO::Scalar
Archive::Tar
Convert::UU

So. This actually does almost everything I want it to. It does choke, however, and doesnt extract the tarball. I think what I'm running into is a lack of understanding the way Archive::Tar works. I'm actually pretty stunned that the resulting code goes through perl -c without issues. The problem I'm having is that Archive::Tar isnt reporting any errors, and its not actually extracting the files. One thing of note here is that Archive::Tar lists an extract_files method in its documentation, but the extract method I found from looking through the source is much better. The filenames listed at the top are the first 10 lines from /usr/dict/words, and a copy of `which cat`. Relatively small files. Where do I go from here?

I have posted this in CUFP because, gee, this is one damn cool use for perl IMHO. This should even be portable to MacOS and Windows. One final plan I have for this script is to include some weak encryption so that I dont have to worry about script kiddies downloading our users database and hacking us. But given the large amount of encryption modules available for perl, that part shouldnt be very tough.

thanks, fellow monks.
dep.

Update:

I have stopped using Archive::Tar and Convert:UU. Both modules are fine examples of how to do very specific things. They however dont play very well together. Not using either of these modules means I dont really need to use IO::Scalar, either (although that has to be one of the coooooolest modules I have ever played with. Our own japhy suggested pack which does UUencoding all by itself and doesnt require an extra module.

An anonymous monk suggested using shar which I'm embarassed to admit I knew nothing about. It's a good idea except that it's not as portable as I'd like. Also, well, at this point I'm pretty attached to my idea and would like to keep this 100% perl. :)

I will post the full code when I'm done with it. I'm moving along.

--
i am not cool enough to have a signature.


In reply to Self Extracting Archives with Perl (almost) by deprecated

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.