better way to fetch and install packages than just a bunch of systemcalls?

E

Ed

Howdy all!

As part of a test script, I have to make sure my test machine (i.e.
the machine that is running the script) has libraries zlib and hdf5. I
do that with this code. Is there a better way?

if ($opt{netcdf4} && ! -e $install_file) {
copy("/upc/share/ed/downloads/zlib-$
{zlib_version}.tar.gz", $hdf5dir) || die;
copy("/upc/share/ed/downloads/hdf5-$
{hdf5_version}.tar.gz", $hdf5dir) || die;
chdir($hdf5dir) || die;
system("gunzip -f zlib-${zlib_version}.tar.gz");
system("tar xf zlib-${zlib_version}.tar");
chdir("zlib-$zlib_version");
system("./configure --prefix=$hdf5dir");
system("make install");
chdir($hdf5dir);
system("rm -rf zlib-${zlib_version}*");
system("gunzip -f hdf5-${hdf5_version}.tar.gz");
system("tar xf hdf5-${hdf5_version}.tar");
chdir("hdf5-$hdf5_version");
system("./configure --prefix=$hdf5dir --with-zlib=$hdf5dir
--disable-shared");
system("make install");
chdir($hdf5dir);
system("rm -rf hdf5-${hdf5_version}*");
system("touch $install_file");
}

Any comments appreciated!

Thanks,

Ed
 
Q

QoS

Ed said:
Howdy all!

As part of a test script, I have to make sure my test machine (i.e.
the machine that is running the script) has libraries zlib and hdf5. I
do that with this code. Is there a better way?

if ($opt{netcdf4} && ! -e $install_file) {
copy("/upc/share/ed/downloads/zlib-$
{zlib_version}.tar.gz", $hdf5dir) || die;
copy("/upc/share/ed/downloads/hdf5-$
{hdf5_version}.tar.gz", $hdf5dir) || die;
chdir($hdf5dir) || die;
system("gunzip -f zlib-${zlib_version}.tar.gz");
system("tar xf zlib-${zlib_version}.tar");
chdir("zlib-$zlib_version");
system("./configure --prefix=$hdf5dir");
system("make install");
chdir($hdf5dir);
system("rm -rf zlib-${zlib_version}*");
system("gunzip -f hdf5-${hdf5_version}.tar.gz");
system("tar xf hdf5-${hdf5_version}.tar");
chdir("hdf5-$hdf5_version");
system("./configure --prefix=$hdf5dir --with-zlib=$hdf5dir
--disable-shared");
system("make install");
chdir($hdf5dir);
system("rm -rf hdf5-${hdf5_version}*");
system("touch $install_file");
}

Any comments appreciated!

Thanks,

Ed

Id not assume the functionality or existance of those utilities.

Perhaps putting your files into a __DATA__ block and then creating
the file would work on more systems.
 
E

Eric Pozharski

*SKIP*
copy("/upc/share/ed/downloads/zlib-$
{zlib_version}.tar.gz", $hdf5dir) || die;

In my experience B<File::Copy> has somewhat unintuitive notion of what
is error. You've better don't rely on that.

*SKIP*
system("gunzip -f zlib-${zlib_version}.tar.gz");
system("tar xf zlib-${zlib_version}.tar");

If my reading of F<changelog> of B<tar> is correct, than I'd guess that
B<tar> knows about B<gzip> sometime about Sep 2004. So
C<tar -xzf whatever.tgz> would do the same.

And why you copy archives? B<tar> will happily extract (if that's
possible, of course) from anywhere into I<cwd>.

*SKIP*
Any comments appreciated!

Don't write shell in Perl.
 
M

Martijn Lievaart

If my reading of F<changelog> of B<tar> is correct, than I'd guess that
B<tar> knows about B<gzip> sometime about Sep 2004. So C<tar -xzf
whatever.tgz> would do the same.

And why you copy archives? B<tar> will happily extract (if that's
possible, of course) from anywhere into I<cwd>.

Not all tars are GNU tars.

M4
 
E

Ed

Id not assume the functionality or existance of those utilities.

Perhaps putting your files into a __DATA__ block and then creating
the file would work on more systems.

No, these files are software source code packages...

Thanks,

Ed
 
E

Ed

*SKIP*


In my experience B<File::Copy> has somewhat unintuitive notion of what
is error. You've better don't rely on that.


Hmmmm? How do you mean unintuitive?
*SKIP*


If my reading of F<changelog> of B<tar> is correct, than I'd guess that
B<tar> knows about B<gzip> sometime about Sep 2004. So
C<tar -xzf whatever.tgz> would do the same.

Not all tars support this, unfortunately. GNU tar does.
And why you copy archives? B<tar> will happily extract (if that's
possible, of course) from anywhere into I<cwd>.


Hey, good point! Now why didn't I think of that?
*SKIP*


Don't write shell in Perl.


What the heck does this mean?

Ed
 
E

Eric Pozharski

Ed said:
Hmmmm? How do you mean unintuitive?

Some time ago I've used B<File::Copy> for caching (to and fro). I admit
that I've put it in circumstances it wasn't ready for (maybe).
L<File::Copy> says

All functions return 1 on success, 0 on failure. $! will be set
if an error was encountered.

A problem here is "What is failure?" (in B<File::Copy> sense). Right
now I've gave up on that. I promise, some time later I'm going to
figure out all the cases that B<File::Copy> considers to be a failure
and file bugreport (L<perlstyle> violation).

*SKIP*
What the heck does this mean?

That means exactly that.

That's shell:

cp ../x.tgz y.tar.gz
gunzip y.tar.gz
tar -x y.tar

That's shell written in Perl:

copy('../x.tgz', 'y.tar.gz');
system('gunzip y.tar.gz');
system('tar -x y.tar);

Tomorrow I'd write Perl in Perl section too. But right now I'm not
ready yet (if I'd dare, I'd be beaten hardly). So it's left as an
exercise for courious reader.
 
E

Eric Pozharski

Eric Pozharski said:
That means exactly that.
That's shell:
cp ../x.tgz y.tar.gz
gunzip y.tar.gz
tar -x y.tar
That's shell written in Perl:
copy('../x.tgz', 'y.tar.gz');
system('gunzip y.tar.gz');
system('tar -x y.tar);
Tomorrow I'd write Perl in Perl section too. But right now I'm not
ready yet (if I'd dare, I'd be beaten hardly). So it's left as an
exercise for courious reader.

I'm man of word, tomorrow is today, and I dare to be beaten hardly. So
a bit of excuses.

I have no option but B<IO::Zlib>. A problem with the modules is that it
B<isa> B<Tie::Handle> but B<IO::Handle>. That results in B<IPC::Run>,
B<IPC::Run3>, B<IPC::Open2>, B<IPC::Open3> won't work with it
(differently and unconditionally). And I'll need bzip2 some day.

sub read_compressed ($@) {
my $src = shift @_;
my @cmd = ( @_ );
split_debian_name($src)->{zipped} eq q|gz| or
die qq|anything but F<*.gz> is unsupported ($src)\n|;
my $gz = new IO::Zlib;
my $pipe = new IO::pipe;
$gz->open($src, q|rb|) or
die qq|can't open for reading ($src): $!\n|;
$pipe->writer(@cmd) or
die qq|can't setup ($cmd[0])\n|;
my($eof, $buf, $scan);
while($eof = $gz->read($buf, 4096)) {
do_status $src, ($scan += $eof);
defined $pipe->write($buf, 4096) or
die qq|can't pipe into ($cmd[0]): $!\n|; };
defined $eof or
die qq|can't read ($src): $!\n|;
do_status $src; };
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top