| 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 |
|
|---|
| 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 | 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 | =cut
|
|---|
| 56 |
|
|---|
| 57 | # Handle options
|
|---|
| 58 | #
|
|---|
| 59 | GetOptions(
|
|---|
| 60 |
|
|---|
| 61 | =over 4
|
|---|
| 62 |
|
|---|
| 63 | =cut
|
|---|
| 64 | "verbose|v+" => \$opts{'v'},
|
|---|
| 65 |
|
|---|
| 66 | =item B<-v|--verbose>
|
|---|
| 67 |
|
|---|
| 68 | Print a brief help message and exits.
|
|---|
| 69 |
|
|---|
| 70 | =cut
|
|---|
| 71 | "quiet|q" => \$opts{'q'},
|
|---|
| 72 |
|
|---|
| 73 | =item B<-q|--quiet>
|
|---|
| 74 |
|
|---|
| 75 | Do not print any output.
|
|---|
| 76 |
|
|---|
| 77 | =cut
|
|---|
| 78 | "help|?|h" => \$opts{'h'},
|
|---|
| 79 |
|
|---|
| 80 | =item B<-h|--help>
|
|---|
| 81 |
|
|---|
| 82 | Print a brief help message and exits.
|
|---|
| 83 |
|
|---|
| 84 | =cut
|
|---|
| 85 | "man" => \$opts{'man'},
|
|---|
| 86 |
|
|---|
| 87 | =item B<--man>
|
|---|
| 88 |
|
|---|
| 89 | Prints the manual page and exits.
|
|---|
| 90 |
|
|---|
| 91 | =cut
|
|---|
| 92 | "iso|i=s" => \$opts{'i'},
|
|---|
| 93 |
|
|---|
| 94 | =item B<-i|--iso iso_image>
|
|---|
| 95 |
|
|---|
| 96 | Name 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 |
|
|---|
| 103 | Name 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 |
|
|---|
| 110 | Name 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 |
|
|---|
| 117 | Activate OBDR mode for tape (Bootable tape devices)
|
|---|
| 118 |
|
|---|
| 119 | =cut
|
|---|
| 120 | "version|V" => \$opts{'V'},
|
|---|
| 121 |
|
|---|
| 122 | =item B<-V|--version>
|
|---|
| 123 |
|
|---|
| 124 | Display mindi version and exit
|
|---|
| 125 |
|
|---|
| 126 | =cut
|
|---|
| 127 | "force|f" => \$opts{'f'},
|
|---|
| 128 |
|
|---|
| 129 | =item B<-f|--force>
|
|---|
| 130 |
|
|---|
| 131 | Force 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 |
|
|---|
| 138 | Prints 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 |
|
|---|
| 148 | 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/>.
|
|---|
| 149 |
|
|---|
| 150 | =head1 USER MAILING LIST
|
|---|
| 151 |
|
|---|
| 152 | The miling list of the project is available at L<mailto:mondo@lists.sf.net>
|
|---|
| 153 |
|
|---|
| 154 | =head1 CONFIGURATION FILES
|
|---|
| 155 |
|
|---|
| 156 | The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
|
|---|
| 157 |
|
|---|
| 158 | Here 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 |
|
|---|
| 168 | The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
|---|
| 169 |
|
|---|
| 170 | =head1 COPYRIGHT
|
|---|
| 171 |
|
|---|
| 172 | Mindi is distributed under the GPL v2.0 license
|
|---|
| 173 | described in the file C<COPYING> included with the distribution.
|
|---|
| 174 |
|
|---|
| 175 | =cut
|
|---|
| 176 |
|
|---|
| 177 | # ---------------------------------------------------------------------------
|
|---|
| 178 |
|
|---|
| 179 | # Initialize the syntax string
|
|---|
| 180 |
|
|---|
| 181 | pb_syntax_init("mindi Version PBVER-rPBREV\n");
|
|---|
| 182 | pb_display_init("text","");
|
|---|
| 183 |
|
|---|
| 184 | # easy options
|
|---|
| 185 | if (defined $opts{'h'}) {
|
|---|
| 186 | pb_syntax(0,1);
|
|---|
| 187 | }
|
|---|
| 188 | if (defined $opts{'man'}) {
|
|---|
| 189 | pb_syntax(0,2);
|
|---|
| 190 | }
|
|---|
| 191 | if (defined $opts{'p'}) {
|
|---|
| 192 | pb_display("$ENV{$opts{'p'}}\n");
|
|---|
| 193 | exit(0);
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | if (defined $opts{'v'}) {
|
|---|
| 197 | $pbdebug = $opts{'v'};
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | my $force = 0;
|
|---|
| 201 |
|
|---|
| 202 | if (defined $opts{'f'}) {
|
|---|
| 203 | $force=1;
|
|---|
| 204 | }
|
|---|
| 205 | if (defined $opts{'q'}) {
|
|---|
| 206 | $pbdebug=-1;
|
|---|
| 207 | }
|
|---|
| 208 | my $iso;
|
|---|
| 209 |
|
|---|
| 210 | if (defined $opts{'i'}) {
|
|---|
| 211 | $iso = $opts{'i'};
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | #
|
|---|
| 215 | # Global variables
|
|---|
| 216 | #
|
|---|
| 217 | my $MINDI_VERSION = "PBVER-rPBREV";
|
|---|
| 218 | my $MINDI_PREFIX = "XXX";
|
|---|
| 219 | my $MINDI_CONF = "YYY";
|
|---|
| 220 | my $MINDI_LIB = "LLL";
|
|---|
| 221 | my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
|
|---|
| 222 | my $MINDI_FDISK = "$MINDI_SBIN/parted2fdik";
|
|---|
| 223 | my $MINDI_DEPLIST = "$MINDI_CONF/deplist.d";
|
|---|
| 224 | # Better ?
|
|---|
| 225 | my $ARCH = `uname -m`;
|
|---|
| 226 | chop($ARCH);
|
|---|
| 227 |
|
|---|
| 228 | #
|
|---|
| 229 | # Temp dir
|
|---|
| 230 | #
|
|---|
| 231 | pb_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 | #
|
|---|
| 238 | open(MD5,"$MINDI_CONF/mondorescue.conf.dist.md5") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist.md5: $!";
|
|---|
| 239 | my $omd5 = <MD5>;
|
|---|
| 240 | chop($omd5);
|
|---|
| 241 | close(MD5);
|
|---|
| 242 | open(CONF,"$MINDI_CONF/mondorescue.conf.dist") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist: $!";
|
|---|
| 243 | my $md5 = Digest::MD5->new;
|
|---|
| 244 | binmode(CONF);
|
|---|
| 245 | $md5->addfile(CONF);
|
|---|
| 246 | die "Invalid MD5 found sum for $MINDI_CONF/mondorescue.conf.dist: $md5->hexdigest" if ($omd5 ne $md5->hexdigest);
|
|---|
| 247 | close(CONF);
|
|---|
| 248 |
|
|---|
| 249 | # Adds conf files in order
|
|---|
| 250 | pb_conf_add("$ENV{'HOME'}/.mondorescuerc","$MINDI_CONF/mondorescue.conf","$MINDI_CONF/mondorescue.conf.dist");
|
|---|
| 251 |
|
|---|
| 252 | #
|
|---|
| 253 | # Configuration parameters
|
|---|
| 254 | #
|
|---|
| 255 | $ENV{'PBPROJ'} = "mindi";
|
|---|
| 256 | 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");
|
|---|
| 257 | 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");
|
|---|
| 258 | 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");
|
|---|
| 259 |
|
|---|
| 260 | #
|
|---|
| 261 | # Manage log file
|
|---|
| 262 | #
|
|---|
| 263 | my $logfile = $mr_logfile->{$ENV{'PBPROJ'}};
|
|---|
| 264 |
|
|---|
| 265 | if (defined $opts{'l'}) {
|
|---|
| 266 | $logfile = $opts{'l'};
|
|---|
| 267 | }
|
|---|
| 268 | open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
|
|---|
| 269 | $pbLOG = \*pbLOG;
|
|---|
| 270 | $pbdebug = 0 if ($pbdebug == -1);
|
|---|
| 271 | pb_log_init($pbdebug, $pbLOG);
|
|---|
| 272 |
|
|---|
| 273 | pb_log(0,"mindi start date: $mr_date");
|
|---|
| 274 | pb_log(0,"-------------------------------------");
|
|---|
| 275 | pb_log(0,"mindi v$MINDI_VERSION");
|
|---|
| 276 | pb_log(0,"$ARCH architecture detected");
|
|---|
| 277 | pb_log(0,"mindi called with the following arguments: ".join(" ",@ARGV));
|
|---|
| 278 | pb_log(0,"-------------------------------------");
|
|---|
| 279 | pb_log(0,"MONDO_CACHE: $ENV{'MONDO_CACHE'}") if (defined $ENV{'MONDO_CACHE'});
|
|---|
| 280 | pb_log(0,"MINDI_LIB: $MINDI_LIB");
|
|---|
| 281 | pb_log(0,"MINDI_CONF: $MINDI_CONF");
|
|---|
| 282 | pb_log(0,"MINDI_SBIN: $MINDI_SBIN");
|
|---|
| 283 | if (-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 | }
|
|---|
| 288 | if (-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 | }
|
|---|
| 293 | pb_log(0,"-------------------------------------");
|
|---|
| 294 |
|
|---|
| 295 | #
|
|---|
| 296 | # Prepare cache dir
|
|---|
| 297 | #
|
|---|
| 298 | pb_rm_rf("$mr_cache_dir/*");
|
|---|
| 299 | pb_mkdir_p($mr_cache_dir);
|
|---|
| 300 |
|
|---|
| 301 | #
|
|---|
| 302 | # LVM setup
|
|---|
| 303 | #
|
|---|
| 304 | my ($lvmver,$lvmcmd) = mr_lvm_check();
|
|---|
| 305 |
|
|---|
| 306 | pb_log(0,"LVM $lvmver command set to $lvmcmd");
|
|---|
| 307 | pb_log(0,"-------------------------------------");
|
|---|
| 308 | mr_exit(0);
|
|---|