source: MondoRescue/devel/mrmini/sbin/mrmini @ 2650

Last change on this file since 2650 was 2650, checked in by Bruno Cornec, 10 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: 6.9 KB
Line 
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
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
39mrmini - Tool to create a boot environment from a distribution
40
41=head1 DESCRIPTION
42
43B<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
45For 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
47The probably more frequent way of calling B<mrmini> is non-interactively from mondoarchive(8) using a dedicated configuration file.
48
49=head1 SYNOPSIS
50
51mrmini [-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
64Print a brief help message and exits.
65
66=item B<-q|--quiet>
67
68Do not print any output.
69
70=item B<-h|--help>
71
72Print a brief help message and exits.
73
74=item B<--man>
75
76Prints the manual page and exits.
77
78=item B<-i|--iso iso_image>
79
80Name of the ISO image you want to created.
81
82=item B<-u|--usb usb_device>
83
84Name of the USB device on which you want to created your image.
85
86=item B<-t|--tape tape_device>
87
88Name of the Tape device on which you want to created your image.
89
90=item B<-o|--obdr>
91
92Activate OBDR mode for tape (Bootable tape devices)
93
94=item B<-V|--version>
95
96Display mrmini version and exit
97
98=item B<-f|--force>
99
100Force usage of defaults parameters or values without asking questions
101
102=item B<-p|--printvars variable>
103
104Prints the value of the variable passed as parameter
105
106=cut
107GetOptions(
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
127The 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
131The miling list of the project is available at L<mailto:mondo@lists.sf.net>
132
133=head1 CONFIGURATION FILES
134
135The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
136
137Here 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
147The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
148
149=head1 COPYRIGHT
150
151mrmini is distributed under the GPL v2.0 license
152described in the file C<COPYING> included with the distribution.
153
154=cut
155
156# ---------------------------------------------------------------------------
157
158# Initialize the syntax string
159
160pb_syntax_init("mrmini Version PBVER-rPBREV\n");
161pb_display_init("text","");
162
163# easy options
164if (defined $opts{'h'}) {
165    pb_syntax(0,1);
166}
167if (defined $opts{'man'}) {
168    pb_syntax(0,2);
169}
170if (defined $opts{'p'}) {
171    pb_display("$ENV{$opts{'p'}}\n");
172    exit(0);
173}
174
175if (defined $opts{'v'}) {
176    $pbdebug = $opts{'v'};
177}
178
179my $force = 0;
180
181if (defined $opts{'f'}) {
182    $force=1;
183}
184if (defined $opts{'q'}) {
185    $pbdebug=-1;
186}
187my $iso;
188
189if (defined $opts{'i'}) {
190    $iso = $opts{'i'};
191}
192
193#
194# Global variables
195#
196my ($MRMINI_PREFIX,$MRMINI_CONF,$MRMINI_LIB) = mr_setup_var();
197my $MRMINI_VERSION = "PBVER-rPBREV";
198my $MRMINI_SBIN = "$MRMINI_PREFIX/sbin";
199my $MRMINI_FDISK = "$MRMINI_SBIN/parted2fdik";
200my $MRMINI_DEPLIST = "$MRMINI_CONF/deplist.d";
201# Better ?
202my $ARCH = `uname -m`;
203chop($ARCH);
204
205#
206# Temp dir
207#
208pb_temp_init();
209
210# Adds conf files in order
211pb_conf_add("$ENV{'HOME'}/.mondorescuerc","$MRMINI_CONF/mondorescue.conf");
212
213#
214# Configuration parameters
215#
216$ENV{'PBPROJ'} = "mrmini";
217my ($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");
218my ($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");
219my ($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#
224my $logfile = $mr_logfile->{$ENV{'PBPROJ'}};
225
226if (defined $opts{'l'}) {
227    $logfile = $opts{'l'};
228}
229open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
230$pbLOG = \*pbLOG;
231$pbdebug = 0  if ($pbdebug == -1);
232pb_log_init($pbdebug, $pbLOG);
233
234pb_log(0,"mrmini start date: $mr_date");
235pb_log(0,"-------------------------------------");
236pb_log(0,"mrmini v$MRMINI_VERSION");
237pb_log(0,"$ARCH architecture detected");
238pb_log(0,"mrmini called with the following arguments: ".join(" ",@ARGV));
239pb_log(0,"-------------------------------------");
240pb_log(0,"MONDO_CACHE: $ENV{'MONDO_CACHE'}") if (defined $ENV{'MONDO_CACHE'});
241pb_log(0,"MRMINI_LIB: $MRMINI_LIB");
242pb_log(0,"MRMINI_CONF: $MRMINI_CONF");
243pb_log(0,"MRMINI_SBIN: $MRMINI_SBIN");
244if (-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}
249if (-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}
254pb_log(0,"-------------------------------------");
255
256#
257# Prepare cache dir
258#
259pb_rm_rf("$mr_cache_dir/*");
260pb_mkdir_p($mr_cache_dir);
261
262#
263# LVM setup
264#
265my ($lvmver,$lvmcmd) = mr_lvm_check();
266
267pb_log(0,"LVM $lvmver command set to $lvmcmd");
268pb_log(0,"-------------------------------------");
269mr_exit(0);
Note: See TracBrowser for help on using the repository browser.