source: MondoRescue/branches/3.2/mindi/mindi-get-perl-modules@ 3586

Last change on this file since 3586 was 3473, checked in by Bruno Cornec, 9 years ago

Fix mindi-get-perl-modules to support symlinks

  • If perl has symlinks in its installation, mindi-get-perl-modules wasn't returning them. THis is now fixed by calling mr_file_read_all_link
  • Property svn:executable set to *
File size: 2.9 KB
Line 
1#!/usr/bin/perl -w
2#
3# $Id$
4# Copyright B. Cornec 2005-2013
5# Provided under the GPL v2
6#
7# Get perl modules required by mindi and mondo and that should be on the restore media
8#
9use strict;
10
11use MondoRescue::File;
12use Data::Dumper;
13use File::Basename;
14use ProjectBuilder::Base;
15use Getopt::Long qw(:config auto_abbrev no_ignore_case);
16use Module::ScanDeps;
17
18=pod
19
20=head1 NAME
21
22mindi-get-perl-modules keeps track of the perl modules that should be on your restore media
23
24=head1 DESCRIPTION
25
26mindi-get-perl-modules keeps track of the perl modules that should be on your restore media by analyzing the references made to them in the scripts passed as parameters and returning all the modules needed to have them work correctly.
27
28=head1 SYNOPSIS
29
30mindi-get-perl-modules /path/to/perl-script ...
31
32=head1 ARGUMENTS
33
34=over 4
35
36=item B</path/to/perl-script>
37
38This is the path of the perl script to analyze and for which we want its perl modules in dependence to be included
39
40=back
41
42=head1 WEB SITES
43
44The main Web site of the project is available at L<http://www.mondorescue.org>. Bug reports should be filled using the trac instance of the project at L<http://trac.mondorescue.org/>.
45
46=head1 USER MAILING LIST
47
48For community exchanges around MondoRescue please use the list L<http://sourceforge.net/mailarchive/forum.php?forum_name=mondo-devel>
49
50=head1 AUTHORS
51
52The MondoRescue team lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
53
54=head1 COPYRIGHT
55
56MondoRescue is distributed under the GPL v2.0 license or later,
57described in the file C<COPYING> included with the distribution.
58
59=cut
60
61# Globals
62my %files;
63my %found;
64my %opts;
65my @includes;
66my $req;
67GetOptions(
68 "verbose|v+" => \$opts{'v'},
69);
70
71pb_syntax_init("mindi-get-perl-modules Version PBVER-rPBREV\n");
72
73$pbdebug = $opts{'v'};
74$pbdebug = 0 if (not defined $pbdebug);
75
76if (not defined $ARGV[0]) {
77 pb_syntax();
78}
79
80pb_temp_init();
81
82# Adds missing modules not found automatically in certain cases
83#
84my $tmpf = "$ENV{'PBTMP'}/mgpm.$$.pl";
85
86open(TMPF,"> $tmpf") || die "Unable to create $tmpf: !$\n";
87print TMPF "# To include module corresponding to perl -w\n";
88print TMPF "use warnings;\n";
89print TMPF "# To include module used by Data:Dumper in a masked way for this script\n";
90print TMPF "use bytes;\n";
91print TMPF "# To prevent a bug with perl 5.10.0\n";
92print TMPF "use Tie::Hash::NamedCapture;\n";
93print TMPF "# To prevent a bug somewhere with scan_deps :-(\n";
94print TMPF "use lib;\n";
95close(TMPF);
96
97push @ARGV,$tmpf;
98
99my $h = scan_deps(
100 files => \@ARGV,
101 recurse => 1,
102 );
103
104unlink("$tmpf");
105
106my $h2;
107
108pb_log(1,"Returning:");
109pb_log(1,Dumper($h));
110pb_log(1,"-----------------------\n");
111# In case there are links in the perl installation
112foreach my $f (sort keys %$h) {
113 # Skip the temp file
114 next if ($h->{$f}->{'file'} =~ /$ENV{'PBTMP'}/);
115 my $file = mr_file_read_all_link($h->{$f}->{'file'});
116 foreach my $k (keys %$file) {
117 $h2->{$k} = "";
118 }
119}
120
121foreach my $f (sort keys %$h2) {
122 print "$f\n";
123}
124
125exit 0;
Note: See TracBrowser for help on using the repository browser.