Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > better way to fetch and install packages than just a bunch of systemcalls?

Reply
Thread Tools

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

 
 
Ed
Guest
Posts: n/a
 
      08-21-2008
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
 
Reply With Quote
 
 
 
 
QoS@domain.invalid
Guest
Posts: n/a
 
      08-22-2008

Ed <(E-Mail Removed)> wrote in message-id: <(E-Mail Removed)>

>
> 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.


 
Reply With Quote
 
 
 
 
Eric Pozharski
Guest
Posts: n/a
 
      08-22-2008
Ed <(E-Mail Removed)> wrote:

*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.

--
Torvalds' goal for Linux is very simple: World Domination
 
Reply With Quote
 
Martijn Lievaart
Guest
Posts: n/a
 
      08-23-2008
On Fri, 22 Aug 2008 22:53:41 +0300, Eric Pozharski wrote:

> Ed <(E-Mail Removed)> wrote:
>> 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>.


Not all tars are GNU tars.

M4
 
Reply With Quote
 
Eric Pozharski
Guest
Posts: n/a
 
      08-23-2008
Martijn Lievaart <(E-Mail Removed)> wrote:
> On Fri, 22 Aug 2008 22:53:41 +0300, Eric Pozharski wrote:
>> Ed <(E-Mail Removed)> wrote:
>>> 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>.

> Not all tars are GNU tars.


I suppose it's about C<tar -z>, right? You won.

--
Torvalds' goal for Linux is very simple: World Domination
 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      08-24-2008
On Aug 21, 7:58 pm, (E-Mail Removed) wrote:
> Ed <(E-Mail Removed)> wrote in message-id: <(E-Mail Removed)>
>
> > 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.


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

Thanks,

Ed
 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      08-24-2008
On Aug 22, 1:53 pm, Eric Pozharski <(E-Mail Removed)> wrote:
> Ed <(E-Mail Removed)> wrote:
>
> *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.



Hmmmm? How do you mean unintuitive?

>
> *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.


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*
>
> > Any comments appreciated!

>
> Don't write shell in Perl.



What the heck does this mean?

Ed
 
Reply With Quote
 
Eric Pozharski
Guest
Posts: n/a
 
      08-24-2008
Ed <(E-Mail Removed)> wrote:
> On Aug 22, 1:53 pm, Eric Pozharski <(E-Mail Removed)> wrote:
>> Ed <(E-Mail Removed)> wrote:
>> > 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.

> 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*
>> Don't write shell in Perl.

> 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.

--
Torvalds' goal for Linux is very simple: World Domination
 
Reply With Quote
 
Eric Pozharski
Guest
Posts: n/a
 
      08-25-2008
Eric Pozharski <(E-Mail Removed)> wrote:
*SKIP*
>>> Don't write shell in Perl.

>> 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.


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:ipe;
$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; };

--
Torvalds' goal for Linux is very simple: World Domination
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to install local module other than in "site-packages"? Jive Dadson Python 14 01-18-2010 11:03 AM
GL2 better than the XLs? Consumer grade HDs better than pro-sumer Mini DVs? dh@. DVD Video 1 08-28-2008 07:20 PM
Is splint really better than lint? Is there a better tool than splint? Peter Bencsik C Programming 2 09-21-2006 10:02 PM
just shot a bunch of raw snow dmedhora@gmail.com Digital Photography 30 06-05-2006 02:42 AM



Advertisments