[2003] | 1 | #!/usr/bin/perl -w
|
---|
| 2 | #
|
---|
[2648] | 3 | # mrmini main application
|
---|
[2003] | 4 | # Mini-distribution maker for the MondoRescue project
|
---|
| 5 | #
|
---|
| 6 | # $Id$
|
---|
| 7 | #
|
---|
[2645] | 8 | # Copyright B. Cornec 2008-2010
|
---|
[2003] | 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);
|
---|
[2149] | 22 | use POSIX qw(strftime);
|
---|
[2003] | 23 | use ProjectBuilder::Base;
|
---|
| 24 | use ProjectBuilder::Conf;
|
---|
| 25 | use ProjectBuilder::Distribution;
|
---|
[2149] | 26 | use ProjectBuilder::Display;
|
---|
[2540] | 27 | use MondoRescue::LVM;
|
---|
[2149] | 28 | use MondoRescue::Base;
|
---|
[2659] | 29 | use MondoRescue::DynConf;
|
---|
| 30 | use MondoRescue::Mini::Base;
|
---|
[2003] | 31 |
|
---|
| 32 | =pod
|
---|
| 33 |
|
---|
| 34 | =head1 NAME
|
---|
| 35 |
|
---|
[2648] | 36 | mrmini - Tool to create a boot environment from a distribution
|
---|
[2003] | 37 |
|
---|
| 38 | =head1 DESCRIPTION
|
---|
| 39 |
|
---|
[2648] | 40 | 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.
|
---|
[2003] | 41 |
|
---|
[2648] | 42 | 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
|
---|
[2003] | 43 |
|
---|
[2648] | 44 | The probably more frequent way of calling B<mrmini> is non-interactively from mondoarchive(8) using a dedicated configuration file.
|
---|
[2003] | 45 |
|
---|
| 46 | =head1 SYNOPSIS
|
---|
| 47 |
|
---|
[2648] | 48 | mrmini [-v]|[-q]|[-h]|[--man]
|
---|
[2003] | 49 |
|
---|
| 50 | =head1 OPTIONS
|
---|
| 51 |
|
---|
[2645] | 52 | =cut
|
---|
| 53 |
|
---|
| 54 | # Handle options
|
---|
| 55 | #
|
---|
| 56 |
|
---|
[2650] | 57 | =pod
|
---|
[2003] | 58 | =over 4
|
---|
| 59 | =item B<-v|--verbose>
|
---|
| 60 |
|
---|
| 61 | Print a brief help message and exits.
|
---|
| 62 |
|
---|
| 63 | =item B<-q|--quiet>
|
---|
| 64 |
|
---|
| 65 | Do not print any output.
|
---|
| 66 |
|
---|
| 67 | =item B<-h|--help>
|
---|
| 68 |
|
---|
| 69 | Print a brief help message and exits.
|
---|
| 70 |
|
---|
| 71 | =item B<--man>
|
---|
| 72 |
|
---|
| 73 | Prints the manual page and exits.
|
---|
| 74 |
|
---|
| 75 | =item B<-i|--iso iso_image>
|
---|
| 76 |
|
---|
| 77 | Name of the ISO image you want to created.
|
---|
| 78 |
|
---|
[2645] | 79 | =item B<-u|--usb usb_device>
|
---|
| 80 |
|
---|
| 81 | Name of the USB device on which you want to created your image.
|
---|
| 82 |
|
---|
| 83 | =item B<-t|--tape tape_device>
|
---|
| 84 |
|
---|
| 85 | Name of the Tape device on which you want to created your image.
|
---|
| 86 |
|
---|
| 87 | =item B<-o|--obdr>
|
---|
| 88 |
|
---|
| 89 | Activate OBDR mode for tape (Bootable tape devices)
|
---|
| 90 |
|
---|
| 91 | =item B<-V|--version>
|
---|
| 92 |
|
---|
[2648] | 93 | Display mrmini version and exit
|
---|
[2645] | 94 |
|
---|
| 95 | =item B<-f|--force>
|
---|
| 96 |
|
---|
| 97 | Force usage of defaults parameters or values without asking questions
|
---|
| 98 |
|
---|
| 99 | =item B<-p|--printvars variable>
|
---|
| 100 |
|
---|
| 101 | Prints the value of the variable passed as parameter
|
---|
| 102 |
|
---|
| 103 | =cut
|
---|
[2659] | 104 |
|
---|
| 105 | # Global variables
|
---|
| 106 | my %opts; # CLI Options
|
---|
| 107 |
|
---|
[2650] | 108 | GetOptions(
|
---|
| 109 | "verbose|v+" => \$opts{'v'},
|
---|
| 110 | "quiet|q" => \$opts{'q'},
|
---|
| 111 | "help|?|h" => \$opts{'h'},
|
---|
| 112 | "man" => \$opts{'man'},
|
---|
| 113 | "iso|i=s" => \$opts{'i'},
|
---|
| 114 | "usb|u=s" => \$opts{'u'},
|
---|
| 115 | "tape|t=s" => \$opts{'t'},
|
---|
| 116 | "obdr|o" => \$opts{'o'},
|
---|
| 117 | "version|V" => \$opts{'V'},
|
---|
| 118 | "force|f" => \$opts{'f'},
|
---|
| 119 | "printvar|p=s" => \$opts{'p'},
|
---|
[2645] | 120 | "log-files|l=s" => \$opts{'l'},
|
---|
| 121 | ) || pb_syntax(-1,0);
|
---|
| 122 |
|
---|
[2650] | 123 | =pod
|
---|
[2003] | 124 | =back
|
---|
| 125 |
|
---|
| 126 | =head1 WEB SITES
|
---|
| 127 |
|
---|
| 128 | 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/>.
|
---|
| 129 |
|
---|
| 130 | =head1 USER MAILING LIST
|
---|
| 131 |
|
---|
| 132 | The miling list of the project is available at L<mailto:mondo@lists.sf.net>
|
---|
| 133 |
|
---|
| 134 | =head1 CONFIGURATION FILES
|
---|
| 135 |
|
---|
| 136 | The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
|
---|
| 137 |
|
---|
| 138 | Here is an example of such a configuration file:
|
---|
| 139 |
|
---|
| 140 | # mrcachedir points to the directory where the tool will store generated content
|
---|
[2648] | 141 | # If not defined, mrcachedir is under /var/cache/mrmini
|
---|
| 142 | mrcachedir mrmini = /var/cache/mrmini
|
---|
[2645] | 143 |
|
---|
[2648] | 144 | Also look at man mrmini.conf
|
---|
[2003] | 145 |
|
---|
| 146 | =head1 AUTHORS
|
---|
| 147 |
|
---|
| 148 | The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
---|
| 149 |
|
---|
| 150 | =head1 COPYRIGHT
|
---|
| 151 |
|
---|
[2648] | 152 | mrmini is distributed under the GPL v2.0 license
|
---|
[2003] | 153 | described in the file C<COPYING> included with the distribution.
|
---|
| 154 |
|
---|
| 155 | =cut
|
---|
| 156 |
|
---|
[2659] | 157 |
|
---|
| 158 |
|
---|
[2003] | 159 | # ---------------------------------------------------------------------------
|
---|
| 160 |
|
---|
[2667] | 161 | # Catch signals
|
---|
| 162 | $SIG{INT} = \&mr_exit;
|
---|
| 163 | $SIG{QUIT} = \&mr_exit;
|
---|
| 164 | $SIG{ABRT} = \&mr_exit;
|
---|
| 165 | $SIG{KILL} = \&mr_exit;
|
---|
| 166 | $SIG{TERM} = \&mr_exit;
|
---|
[2003] | 167 |
|
---|
[2659] | 168 | #
|
---|
| 169 | # Global variables
|
---|
| 170 | #
|
---|
[3110] | 171 | mr_init();
|
---|
[2659] | 172 | $ENV{'PBPKG'} = "mrmini";
|
---|
| 173 |
|
---|
| 174 | # Adds conf files in order
|
---|
| 175 | ($mr->{'install_dir'},$mr->{'version'}) = mr_conf_get("mr_install_dir","mr_version");
|
---|
| 176 |
|
---|
[2667] | 177 | # Initialize the syntax string
|
---|
[2659] | 178 | pb_syntax_init("$ENV{'PBPKG'} Version $mr->{'version'}\n");
|
---|
[2003] | 179 | pb_display_init("text","");
|
---|
| 180 |
|
---|
| 181 | # easy options
|
---|
| 182 | if (defined $opts{'h'}) {
|
---|
| 183 | pb_syntax(0,1);
|
---|
| 184 | }
|
---|
| 185 | if (defined $opts{'man'}) {
|
---|
| 186 | pb_syntax(0,2);
|
---|
| 187 | }
|
---|
| 188 | if (defined $opts{'p'}) {
|
---|
[3110] | 189 | print("$ENV{$opts{'p'}}\n");
|
---|
[2003] | 190 | exit(0);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | if (defined $opts{'v'}) {
|
---|
| 194 | $pbdebug = $opts{'v'};
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | my $force = 0;
|
---|
| 198 |
|
---|
| 199 | if (defined $opts{'f'}) {
|
---|
| 200 | $force=1;
|
---|
| 201 | }
|
---|
| 202 | if (defined $opts{'q'}) {
|
---|
| 203 | $pbdebug=-1;
|
---|
| 204 | }
|
---|
| 205 | my $iso;
|
---|
| 206 |
|
---|
| 207 | if (defined $opts{'i'}) {
|
---|
| 208 | $iso = $opts{'i'};
|
---|
| 209 | }
|
---|
[2659] | 210 | my $logfile = undef;
|
---|
[2003] | 211 | if (defined $opts{'l'}) {
|
---|
[2666] | 212 | # Log file forced externally
|
---|
[2003] | 213 | $logfile = $opts{'l'};
|
---|
[2666] | 214 | } elsif ($pbdebug ge 1) {
|
---|
| 215 | # Log file forced internally to default value as we are in debug mode
|
---|
| 216 | ($logfile) = mr_conf_get("mr_logfile");
|
---|
[2003] | 217 | }
|
---|
| 218 |
|
---|
[2666] | 219 | if (defined $logfile) {
|
---|
| 220 | open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
|
---|
| 221 | $mr->{'logdesc'} = \*pbLOG;
|
---|
| 222 | } else {
|
---|
| 223 | $mr->{'logdesc'} = undef;
|
---|
| 224 | }
|
---|
| 225 |
|
---|
[3110] | 226 | pb_log_init($pbdebug,$mr->{'logdesc'});
|
---|
[2666] | 227 | mr_mini_main();
|
---|
[2149] | 228 | mr_exit(0);
|
---|