Code

Fix for regex input of '|', being output causing problems with Nagios' parsing of
[nagiosplug.git] / tools / build_perl_modules
1 #!/usr/bin/perl
2 # SYNTAX:
3 #       build_perl_modules -d dest_dir [-c] [-m] [-t] [-i] tarball_dir
4 #
5 # DESCRIPTION:
6 #       Installs perl modules found in tarball_dir
7 #       Expects a file called install_order, containing one line per distribution name
8 #       Will take action against each distribution in turn
9 #       -d is a necessary destination directory for the perl mods
10 #       If -c is set, will remove the module build directories and exit
11 #       If -m is set, will run perl Makefile.PL and make
12 #       If -t is set, will run make test
13 #       If -i is set, will run make install
14 #       Options are discrete. This is because an overall ./configure, make, make test, make install
15 #       are run in different invocations. Obviously, you can't run a -t without a -m, but there's no
16 #       checking here for that
18 # Can only use base modules
19 use warnings;
20 use strict;
21 use Config;
22 use Getopt::Std;
23 use Cwd;
24 use File::Path;
26 my $opts = {};
27 getopts('d:cmti', $opts) || die "Invalid options";
28 my $moddir = shift @ARGV or die "Must specify a directory where tarballs exist";
30 my $destdir = $opts->{d};
31 die "Must set a destination directory" unless $destdir;
33 chdir $moddir or die "Cannot change to $moddir";
34 open F, "install_order" or die "Cannot open install_order file";
35 my @files = grep { ! /^#/ && chop } <F>;
36 close F;
38 my @tarballs;
39 foreach my $f (@files) {
40         # Needs to be better. Also, what if there are two with same name?
41         my $tarball;
42         eval '$tarball = <'."$f".'*.tar.gz>';
43         die unless ($tarball);
44         print "Got $f, with file: $tarball",$/;
45         push @tarballs, $tarball;
46         (my $dir = $tarball) =~ s/\.tar.gz//;
47         # Need to do cleaning before doing each module in turn
48         if ($opts->{c}) {
49                 print "Cleaning $dir",$/;
50                 rmtree($dir);
51         }
52 }
54 if ($opts->{c}) {
55         print "Finished cleaning",$/;
56         exit;
57 }
59 my $topdir = cwd();
60 foreach my $tarball (@tarballs) {
61         (my $dir = $tarball) =~ s/\.tar.gz//;
62         if ($opts->{m}) {
63                 # Don't compile if already done - this is because of invocating this
64                 # script at different stages
65                 unless (-e $dir) {
66                         system("gunzip -c $tarball | tar -xf -") == 0 or die "Cannot extract $tarball";
67                         chdir $dir or die "Can't chdir into $dir";
68                         system("perl Makefile.PL PREFIX=$destdir INSTALLDIRS=site LIB=$destdir/lib") == 0 or die "Can't run perl Makefile.PL";
69                         system("make") == 0 or die "Can't run make";
70                         chdir $topdir or die "Can't chdir to top";;
71                 }
72         }
74         chdir $dir or die "Can't chdir into $dir";
76         # Need to add this so this module is found for subsequent ones
77         my @dirs = split(":", $ENV{PERL5LIB} || "");
78         unshift @dirs, "$topdir/$dir/blib/lib";
79         $ENV{PERL5LIB}=join(":", @dirs);
81         if ($opts->{t}) {
82                 system("make test") == 0 or die "Can't run make test failed";
83         }
84         if ($opts->{i}) {
85                 system("make install SITEPREFIX=$destdir") == 0 or die "Can't run make install";
86         }
87         chdir $topdir or die "Can't go back to $topdir";
88 }