1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # mrmini 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 |
|
---|
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::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 | mrmini - Tool to create a boot environment from a distribution
|
---|
40 |
|
---|
41 | =head1 DESCRIPTION
|
---|
42 |
|
---|
43 | B<mrmini> creates a bootable ISO/USB image using files from the system it runs on. B<mrmini> 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<mrmini> 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<mrmini> 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<mrmini> is working
|
---|
46 |
|
---|
47 | The probably more frequent way of calling B<mrmini> is non-interactively from mondoarchive(8) using a dedicated configuration file.
|
---|
48 |
|
---|
49 | =head1 SYNOPSIS
|
---|
50 |
|
---|
51 | mrmini [-v]|[-q]|[-h]|[--man]
|
---|
52 |
|
---|
53 | =head1 OPTIONS
|
---|
54 |
|
---|
55 | =cut
|
---|
56 |
|
---|
57 | # Handle options
|
---|
58 | #
|
---|
59 |
|
---|
60 | =pod
|
---|
61 | =over 4
|
---|
62 | =item B<-v|--verbose>
|
---|
63 |
|
---|
64 | Print a brief help message and exits.
|
---|
65 |
|
---|
66 | =item B<-q|--quiet>
|
---|
67 |
|
---|
68 | Do not print any output.
|
---|
69 |
|
---|
70 | =item B<-h|--help>
|
---|
71 |
|
---|
72 | Print a brief help message and exits.
|
---|
73 |
|
---|
74 | =item B<--man>
|
---|
75 |
|
---|
76 | Prints the manual page and exits.
|
---|
77 |
|
---|
78 | =item B<-i|--iso iso_image>
|
---|
79 |
|
---|
80 | Name of the ISO image you want to created.
|
---|
81 |
|
---|
82 | =item B<-u|--usb usb_device>
|
---|
83 |
|
---|
84 | Name of the USB device on which you want to created your image.
|
---|
85 |
|
---|
86 | =item B<-t|--tape tape_device>
|
---|
87 |
|
---|
88 | Name of the Tape device on which you want to created your image.
|
---|
89 |
|
---|
90 | =item B<-o|--obdr>
|
---|
91 |
|
---|
92 | Activate OBDR mode for tape (Bootable tape devices)
|
---|
93 |
|
---|
94 | =item B<-V|--version>
|
---|
95 |
|
---|
96 | Display mrmini version and exit
|
---|
97 |
|
---|
98 | =item B<-f|--force>
|
---|
99 |
|
---|
100 | Force usage of defaults parameters or values without asking questions
|
---|
101 |
|
---|
102 | =item B<-p|--printvars variable>
|
---|
103 |
|
---|
104 | Prints the value of the variable passed as parameter
|
---|
105 |
|
---|
106 | =cut
|
---|
107 | GetOptions(
|
---|
108 | "verbose|v+" => \$opts{'v'},
|
---|
109 | "quiet|q" => \$opts{'q'},
|
---|
110 | "help|?|h" => \$opts{'h'},
|
---|
111 | "man" => \$opts{'man'},
|
---|
112 | "iso|i=s" => \$opts{'i'},
|
---|
113 | "usb|u=s" => \$opts{'u'},
|
---|
114 | "tape|t=s" => \$opts{'t'},
|
---|
115 | "obdr|o" => \$opts{'o'},
|
---|
116 | "version|V" => \$opts{'V'},
|
---|
117 | "force|f" => \$opts{'f'},
|
---|
118 | "printvar|p=s" => \$opts{'p'},
|
---|
119 | "log-files|l=s" => \$opts{'l'},
|
---|
120 | ) || pb_syntax(-1,0);
|
---|
121 |
|
---|
122 | =pod
|
---|
123 | =back
|
---|
124 |
|
---|
125 | =head1 WEB SITES
|
---|
126 |
|
---|
127 | 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/>.
|
---|
128 |
|
---|
129 | =head1 USER MAILING LIST
|
---|
130 |
|
---|
131 | The miling list of the project is available at L<mailto:mondo@lists.sf.net>
|
---|
132 |
|
---|
133 | =head1 CONFIGURATION FILES
|
---|
134 |
|
---|
135 | The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
|
---|
136 |
|
---|
137 | Here is an example of such a configuration file:
|
---|
138 |
|
---|
139 | # mrcachedir points to the directory where the tool will store generated content
|
---|
140 | # If not defined, mrcachedir is under /var/cache/mrmini
|
---|
141 | mrcachedir mrmini = /var/cache/mrmini
|
---|
142 |
|
---|
143 | Also look at man mrmini.conf
|
---|
144 |
|
---|
145 | =head1 AUTHORS
|
---|
146 |
|
---|
147 | The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
---|
148 |
|
---|
149 | =head1 COPYRIGHT
|
---|
150 |
|
---|
151 | mrmini is distributed under the GPL v2.0 license
|
---|
152 | described in the file C<COPYING> included with the distribution.
|
---|
153 |
|
---|
154 | =cut
|
---|
155 |
|
---|
156 | # ---------------------------------------------------------------------------
|
---|
157 |
|
---|
158 | # Initialize the syntax string
|
---|
159 |
|
---|
160 | pb_syntax_init("mrmini Version PBVER-rPBREV\n");
|
---|
161 | pb_display_init("text","");
|
---|
162 |
|
---|
163 | # easy options
|
---|
164 | if (defined $opts{'h'}) {
|
---|
165 | pb_syntax(0,1);
|
---|
166 | }
|
---|
167 | if (defined $opts{'man'}) {
|
---|
168 | pb_syntax(0,2);
|
---|
169 | }
|
---|
170 | if (defined $opts{'p'}) {
|
---|
171 | pb_display("$ENV{$opts{'p'}}\n");
|
---|
172 | exit(0);
|
---|
173 | }
|
---|
174 |
|
---|
175 | if (defined $opts{'v'}) {
|
---|
176 | $pbdebug = $opts{'v'};
|
---|
177 | }
|
---|
178 |
|
---|
179 | my $force = 0;
|
---|
180 |
|
---|
181 | if (defined $opts{'f'}) {
|
---|
182 | $force=1;
|
---|
183 | }
|
---|
184 | if (defined $opts{'q'}) {
|
---|
185 | $pbdebug=-1;
|
---|
186 | }
|
---|
187 | my $iso;
|
---|
188 |
|
---|
189 | if (defined $opts{'i'}) {
|
---|
190 | $iso = $opts{'i'};
|
---|
191 | }
|
---|
192 |
|
---|
193 | #
|
---|
194 | # Global variables
|
---|
195 | #
|
---|
196 | my ($MRMINI_PREFIX,$MRMINI_CONF,$MRMINI_LIB) = mr_setup_var();
|
---|
197 | my $MRMINI_VERSION = "PBVER-rPBREV";
|
---|
198 | my $MRMINI_SBIN = "$MRMINI_PREFIX/sbin";
|
---|
199 | my $MRMINI_FDISK = "$MRMINI_SBIN/parted2fdik";
|
---|
200 | my $MRMINI_DEPLIST = "$MRMINI_CONF/deplist.d";
|
---|
201 | # Better ?
|
---|
202 | my $ARCH = `uname -m`;
|
---|
203 | chop($ARCH);
|
---|
204 |
|
---|
205 | #
|
---|
206 | # Temp dir
|
---|
207 | #
|
---|
208 | pb_temp_init();
|
---|
209 |
|
---|
210 | # Adds conf files in order
|
---|
211 | pb_conf_add("$ENV{'HOME'}/.mondorescuerc","$MRMINI_CONF/mondorescue.conf");
|
---|
212 |
|
---|
213 | #
|
---|
214 | # Configuration parameters
|
---|
215 | #
|
---|
216 | $ENV{'PBPROJ'} = "mrmini";
|
---|
217 | 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");
|
---|
218 | 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");
|
---|
219 | 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");
|
---|
220 |
|
---|
221 | #
|
---|
222 | # Manage log file
|
---|
223 | #
|
---|
224 | my $logfile = $mr_logfile->{$ENV{'PBPROJ'}};
|
---|
225 |
|
---|
226 | if (defined $opts{'l'}) {
|
---|
227 | $logfile = $opts{'l'};
|
---|
228 | }
|
---|
229 | open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
|
---|
230 | $pbLOG = \*pbLOG;
|
---|
231 | $pbdebug = 0 if ($pbdebug == -1);
|
---|
232 | pb_log_init($pbdebug, $pbLOG);
|
---|
233 |
|
---|
234 | pb_log(0,"mrmini start date: $mr_date");
|
---|
235 | pb_log(0,"-------------------------------------");
|
---|
236 | pb_log(0,"mrmini v$MRMINI_VERSION");
|
---|
237 | pb_log(0,"$ARCH architecture detected");
|
---|
238 | pb_log(0,"mrmini called with the following arguments: ".join(" ",@ARGV));
|
---|
239 | pb_log(0,"-------------------------------------");
|
---|
240 | pb_log(0,"MONDO_CACHE: $ENV{'MONDO_CACHE'}") if (defined $ENV{'MONDO_CACHE'});
|
---|
241 | pb_log(0,"MRMINI_LIB: $MRMINI_LIB");
|
---|
242 | pb_log(0,"MRMINI_CONF: $MRMINI_CONF");
|
---|
243 | pb_log(0,"MRMINI_SBIN: $MRMINI_SBIN");
|
---|
244 | if (-r "$ENV{'HOME'}/.mondorescuerc") {
|
---|
245 | pb_log(0,"-------------------------------------");
|
---|
246 | pb_log(0,"Conf file $ENV{'HOME'}/.mondorescuerc");
|
---|
247 | pb_display_file("$ENV{'HOME'}/.mondorescuerc");
|
---|
248 | }
|
---|
249 | if (-r "$MRMINI_CONF/mondorescue.conf") {
|
---|
250 | pb_log(0,"-------------------------------------");
|
---|
251 | pb_log(0,"Conf file $MRMINI_CONF/mondorescue.conf");
|
---|
252 | pb_display_file("$MRMINI_CONF/mondorescue.conf");
|
---|
253 | }
|
---|
254 | pb_log(0,"-------------------------------------");
|
---|
255 |
|
---|
256 | #
|
---|
257 | # Prepare cache dir
|
---|
258 | #
|
---|
259 | pb_rm_rf("$mr_cache_dir/*");
|
---|
260 | pb_mkdir_p($mr_cache_dir);
|
---|
261 |
|
---|
262 | #
|
---|
263 | # LVM setup
|
---|
264 | #
|
---|
265 | my ($lvmver,$lvmcmd) = mr_lvm_check();
|
---|
266 |
|
---|
267 | pb_log(0,"LVM $lvmver command set to $lvmcmd");
|
---|
268 | pb_log(0,"-------------------------------------");
|
---|
269 | mr_exit(0);
|
---|