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 |
|
---|
13 | use strict 'vars';
|
---|
14 | use Getopt::Long qw(:config auto_abbrev no_ignore_case);
|
---|
15 | use Data::Dumper;
|
---|
16 | use English;
|
---|
17 | use File::Basename;
|
---|
18 | use File::Copy;
|
---|
19 | use File::stat;
|
---|
20 | use Digest::MD5 qw(md5_hex);
|
---|
21 | use lib qw (lib);
|
---|
22 | use POSIX qw(strftime);
|
---|
23 | use ProjectBuilder::Base;
|
---|
24 | use ProjectBuilder::Conf;
|
---|
25 | use ProjectBuilder::Distribution;
|
---|
26 | use ProjectBuilder::Display;
|
---|
27 | use MondoRescue::Mindi::LVM;
|
---|
28 | use MondoRescue::Base;
|
---|
29 |
|
---|
30 | # Global variables
|
---|
31 | my %opts; # CLI Options
|
---|
32 | my @date = pb_get_date();
|
---|
33 | my $mr_date = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
34 |
|
---|
35 | =pod
|
---|
36 |
|
---|
37 | =head1 NAME
|
---|
38 |
|
---|
39 | Mindi - Tool to create a boot environment from a distribution
|
---|
40 |
|
---|
41 | =head1 DESCRIPTION
|
---|
42 |
|
---|
43 | B<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 |
|
---|
45 | For 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 |
|
---|
47 | The probably more frequent way of calling B<mindi> is non-interactively from mondoarchive(8) using a dedicated configuration file.
|
---|
48 |
|
---|
49 | =head1 SYNOPSIS
|
---|
50 |
|
---|
51 | mindi [-v]|[-q]|[-h]|[--man]
|
---|
52 |
|
---|
53 | =head1 OPTIONS
|
---|
54 |
|
---|
55 | =over 4
|
---|
56 |
|
---|
57 | =item B<-v|--verbose>
|
---|
58 |
|
---|
59 | Print a brief help message and exits.
|
---|
60 |
|
---|
61 | =item B<-q|--quiet>
|
---|
62 |
|
---|
63 | Do not print any output.
|
---|
64 |
|
---|
65 | =item B<-h|--help>
|
---|
66 |
|
---|
67 | Print a brief help message and exits.
|
---|
68 |
|
---|
69 | =item B<--man>
|
---|
70 |
|
---|
71 | Prints the manual page and exits.
|
---|
72 |
|
---|
73 | =item B<-i|--iso iso_image>
|
---|
74 |
|
---|
75 | Name of the ISO image you want to created.
|
---|
76 |
|
---|
77 | =back
|
---|
78 |
|
---|
79 | =head1 WEB SITES
|
---|
80 |
|
---|
81 | The 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 |
|
---|
85 | The miling list of the project is available at L<mailto:mondo@lists.sf.net>
|
---|
86 |
|
---|
87 | =head1 CONFIGURATION FILES
|
---|
88 |
|
---|
89 | The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
|
---|
90 |
|
---|
91 | Here 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 |
|
---|
99 | The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
---|
100 |
|
---|
101 | =head1 COPYRIGHT
|
---|
102 |
|
---|
103 | Mindi is distributed under the GPL v2.0 license
|
---|
104 | described in the file C<COPYING> included with the distribution.
|
---|
105 |
|
---|
106 | =cut
|
---|
107 |
|
---|
108 | # ---------------------------------------------------------------------------
|
---|
109 |
|
---|
110 | # Initialize the syntax string
|
---|
111 |
|
---|
112 | pb_syntax_init("mindi Version PBVER-rPBREV\n");
|
---|
113 | pb_display_init("text","");
|
---|
114 |
|
---|
115 | # Handle options
|
---|
116 | #
|
---|
117 | GetOptions("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
|
---|
132 | if (defined $opts{'h'}) {
|
---|
133 | pb_syntax(0,1);
|
---|
134 | }
|
---|
135 | if (defined $opts{'man'}) {
|
---|
136 | pb_syntax(0,2);
|
---|
137 | }
|
---|
138 | if (defined $opts{'p'}) {
|
---|
139 | pb_display("$ENV{$opts{'p'}}\n");
|
---|
140 | exit(0);
|
---|
141 | }
|
---|
142 |
|
---|
143 | if (defined $opts{'v'}) {
|
---|
144 | $pbdebug = $opts{'v'};
|
---|
145 | }
|
---|
146 |
|
---|
147 | my $force = 0;
|
---|
148 |
|
---|
149 | if (defined $opts{'f'}) {
|
---|
150 | $force=1;
|
---|
151 | }
|
---|
152 | if (defined $opts{'q'}) {
|
---|
153 | $pbdebug=-1;
|
---|
154 | }
|
---|
155 | my $iso;
|
---|
156 |
|
---|
157 | if (defined $opts{'i'}) {
|
---|
158 | $iso = $opts{'i'};
|
---|
159 | }
|
---|
160 |
|
---|
161 | #
|
---|
162 | # Global variables
|
---|
163 | #
|
---|
164 | my $MINDI_VERSION = "PBVER-rPBREV";
|
---|
165 | my $MINDI_PREFIX = "XXX";
|
---|
166 | my $MINDI_CONF = "YYY";
|
---|
167 | my $MINDI_LIB = "LLL";
|
---|
168 | my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
|
---|
169 | my $MINDI_FDISK = "$MINDI_SBIN/parted2fdik";
|
---|
170 | my $MINDI_DEPLIST = "$MINDI_CONF/deplist.d";
|
---|
171 | # Better ?
|
---|
172 | my $ARCH = `uname -m`;
|
---|
173 | chop($ARCH);
|
---|
174 |
|
---|
175 | #
|
---|
176 | # Temp dir
|
---|
177 | #
|
---|
178 | pb_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 | #
|
---|
185 | open(MD5,"$MINDI_CONF/mondorescue.conf.dist.md5") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist.md5: $!";
|
---|
186 | my $omd5 = <MD5>;
|
---|
187 | chop($omd5);
|
---|
188 | close(MD5);
|
---|
189 | open(CONF,"$MINDI_CONF/mondorescue.conf.dist") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist: $!";
|
---|
190 | my $md5 = Digest::MD5->new;
|
---|
191 | binmode(CONF);
|
---|
192 | $md5->addfile(CONF);
|
---|
193 | die "Invalid MD5 found sum for $MINDI_CONF/mondorescue.conf.dist: $md5->hexdigest" if ($omd5 ne $md5->hexdigest);
|
---|
194 | close(CONF);
|
---|
195 |
|
---|
196 | pb_conf_add("$ENV{'HOME'}/.mondorescuerc","$MINDI_CONF/mondorescue.conf","$MINDI_CONF/mondorescue.conf.dist");
|
---|
197 |
|
---|
198 | #
|
---|
199 | # Configuration parameters
|
---|
200 | #
|
---|
201 | $ENV{'PBPROJ'} = "mindi";
|
---|
202 | my ($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");
|
---|
203 | my ($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");
|
---|
204 | my ($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 | #
|
---|
209 | my $logfile = $mr_logfile->{$ENV{'PBPROJ'}};
|
---|
210 |
|
---|
211 | if (defined $opts{'l'}) {
|
---|
212 | $logfile = $opts{'l'};
|
---|
213 | }
|
---|
214 | open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
|
---|
215 | $pbLOG = \*pbLOG;
|
---|
216 | $pbdebug = 0 if ($pbdebug == -1);
|
---|
217 | pb_log_init($pbdebug, $pbLOG);
|
---|
218 |
|
---|
219 | pb_log(0,"mindi start date: $mr_date");
|
---|
220 | pb_log(0,"-------------------------------------");
|
---|
221 | pb_log(0,"mindi v$MINDI_VERSION");
|
---|
222 | pb_log(0,"$ARCH architecture detected");
|
---|
223 | pb_log(0,"mindi called with the following arguments: ".join(" ",@ARGV));
|
---|
224 | pb_log(0,"-------------------------------------");
|
---|
225 | pb_log(0,"MONDO_CACHE: $ENV{'MONDO_CACHE'}") if (defined $ENV{'MONDO_CACHE'});
|
---|
226 | pb_log(0,"MINDI_LIB: $MINDI_LIB");
|
---|
227 | pb_log(0,"MINDI_CONF: $MINDI_CONF");
|
---|
228 | pb_log(0,"MINDI_SBIN: $MINDI_SBIN");
|
---|
229 | if (-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 | }
|
---|
234 | if (-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 | }
|
---|
239 | pb_log(0,"-------------------------------------");
|
---|
240 |
|
---|
241 | #
|
---|
242 | # Prepare cache dir
|
---|
243 | #
|
---|
244 | pb_rm_rf("$mr_cache_dir/*");
|
---|
245 | pb_mkdir_p($mr_cache_dir);
|
---|
246 |
|
---|
247 | #
|
---|
248 | # LVM setup
|
---|
249 | #
|
---|
250 | my ($lvmver,$lvmcmd) = mr_lvm_check();
|
---|
251 |
|
---|
252 | pb_log(0,"LVM $lvmver command set to $lvmcmd");
|
---|
253 | pb_log(0,"-------------------------------------");
|
---|
254 | mr_exit(0);
|
---|