[2149] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
| 3 | # Base subroutines brought by the MondoRescue project
|
---|
| 4 | #
|
---|
| 5 | # $Id$
|
---|
| 6 | #
|
---|
| 7 | # Copyright B. Cornec 2008
|
---|
| 8 | # Provided under the GPL v2
|
---|
| 9 |
|
---|
| 10 | package MondoRescue::Base;
|
---|
| 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;
|
---|
[2540] | 21 | use MondoRescue::DynConf;
|
---|
[2149] | 22 |
|
---|
| 23 | # Inherit from the "Exporter" module which handles exporting functions.
|
---|
| 24 |
|
---|
| 25 | use Exporter;
|
---|
| 26 |
|
---|
| 27 | # Export, by default, all the functions into the namespace of
|
---|
| 28 | # any code which uses this module.
|
---|
| 29 |
|
---|
| 30 | our @ISA = qw(Exporter);
|
---|
[2538] | 31 | our @EXPORT = qw(mr_init mr_exit);
|
---|
[2149] | 32 |
|
---|
| 33 | =pod
|
---|
| 34 |
|
---|
| 35 | =head1 NAME
|
---|
| 36 |
|
---|
| 37 | MondoRescue::Base, part of the mondorescue.org
|
---|
| 38 |
|
---|
| 39 | =head1 DESCRIPTION
|
---|
| 40 |
|
---|
| 41 | This modules provides low level and generic functions for the Mondorescue project
|
---|
| 42 |
|
---|
| 43 | =head1 USAGE
|
---|
| 44 |
|
---|
| 45 | =over 4
|
---|
| 46 |
|
---|
[2538] | 47 | =item B<mr_init>
|
---|
| 48 |
|
---|
| 49 | This function initialize MondoRescue, point to the right conf files, setup stuff
|
---|
| 50 | It takes 1 parameter, the message to print if needed
|
---|
| 51 |
|
---|
| 52 | =cut
|
---|
| 53 |
|
---|
[2540] | 54 | sub mr_init {
|
---|
[2538] | 55 |
|
---|
| 56 | my $msg = shift || "";
|
---|
| 57 |
|
---|
| 58 | if (defined $msg) {
|
---|
| 59 | pb_log($pbdebug,$msg);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
[2650] | 62 |
|
---|
[2539] | 63 | # Get the various location determined at installation time
|
---|
[2650] | 64 | my ($etcdir,$pbproj) = mr_dynconf_init();
|
---|
[2539] | 65 |
|
---|
[2541] | 66 | # Temp dir
|
---|
| 67 | pb_temp_init();
|
---|
| 68 |
|
---|
[2539] | 69 | # First use the main configuration file
|
---|
[2540] | 70 | pb_conf_init($pbproj);
|
---|
[2650] | 71 | #
|
---|
| 72 | # Conf files Management
|
---|
| 73 | # the $MRMINI_CONF/mondorescue.conf.dist is delivered as part of the project and
|
---|
| 74 | # its checksum is verified as we need good default values that we can trust
|
---|
| 75 | #
|
---|
| 76 | open(MD5,"$etcdir/$pbproj.conf.dist.md5") || die "Unable to read mandatory $etcdir/$pbproj.conf.dist.md5: $!";
|
---|
| 77 | my $omd5 = <MD5>;
|
---|
| 78 | chop($omd5);
|
---|
| 79 | close(MD5);
|
---|
| 80 | open(CONF,"$etcdir/$pbproj.conf.dist") || die "Unable to read mandatory $etcdir/$pbproj.conf.dist: $!";
|
---|
| 81 | my $md5 = Digest::MD5->new;
|
---|
| 82 | binmode(CONF);
|
---|
| 83 | $md5->addfile(CONF);
|
---|
| 84 | die "Invalid MD5 found sum for $etcdir/$pbproj.conf.dist: $md5->hexdigest" if ($omd5 ne $md5->hexdigest);
|
---|
| 85 | close(CONF);
|
---|
| 86 |
|
---|
| 87 | pb_conf_add("$etcdir/$pbproj.conf.dist");
|
---|
[2538] | 88 | }
|
---|
[2539] | 89 |
|
---|
[2149] | 90 | =item B<mr_exit>
|
---|
| 91 |
|
---|
| 92 | This function closes opened files, clean up the environment and exits MondoRescue
|
---|
| 93 | It takes 2 parameters, the exit code, and the message to print if needed
|
---|
| 94 |
|
---|
| 95 | =cut
|
---|
| 96 |
|
---|
| 97 | sub mr_exit {
|
---|
| 98 |
|
---|
| 99 | my $code = shift;
|
---|
| 100 | my $msg = shift || "";
|
---|
| 101 |
|
---|
| 102 | if (defined $msg) {
|
---|
| 103 | pb_log($pbdebug,$msg);
|
---|
| 104 | }
|
---|
| 105 | die "ERROR returned\n" if ($code < 0);
|
---|
| 106 | exit($code);
|
---|
| 107 | }
|
---|