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

Discussion in 'Perl Misc' started by Ed, Aug 21, 2008.

  1. Ed

    Ed Guest

    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
    Ed, Aug 21, 2008
    #1
    1. Advertising

  2. Ed

    Guest

    Re: better way to fetch and install packages than just a bunch of system

    Ed <> wrote in message-id: <>

    >
    > 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.
    , Aug 22, 2008
    #2
    1. Advertising

  3. Re: better way to fetch and install packages than just a bunch of system ?calls?

    Ed <> 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
    Eric Pozharski, Aug 22, 2008
    #3
  4. Re: better way to fetch and install packages than just a bunch ofsystem ?calls?

    On Fri, 22 Aug 2008 22:53:41 +0300, Eric Pozharski wrote:

    > Ed <> 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
    Martijn Lievaart, Aug 23, 2008
    #4
  5. Re: better way to fetch and install packages than just a bunch of system ?calls?

    Martijn Lievaart <> wrote:
    > On Fri, 22 Aug 2008 22:53:41 +0300, Eric Pozharski wrote:
    >> Ed <> 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
    Eric Pozharski, Aug 23, 2008
    #5
  6. Ed

    Ed Guest

    Re: better way to fetch and install packages than just a bunch ofsystem

    On Aug 21, 7:58 pm, wrote:
    > Ed <> wrote in message-id: <>
    >
    > > 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
    Ed, Aug 24, 2008
    #6
  7. Ed

    Ed Guest

    Re: better way to fetch and install packages than just a bunch ofsystem ?calls?

    On Aug 22, 1:53 pm, Eric Pozharski <> wrote:
    > Ed <> 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
    Ed, Aug 24, 2008
    #7
  8. Re: better way to fetch and install packages than just a bunch of ?system ?calls?

    Ed <> wrote:
    > On Aug 22, 1:53 pm, Eric Pozharski <> wrote:
    >> Ed <> 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
    Eric Pozharski, Aug 24, 2008
    #8
  9. Re: better way to fetch and install packages than just a bunch of ?system ?calls?

    Eric Pozharski <> 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::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; };

    --
    Torvalds' goal for Linux is very simple: World Domination
    Eric Pozharski, Aug 25, 2008
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Bencsik
    Replies:
    2
    Views:
    805
  2. Guest
    Replies:
    1
    Views:
    360
    bruce barker
    Jun 16, 2007
  3. Jive Dadson
    Replies:
    14
    Views:
    607
    Dave Angel
    Jan 18, 2010
  4. Jack
    Replies:
    1
    Views:
    108
    J├╝rgen Exner
    Sep 13, 2008
  5. Replies:
    2
    Views:
    39
    Mark H Harris
    May 13, 2014
Loading...

Share This Page