1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Mindi subroutines brought by the MondoRescue project
|
---|
4 | #
|
---|
5 | # $Id$
|
---|
6 | #
|
---|
7 | # Copyright B. Cornec 2008
|
---|
8 | # Provided under the GPL v2
|
---|
9 |
|
---|
10 | package MandoRescue::Mindi;
|
---|
11 |
|
---|
12 | use strict 'vars';
|
---|
13 | use Data::Dumper;
|
---|
14 | use English;
|
---|
15 | use File::Basename;
|
---|
16 | use File::Copy;
|
---|
17 | use POSIX qw(strftime);
|
---|
18 | use lib qw (lib);
|
---|
19 | use ProjectBuilder::Base;
|
---|
20 | use ProjectBuilder::Conf;
|
---|
21 |
|
---|
22 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
23 |
|
---|
24 | use Exporter;
|
---|
25 |
|
---|
26 | # Export, by default, all the functions into the namespace of
|
---|
27 | # any code which uses this module.
|
---|
28 |
|
---|
29 | our @ISA = qw(Exporter);
|
---|
30 | our @EXPORT = qw(mr_lvm_check);
|
---|
31 |
|
---|
32 | =pod
|
---|
33 |
|
---|
34 | =head1 NAME
|
---|
35 |
|
---|
36 | MondoRescue::Mindi, part of the mondorescue.org
|
---|
37 |
|
---|
38 | =head1 DESCRIPTION
|
---|
39 |
|
---|
40 | This modules provides low level functions for the Mindi part of the Mondorescue project
|
---|
41 |
|
---|
42 | =head1 USAGE
|
---|
43 |
|
---|
44 | =over 4
|
---|
45 |
|
---|
46 | =item B<mr_lvm_check>
|
---|
47 |
|
---|
48 | This function checks the usage of LVM and gets the version used
|
---|
49 | It returns 2 parameters, the LVM version, and the lvm command to use if needed
|
---|
50 |
|
---|
51 | =cut
|
---|
52 |
|
---|
53 | sub mr_lvm_check {
|
---|
54 |
|
---|
55 | # Get them from a conf file instead
|
---|
56 | my $lvmds = "/usr/sbin/lvmdiskscan";
|
---|
57 | my $lvmproc = "/proc/lvm/global";
|
---|
58 | my $lvmcmd = "/usr/sbin/lvm";
|
---|
59 |
|
---|
60 | mr_exit(1,"$lvmproc doesn't exist.") if (! -x $lvmproc) ;
|
---|
61 |
|
---|
62 | # Check LVM volumes presence
|
---|
63 | open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc");
|
---|
64 | while (<LVM>) {
|
---|
65 | mr_exit(1,"No LVM volumes found in $lvmproc") if (/0 VGs 0 PVs 0 LVs/);
|
---|
66 | }
|
---|
67 | close(LVM);
|
---|
68 |
|
---|
69 | # Check LVM version
|
---|
70 | my $lvmver=0;
|
---|
71 | if (-x $lvmds ) {
|
---|
72 | open(LVM,"$lvmds --help 2>&1 |") || mr_exit(-1,"Unable to execute $lvmds");
|
---|
73 | while (<LVM>) {
|
---|
74 | if (/Logical Volume Manager/ || /LVM version:/) {
|
---|
75 | $lvmver = $_;
|
---|
76 | $lvmver =~ s/:([0-9])\..*/$1/;
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|
80 | close(LVM);
|
---|
81 |
|
---|
82 | if ($lvmver == 0) {
|
---|
83 | # Still not found
|
---|
84 | if (-x $lvmcmd) {
|
---|
85 | open(LVM,"$lvmcmd version |") || mr_exit(-1,"Unable to execute $lvmcmd");
|
---|
86 | while (<LVM>) {
|
---|
87 | if (/LVM version/) {
|
---|
88 | $lvmver = $_;
|
---|
89 | $lvmver =~ s/LVM version ([0-9])\..*/$1/;
|
---|
90 | }
|
---|
91 | }
|
---|
92 | close(LVM);
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | if ($lvmver == 0) {
|
---|
97 | # Still not found
|
---|
98 | mr_exit(-1,"Unable to determine LVM version.\nPlease report to the dev team with the result of the commands\n$lvmds and $lvmcmd version");
|
---|
99 | } elsif ($lvmver == 1) {
|
---|
100 | $lvmcmd = "";
|
---|
101 | }
|
---|
102 | pb_log(1,"Found LVM version $lvmver");
|
---|
103 | return ($lvmver,$lvmcmd);
|
---|
104 |
|
---|
105 | }
|
---|
106 |
|
---|
107 | =back
|
---|
108 |
|
---|
109 | =head1 WEB SITES
|
---|
110 |
|
---|
111 | The 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/>.
|
---|
112 |
|
---|
113 | =head1 USER MAILING LIST
|
---|
114 |
|
---|
115 | The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
|
---|
116 |
|
---|
117 | =head1 AUTHORS
|
---|
118 |
|
---|
119 | The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
---|
120 |
|
---|
121 | =head1 COPYRIGHT
|
---|
122 |
|
---|
123 | This module is distributed under the GPL v2.0 license
|
---|
124 | described in the file C<COPYING> included with the distribution.
|
---|
125 |
|
---|
126 |
|
---|
127 | =cut
|
---|
128 |
|
---|
129 | 1;
|
---|
130 |
|
---|