source: MondoRescue/devel/mrmini/sbin/mrmindi@ 2647

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

r3869@localhost: bruno | 2010-06-10 11:57:24 +0200

  • Change names in progress
File size: 7.7 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-2010
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=cut
56
57# Handle options
58#
59GetOptions(
60
61=over 4
62
63=cut
64 "verbose|v+" => \$opts{'v'},
65
66=item B<-v|--verbose>
67
68Print a brief help message and exits.
69
70=cut
71 "quiet|q" => \$opts{'q'},
72
73=item B<-q|--quiet>
74
75Do not print any output.
76
77=cut
78 "help|?|h" => \$opts{'h'},
79
80=item B<-h|--help>
81
82Print a brief help message and exits.
83
84=cut
85 "man" => \$opts{'man'},
86
87=item B<--man>
88
89Prints the manual page and exits.
90
91=cut
92 "iso|i=s" => \$opts{'i'},
93
94=item B<-i|--iso iso_image>
95
96Name of the ISO image you want to created.
97
98=cut
99 "usb|u=s" => \$opts{'u'},
100
101=item B<-u|--usb usb_device>
102
103Name of the USB device on which you want to created your image.
104
105=cut
106 "tape|t=s" => \$opts{'t'},
107
108=item B<-t|--tape tape_device>
109
110Name of the Tape device on which you want to created your image.
111
112=cut
113 "obdr|o" => \$opts{'o'},
114
115=item B<-o|--obdr>
116
117Activate OBDR mode for tape (Bootable tape devices)
118
119=cut
120 "version|V" => \$opts{'V'},
121
122=item B<-V|--version>
123
124Display mindi version and exit
125
126=cut
127 "force|f" => \$opts{'f'},
128
129=item B<-f|--force>
130
131Force usage of defaults parameters or values without asking questions
132
133=cut
134 "printvar|p=s" => \$opts{'p'},
135
136=item B<-p|--printvars variable>
137
138Prints the value of the variable passed as parameter
139
140=cut
141 "log-files|l=s" => \$opts{'l'},
142) || pb_syntax(-1,0);
143
144=back
145
146=head1 WEB SITES
147
148The 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/>.
149
150=head1 USER MAILING LIST
151
152The miling list of the project is available at L<mailto:mondo@lists.sf.net>
153
154=head1 CONFIGURATION FILES
155
156The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
157
158Here is an example of such a configuration file:
159
160 # mrcachedir points to the directory where the tool will store generated content
161 # If not defined, mrcachedir is under /var/cache/mindi
162 mrcachedir mindi = /var/cache/mindi
163
164 Also look at man mindi.conf
165
166=head1 AUTHORS
167
168The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
169
170=head1 COPYRIGHT
171
172Mindi is distributed under the GPL v2.0 license
173described in the file C<COPYING> included with the distribution.
174
175=cut
176
177# ---------------------------------------------------------------------------
178
179# Initialize the syntax string
180
181pb_syntax_init("mindi Version PBVER-rPBREV\n");
182pb_display_init("text","");
183
184# easy options
185if (defined $opts{'h'}) {
186 pb_syntax(0,1);
187}
188if (defined $opts{'man'}) {
189 pb_syntax(0,2);
190}
191if (defined $opts{'p'}) {
192 pb_display("$ENV{$opts{'p'}}\n");
193 exit(0);
194}
195
196if (defined $opts{'v'}) {
197 $pbdebug = $opts{'v'};
198}
199
200my $force = 0;
201
202if (defined $opts{'f'}) {
203 $force=1;
204}
205if (defined $opts{'q'}) {
206 $pbdebug=-1;
207}
208my $iso;
209
210if (defined $opts{'i'}) {
211 $iso = $opts{'i'};
212}
213
214#
215# Global variables
216#
217my $MINDI_VERSION = "PBVER-rPBREV";
218my $MINDI_PREFIX = "XXX";
219my $MINDI_CONF = "YYY";
220my $MINDI_LIB = "LLL";
221my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
222my $MINDI_FDISK = "$MINDI_SBIN/parted2fdik";
223my $MINDI_DEPLIST = "$MINDI_CONF/deplist.d";
224# Better ?
225my $ARCH = `uname -m`;
226chop($ARCH);
227
228#
229# Temp dir
230#
231pb_temp_init();
232
233#
234# Conf files Management
235# the $MINDI_CONF/mondorescue.conf.dist is delivered as part of the project and
236# its checksum is verified as we need good default values that we can trust
237#
238open(MD5,"$MINDI_CONF/mondorescue.conf.dist.md5") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist.md5: $!";
239my $omd5 = <MD5>;
240chop($omd5);
241close(MD5);
242open(CONF,"$MINDI_CONF/mondorescue.conf.dist") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist: $!";
243my $md5 = Digest::MD5->new;
244binmode(CONF);
245$md5->addfile(CONF);
246die "Invalid MD5 found sum for $MINDI_CONF/mondorescue.conf.dist: $md5->hexdigest" if ($omd5 ne $md5->hexdigest);
247close(CONF);
248
249# Adds conf files in order
250pb_conf_add("$ENV{'HOME'}/.mondorescuerc","$MINDI_CONF/mondorescue.conf","$MINDI_CONF/mondorescue.conf.dist");
251
252#
253# Configuration parameters
254#
255$ENV{'PBPROJ'} = "mindi";
256my ($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");
257my ($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");
258my ($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");
259
260#
261# Manage log file
262#
263my $logfile = $mr_logfile->{$ENV{'PBPROJ'}};
264
265if (defined $opts{'l'}) {
266 $logfile = $opts{'l'};
267}
268open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
269$pbLOG = \*pbLOG;
270$pbdebug = 0 if ($pbdebug == -1);
271pb_log_init($pbdebug, $pbLOG);
272
273pb_log(0,"mindi start date: $mr_date");
274pb_log(0,"-------------------------------------");
275pb_log(0,"mindi v$MINDI_VERSION");
276pb_log(0,"$ARCH architecture detected");
277pb_log(0,"mindi called with the following arguments: ".join(" ",@ARGV));
278pb_log(0,"-------------------------------------");
279pb_log(0,"MONDO_CACHE: $ENV{'MONDO_CACHE'}") if (defined $ENV{'MONDO_CACHE'});
280pb_log(0,"MINDI_LIB: $MINDI_LIB");
281pb_log(0,"MINDI_CONF: $MINDI_CONF");
282pb_log(0,"MINDI_SBIN: $MINDI_SBIN");
283if (-r "$ENV{'HOME'}/.mondorescuerc") {
284 pb_log(0,"-------------------------------------");
285 pb_log(0,"Conf file $ENV{'HOME'}/.mondorescuerc");
286 pb_display_file("$ENV{'HOME'}/.mondorescuerc");
287}
288if (-r "$MINDI_CONF/mondorescue.conf") {
289 pb_log(0,"-------------------------------------");
290 pb_log(0,"Conf file $MINDI_CONF/mondorescue.conf");
291 pb_display_file("$MINDI_CONF/mondorescue.conf");
292}
293pb_log(0,"-------------------------------------");
294
295#
296# Prepare cache dir
297#
298pb_rm_rf("$mr_cache_dir/*");
299pb_mkdir_p($mr_cache_dir);
300
301#
302# LVM setup
303#
304my ($lvmver,$lvmcmd) = mr_lvm_check();
305
306pb_log(0,"LVM $lvmver command set to $lvmcmd");
307pb_log(0,"-------------------------------------");
308mr_exit(0);
Note: See TracBrowser for help on using the repository browser.