source: devel/mindi/lib/MondoRescue/Mindi.pm @ 2118

Last change on this file since 2118 was 2118, checked in by Bruno Cornec, 12 years ago

Adds perl mindi module

File size: 2.7 KB
Line 
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
10package MandoRescue::Mindi;
11
12use strict 'vars';
13use Data::Dumper;
14use English;
15use File::Basename;
16use File::Copy;
17use POSIX qw(strftime);
18use lib qw (lib);
19use ProjectBuilder::Base;
20use ProjectBuilder::Conf;
21
22# Inherit from the "Exporter" module which handles exporting functions.
23
24use Exporter;
25
26# Export, by default, all the functions into the namespace of
27# any code which uses this module.
28
29our @ISA = qw(Exporter);
30our @EXPORT = qw(mr_lvm_check);
31
32=pod
33
34=head1 NAME
35
36MondoRescue::Mindi, part of the mondorescue.org
37
38=head1 DESCRIPTION
39
40This 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
48This function checks the usage of LVM and gets the version used
49It returns 2 parameters, the LVM version, and the lvm command to use if needed
50
51=cut
52
53sub mr_lvm_check {
54
55# Get them from a conf file instead
56my $lvmds = "/usr/sbin/lvmdiskscan";
57my $lvmproc = "/proc/lvm/global";
58my $lvmcmd = "/usr/sbin/lvm";
59
60mr_exit(1,"$lvmproc doesn't exist.") if (! -x $lvmproc) ;
61
62# Check LVM volumes presence
63open(LVM,$lvmproc) || mr_exit(-1,"Unable to open $lvmproc");
64while (<LVM>) {
65    mr_exit(1,"No LVM volumes found in $lvmproc") if (/0 VGs 0 PVs 0 LVs/);
66}
67close(LVM);
68
69# Check LVM version
70my $lvmver=0;
71if (-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}
80close(LVM);
81
82if ($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
96if ($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}
102pb_log(1,"Found LVM version $lvmver");
103return ($lvmver,$lvmcmd);
104
105}
106
107=back
108
109=head1 WEB SITES
110
111The 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
115The mailing list of the project is available at L<mailto:mondo@lists.sf.net>
116 
117=head1 AUTHORS
118
119The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
120
121=head1 COPYRIGHT
122
123This module is distributed under the GPL v2.0 license
124described in the file C<COPYING> included with the distribution.
125
126
127=cut
128
1291;
130
Note: See TracBrowser for help on using the repository browser.