source: MondoRescue/devel/mr/lib/MondoRescue/Base.pm@ 2650

Last change on this file since 2650 was 2650, checked in by Bruno Cornec, 14 years ago

r3875@localhost: bruno | 2010-06-12 12:31:38 +0200

  • Review completely the installation process for mrmini, and first packages buildable
File size: 2.2 KB
Line 
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
10package MondoRescue::Base;
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;
21use MondoRescue::DynConf;
22
23# Inherit from the "Exporter" module which handles exporting functions.
24
25use Exporter;
26
27# Export, by default, all the functions into the namespace of
28# any code which uses this module.
29
30our @ISA = qw(Exporter);
31our @EXPORT = qw(mr_init mr_exit);
32
33=pod
34
35=head1 NAME
36
37MondoRescue::Base, part of the mondorescue.org
38
39=head1 DESCRIPTION
40
41This modules provides low level and generic functions for the Mondorescue project
42
43=head1 USAGE
44
45=over 4
46
47=item B<mr_init>
48
49This function initialize MondoRescue, point to the right conf files, setup stuff
50It takes 1 parameter, the message to print if needed
51
52=cut
53
54sub mr_init {
55
56my $msg = shift || "";
57
58if (defined $msg) {
59 pb_log($pbdebug,$msg);
60}
61
62
63# Get the various location determined at installation time
64my ($etcdir,$pbproj) = mr_dynconf_init();
65
66# Temp dir
67pb_temp_init();
68
69# First use the main configuration file
70pb_conf_init($pbproj);
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#
76open(MD5,"$etcdir/$pbproj.conf.dist.md5") || die "Unable to read mandatory $etcdir/$pbproj.conf.dist.md5: $!";
77my $omd5 = <MD5>;
78chop($omd5);
79close(MD5);
80open(CONF,"$etcdir/$pbproj.conf.dist") || die "Unable to read mandatory $etcdir/$pbproj.conf.dist: $!";
81my $md5 = Digest::MD5->new;
82binmode(CONF);
83$md5->addfile(CONF);
84die "Invalid MD5 found sum for $etcdir/$pbproj.conf.dist: $md5->hexdigest" if ($omd5 ne $md5->hexdigest);
85close(CONF);
86
87pb_conf_add("$etcdir/$pbproj.conf.dist");
88}
89
90=item B<mr_exit>
91
92This function closes opened files, clean up the environment and exits MondoRescue
93It takes 2 parameters, the exit code, and the message to print if needed
94
95=cut
96
97sub mr_exit {
98
99my $code = shift;
100my $msg = shift || "";
101
102if (defined $msg) {
103 pb_log($pbdebug,$msg);
104}
105die "ERROR returned\n" if ($code < 0);
106exit($code);
107}
Note: See TracBrowser for help on using the repository browser.