summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2007-09-13 11:36:57 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2007-09-13 11:36:57 (GMT)
commit0708e6fa812387214ca1da00d8bad941a2ad5aff (patch)
tree6c544412e666c80a3600f8e33f6a466c714a3328 /tools
parent29d5acb7c821c8be23b32be9e01b242efad5b872 (diff)
downloadmonitoring-plugins-0708e6fa812387214ca1da00d8bad941a2ad5aff.tar.gz
Adding in optional Nagios::Plugin perl module (and
dependencies) compilation and installation git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1777 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'tools')
-rwxr-xr-xtools/build_perl_modules86
1 files changed, 86 insertions, 0 deletions
diff --git a/tools/build_perl_modules b/tools/build_perl_modules
new file mode 100755
index 0000000..fb47145
--- /dev/null
+++ b/tools/build_perl_modules
@@ -0,0 +1,86 @@
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
17
18# Can only use base modules
19use warnings;
20use strict;
21use Config;
22use Getopt::Std;
23use Cwd;
24use File::Path;
25
26my $opts = {};
27getopts('d:cmti', $opts) || die "Invalid options";
28my $moddir = shift @ARGV or die "Must specify a directory where tarballs exist";
29
30my $destdir = $opts->{d};
31die "Must set a destination directory" unless $destdir;
32
33chdir $moddir or die "Cannot change to $moddir";
34open F, "install_order" or die "Cannot open install_order file";
35my @files = grep { ! /^#/ && chop } <F>;
36close F;
37
38my @tarballs;
39foreach 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}
53
54if ($opts->{c}) {
55 print "Finished cleaning",$/;
56 exit;
57}
58
59my $topdir = cwd();
60foreach 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 }
73
74 chdir $dir or die "Can't chdir into $dir";
75
76 # Need to add this so this module is found for subsequent ones
77 $ENV{PERL5LIB}="$topdir/$dir/blib/lib:$ENV{PERL5LIB}";
78
79 if ($opts->{t}) {
80 system("make test") == 0 or die "Can't run make test failed";
81 }
82 if ($opts->{i}) {
83 system("make install SITEPREFIX=$destdir") == 0 or die "Can't run make install";
84 }
85 chdir $topdir or die "Can't go back to $topdir";
86}