Documentation for used modules:#!/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__
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.
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Self Extracting Archives with Perl (almost)
by strredwolf (Chaplain) on Jan 21, 2001 at 11:35 UTC | |
by thoglette (Scribe) on Jan 22, 2001 at 08:02 UTC | |
Re: Self Extracting Archives with Perl (almost)
by Anonymous Monk on Jan 23, 2001 at 22:45 UTC | |
by Anonymous Monk on Jan 23, 2001 at 22:49 UTC | |
Re: Self Extracting Archives with Perl (almost)
by Anonymous Monk on Jan 26, 2001 at 01:05 UTC |