source: devel/mindi/sbin/mindi @ 2540

Last change on this file since 2540 was 2540, checked in by bruno, 9 years ago

r3576@localhost: bruno | 2010-01-08 01:15:36 +0100
First set of correct split packages. Now need to work on content. mranalyze-lvm is now executable.

File size: 7.0 KB
Line 
1#!/usr/bin/perl -w
2#
3# Mindi main application
4# Mini-distribution maker for the MondoRescue project
5#
6# $Id$
7#
8# Copyright B. Cornec 2008
9# Provided under the GPL v2
10
11# Syntax: see below
12
13use strict 'vars';
14use Getopt::Long qw(:config auto_abbrev no_ignore_case);
15use Data::Dumper;
16use English;
17use File::Basename;
18use File::Copy;
19use File::stat;
20use Digest::MD5 qw(md5_hex);
21use lib qw (lib);
22use POSIX qw(strftime);
23use ProjectBuilder::Base;
24use ProjectBuilder::Conf;
25use ProjectBuilder::Distribution;
26use ProjectBuilder::Display;
27use MondoRescue::LVM;
28use MondoRescue::Base;
29
30# Global variables
31my %opts;                   # CLI Options
32my @date = pb_get_date();
33my $mr_date = strftime("%Y-%m-%d %H:%M:%S", @date);
34
35=pod
36
37=head1 NAME
38
39Mindi - Tool to create a boot environment from a distribution
40
41=head1 DESCRIPTION
42
43B<mindi> creates a bootable ISO/USB image using files from the system it runs on. B<mindi> will try hard to reproduce the environment of its host system including loaded modules to ensure that the system can be booted properly from the created rescue media. B<mindi> is used by monodarchive(8) to produce the required USB/ISO images but can also be used stand-alone.
44
45For stand-alone usage, B<mindi> may be called without any parameters or switches. It will then interactively ask the user for all information required to create a set of boot/root media. Options on the command line or a configuration file can also be used to alter the way B<mindi> is working
46
47The probably more frequent way of calling B<mindi> is non-interactively from mondoarchive(8) using a dedicated configuration file.
48
49=head1 SYNOPSIS
50
51mindi [-v]|[-q]|[-h]|[--man]
52
53=head1 OPTIONS
54
55=over 4
56
57=item B<-v|--verbose>
58
59Print a brief help message and exits.
60
61=item B<-q|--quiet>
62
63Do not print any output.
64
65=item B<-h|--help>
66
67Print a brief help message and exits.
68
69=item B<--man>
70
71Prints the manual page and exits.
72
73=item B<-i|--iso iso_image>
74
75Name of the ISO image you want to created.
76
77=back
78
79=head1 WEB SITES
80
81The 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/>.
82
83=head1 USER MAILING LIST
84
85The miling list of the project is available at L<mailto:mondo@lists.sf.net>
86
87=head1 CONFIGURATION FILES
88
89The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
90
91Here is an example of such a configuration file:
92
93 # mrcachedir points to the directory where the tool will store generated content
94 # If not defined, mrcachedir is under /var/cache/mindi
95 mrcachedir mindi = /var/cache/mindi
96 
97=head1 AUTHORS
98
99The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
100
101=head1 COPYRIGHT
102
103Mindi is distributed under the GPL v2.0 license
104described in the file C<COPYING> included with the distribution.
105
106=cut
107
108# ---------------------------------------------------------------------------
109
110# Initialize the syntax string
111
112pb_syntax_init("mindi Version PBVER-rPBREV\n");
113pb_display_init("text","");
114
115# Handle options
116#
117GetOptions("help|?|h" => \$opts{'h'}, 
118        "man" => \$opts{'man'},
119        "verbose|v+" => \$opts{'v'},
120        "quiet|q" => \$opts{'q'},
121        "log-files|l=s" => \$opts{'l'},
122        "force|f" => \$opts{'f'},
123        "iso|i=s" => \$opts{'i'},
124        "usb|u=s" => \$opts{'u'},
125        "tape|t=s" => \$opts{'t'},
126        "printvar|p=s" => \$opts{'p'},
127        "obdr|o" => \$opts{'o'},
128        "version|V" => \$opts{'V'},
129) || pb_syntax(-1,0);
130
131# easy options
132if (defined $opts{'h'}) {
133    pb_syntax(0,1);
134}
135if (defined $opts{'man'}) {
136    pb_syntax(0,2);
137}
138if (defined $opts{'p'}) {
139    pb_display("$ENV{$opts{'p'}}\n");
140    exit(0);
141}
142
143if (defined $opts{'v'}) {
144    $pbdebug = $opts{'v'};
145}
146
147my $force = 0;
148
149if (defined $opts{'f'}) {
150    $force=1;
151}
152if (defined $opts{'q'}) {
153    $pbdebug=-1;
154}
155my $iso;
156
157if (defined $opts{'i'}) {
158    $iso = $opts{'i'};
159}
160
161#
162# Global variables
163#
164my $MINDI_VERSION = "PBVER-rPBREV";
165my $MINDI_PREFIX = "XXX";
166my $MINDI_CONF = "YYY";
167my $MINDI_LIB = "LLL";
168my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
169my $MINDI_FDISK = "$MINDI_SBIN/parted2fdik";
170my $MINDI_DEPLIST = "$MINDI_CONF/deplist.d";
171# Better ?
172my $ARCH = `uname -m`;
173chop($ARCH);
174
175#
176# Temp dir
177#
178pb_temp_init();
179
180#
181# Conf files Management
182# the $MINDI_CONF/mondorescue.conf.dist is delivered as part of the project and
183# its checksum is verified as we need good default values that we can trust
184#
185open(MD5,"$MINDI_CONF/mondorescue.conf.dist.md5") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist.md5: $!";
186my $omd5 = <MD5>;
187chop($omd5);
188close(MD5);
189open(CONF,"$MINDI_CONF/mondorescue.conf.dist") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist: $!";
190my $md5 = Digest::MD5->new;
191binmode(CONF);
192$md5->addfile(CONF);
193die "Invalid MD5 found sum for $MINDI_CONF/mondorescue.conf.dist: $md5->hexdigest" if ($omd5 ne $md5->hexdigest);
194close(CONF);
195
196pb_conf_add("$ENV{'HOME'}/.mondorescuerc","$MINDI_CONF/mondorescue.conf","$MINDI_CONF/mondorescue.conf.dist");
197
198#
199# Configuration parameters
200#
201$ENV{'PBPROJ'} = "mindi";
202my ($mr_boot_size,$mr_boot_cd,$mr_boot_usb,$mr_boot_tape,$mr_kernel,$mr_fstab) =  pb_conf_get("mr_boot_size","mr_boot_cd","mr_boot_usb","mr_boot_tape","mr_kernel","mr_fstab");
203my ($mr_tape_mods,$mr_scsi_mods,$mr_ide_mods,$mr_pcmcia_mods,$mr_usb_mods,$mr_net_mods,$mr_cdrom_mods,$mr_deny_mods,$mr_force_mods) =  pb_conf_get("mr_tape_mods","mr_scsi_mods","mr_ide_mods","mr_pcmcia_mods","mr_usb_mods","mr_net_mods","mr_cdrom_mods","mr_extra_mods","mr_deny_mods","mr_force_mods");
204my ($mr_logfile,$mr_cache_dir,$mr_boot_msg,$mr_burn_cmd,$mr_burn_opt) = pb_conf_get("mr_logfile","mr_cache_dir","mr_boot_msg","mr_burn_cmd","mr_burn_opt");
205
206#
207# Manage log file
208#
209my $logfile = $mr_logfile->{$ENV{'PBPROJ'}};
210
211if (defined $opts{'l'}) {
212    $logfile = $opts{'l'};
213}
214open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
215$pbLOG = \*pbLOG;
216$pbdebug = 0  if ($pbdebug == -1);
217pb_log_init($pbdebug, $pbLOG);
218
219pb_log(0,"mindi start date: $mr_date");
220pb_log(0,"-------------------------------------");
221pb_log(0,"mindi v$MINDI_VERSION");
222pb_log(0,"$ARCH architecture detected");
223pb_log(0,"mindi called with the following arguments: ".join(" ",@ARGV));
224pb_log(0,"-------------------------------------");
225pb_log(0,"MONDO_CACHE: $ENV{'MONDO_CACHE'}") if (defined $ENV{'MONDO_CACHE'});
226pb_log(0,"MINDI_LIB: $MINDI_LIB");
227pb_log(0,"MINDI_CONF: $MINDI_CONF");
228pb_log(0,"MINDI_SBIN: $MINDI_SBIN");
229if (-r "$ENV{'HOME'}/.mondorescuerc") {
230    pb_log(0,"-------------------------------------");
231    pb_log(0,"Conf file $ENV{'HOME'}/.mondorescuerc");
232    pb_display_file("$ENV{'HOME'}/.mondorescuerc");
233}
234if (-r "$MINDI_CONF/mondorescue.conf") {
235    pb_log(0,"-------------------------------------");
236    pb_log(0,"Conf file $MINDI_CONF/mondorescue.conf");
237    pb_display_file("$MINDI_CONF/mondorescue.conf");
238}
239pb_log(0,"-------------------------------------");
240
241#
242# Prepare cache dir
243#
244pb_rm_rf("$mr_cache_dir/*");
245pb_mkdir_p($mr_cache_dir);
246
247#
248# LVM setup
249#
250my ($lvmver,$lvmcmd) = mr_lvm_check();
251
252pb_log(0,"LVM $lvmver command set to $lvmcmd");
253pb_log(0,"-------------------------------------");
254mr_exit(0);
Note: See TracBrowser for help on using the repository browser.