[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 |
|
---|
[2539] | 62 | # Get the various location determined at installation time
|
---|
[2540] | 63 | my ($confdir,$localdir,$pbproj) = mr_dynconf_init();
|
---|
[2539] | 64 |
|
---|
[2541] | 65 | # Temp dir
|
---|
| 66 | pb_temp_init();
|
---|
| 67 |
|
---|
[2539] | 68 | # First use the main configuration file
|
---|
[2540] | 69 | pb_conf_init($pbproj);
|
---|
| 70 | pb_conf_add("$confdir/$pbproj.conf");
|
---|
[2538] | 71 | }
|
---|
[2539] | 72 |
|
---|
[2149] | 73 | =item B<mr_exit>
|
---|
| 74 |
|
---|
| 75 | This function closes opened files, clean up the environment and exits MondoRescue
|
---|
| 76 | It takes 2 parameters, the exit code, and the message to print if needed
|
---|
| 77 |
|
---|
| 78 | =cut
|
---|
| 79 |
|
---|
| 80 | sub mr_exit {
|
---|
| 81 |
|
---|
| 82 | my $code = shift;
|
---|
| 83 | my $msg = shift || "";
|
---|
| 84 |
|
---|
| 85 | if (defined $msg) {
|
---|
| 86 | pb_log($pbdebug,$msg);
|
---|
| 87 | }
|
---|
| 88 | die "ERROR returned\n" if ($code < 0);
|
---|
| 89 | exit($code);
|
---|
| 90 | }
|
---|