[2003] | 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 File::Temp qw(tempdir);
|
---|
| 21 | use POSIX qw(strftime);
|
---|
| 22 | use Digest::MD5 qw(md5_hex);
|
---|
| 23 | use lib qw (lib);
|
---|
| 24 | use ProjectBuilder::Base;
|
---|
| 25 | use ProjectBuilder::Conf;
|
---|
| 26 | use ProjectBuilder::Distribution;
|
---|
| 27 |
|
---|
| 28 | # Global variables
|
---|
| 29 | my %opts; # CLI Options
|
---|
| 30 | my @date = pb_get_date();
|
---|
| 31 | my $mr_date = strftime("%Y-%m-%d %H:%M:%S", @date);
|
---|
| 32 |
|
---|
| 33 | =pod
|
---|
| 34 |
|
---|
| 35 | =head1 NAME
|
---|
| 36 |
|
---|
| 37 | Mindi - Tool to create a boot environment from a distribution
|
---|
| 38 |
|
---|
| 39 | =head1 DESCRIPTION
|
---|
| 40 |
|
---|
| 41 | 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.
|
---|
| 42 |
|
---|
| 43 | 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
|
---|
| 44 |
|
---|
| 45 | The probably more frequent way of calling B<mindi> is non-interactively from mondoarchive(8) using a dedicated configuration file.
|
---|
| 46 |
|
---|
| 47 | =head1 SYNOPSIS
|
---|
| 48 |
|
---|
| 49 | mindi [-v]|[-q]|[-h]|[--man]
|
---|
| 50 |
|
---|
| 51 | =head1 OPTIONS
|
---|
| 52 |
|
---|
| 53 | =over 4
|
---|
| 54 |
|
---|
| 55 | =item B<-v|--verbose>
|
---|
| 56 |
|
---|
| 57 | Print a brief help message and exits.
|
---|
| 58 |
|
---|
| 59 | =item B<-q|--quiet>
|
---|
| 60 |
|
---|
| 61 | Do not print any output.
|
---|
| 62 |
|
---|
| 63 | =item B<-h|--help>
|
---|
| 64 |
|
---|
| 65 | Print a brief help message and exits.
|
---|
| 66 |
|
---|
| 67 | =item B<--man>
|
---|
| 68 |
|
---|
| 69 | Prints the manual page and exits.
|
---|
| 70 |
|
---|
| 71 | =item B<-i|--iso iso_image>
|
---|
| 72 |
|
---|
| 73 | Name of the ISO image you want to created.
|
---|
| 74 |
|
---|
| 75 | =back
|
---|
| 76 |
|
---|
| 77 | =head1 WEB SITES
|
---|
| 78 |
|
---|
| 79 | 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/>.
|
---|
| 80 |
|
---|
| 81 | =head1 USER MAILING LIST
|
---|
| 82 |
|
---|
| 83 | The miling list of the project is available at L<mailto:mondo@lists.sf.net>
|
---|
| 84 |
|
---|
| 85 | =head1 CONFIGURATION FILES
|
---|
| 86 |
|
---|
| 87 | The system administrator may have a configuration file in F<$HOME/.mondorescue>. The values in this file may overwrite any other configuration file value.
|
---|
| 88 |
|
---|
| 89 | Here is an example of such a configuration file:
|
---|
| 90 |
|
---|
| 91 | # mrcachedir points to the directory where the tool will store generated content
|
---|
| 92 | # If not defined, mrcachedir is under /var/cache/mindi
|
---|
| 93 | mrcachedir mindi = /var/cache/mindi
|
---|
| 94 |
|
---|
| 95 | =head1 AUTHORS
|
---|
| 96 |
|
---|
| 97 | The Mondorescue.org team L<http://www.mondorescue.org/> lead by Bruno Cornec L<mailto:bruno@mondorescue.org>.
|
---|
| 98 |
|
---|
| 99 | =head1 COPYRIGHT
|
---|
| 100 |
|
---|
| 101 | Mindi is distributed under the GPL v2.0 license
|
---|
| 102 | described in the file C<COPYING> included with the distribution.
|
---|
| 103 |
|
---|
| 104 | =cut
|
---|
| 105 |
|
---|
| 106 | # ---------------------------------------------------------------------------
|
---|
| 107 |
|
---|
| 108 | # Initialize the syntax string
|
---|
| 109 |
|
---|
| 110 | pb_syntax_init("mindi Version PBVER-rPBREV\n");
|
---|
| 111 | pb_display_init("text","");
|
---|
| 112 |
|
---|
| 113 | # Handle options
|
---|
| 114 | #
|
---|
| 115 | GetOptions("help|?|h" => \$opts{'h'},
|
---|
| 116 | "man" => \$opts{'man'},
|
---|
| 117 | "verbose|v+" => \$opts{'v'},
|
---|
| 118 | "quiet|q" => \$opts{'q'},
|
---|
| 119 | "log-files|l=s" => \$opts{'l'},
|
---|
| 120 | "force|f" => \$opts{'f'},
|
---|
| 121 | "iso|i=s" => \$opts{'i'},
|
---|
| 122 | "usb|u=s" => \$opts{'u'},
|
---|
| 123 | "tape|t=s" => \$opts{'t'},
|
---|
| 124 | "printvar|p=s" => \$opts{'p'},
|
---|
| 125 | "obdr|o" => \$opts{'o'},
|
---|
| 126 | "version|V" => \$opts{'V'},
|
---|
| 127 | ) || pb_syntax(-1,0);
|
---|
| 128 |
|
---|
| 129 | # easy options
|
---|
| 130 | if (defined $opts{'h'}) {
|
---|
| 131 | pb_syntax(0,1);
|
---|
| 132 | }
|
---|
| 133 | if (defined $opts{'man'}) {
|
---|
| 134 | pb_syntax(0,2);
|
---|
| 135 | }
|
---|
| 136 | if (defined $opts{'p'}) {
|
---|
| 137 | pb_display("$ENV{$opts{'p'}}\n");
|
---|
| 138 | exit(0);
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | if (defined $opts{'v'}) {
|
---|
| 142 | $pbdebug = $opts{'v'};
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | my $force = 0;
|
---|
| 146 |
|
---|
| 147 | if (defined $opts{'f'}) {
|
---|
| 148 | $force=1;
|
---|
| 149 | }
|
---|
| 150 | if (defined $opts{'q'}) {
|
---|
| 151 | $pbdebug=-1;
|
---|
| 152 | }
|
---|
| 153 | my $iso;
|
---|
| 154 |
|
---|
| 155 | if (defined $opts{'i'}) {
|
---|
| 156 | $iso = $opts{'i'};
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | #
|
---|
| 160 | # Global variables
|
---|
| 161 | #
|
---|
| 162 | my $MINDI_VERSION = "PBVER-rPBREV";
|
---|
| 163 | my $MINDI_PREFIX = "PBPREFIX";
|
---|
| 164 | my $MINDI_CONF = "PBCONF";
|
---|
| 165 | my $MINDI_LIB = "PBLIB";
|
---|
| 166 | my $MINDI_SBIN = "$MINDI_PREFIX/sbin";
|
---|
| 167 | my $MINDI_FDISK = "$MINDI_SBIN/parted2fdik";
|
---|
| 168 | my $MINDI_DEPLIST = "$MINDI_CONF/deplist.d";
|
---|
| 169 | # Better ?
|
---|
| 170 | my $ARCH = `uname -m`;
|
---|
| 171 | chop($ARCH);
|
---|
| 172 |
|
---|
| 173 | #
|
---|
| 174 | # Temp dir
|
---|
| 175 | #
|
---|
| 176 | pb_temp_init();
|
---|
| 177 |
|
---|
| 178 | #
|
---|
| 179 | # Conf files Management
|
---|
| 180 | # the $MINDI_CONF/mondorescue.conf.dist is delivered as part of the project and
|
---|
| 181 | # its checksum is verified as we need good default values that we can trust
|
---|
| 182 | #
|
---|
| 183 | open(MD5,"$MINDI_CONF/mondorescue.conf.dist.md5") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist.md5: $!";
|
---|
| 184 | my $omd5 = <MD5>;
|
---|
| 185 | chop($omd5);
|
---|
| 186 | close(MD5);
|
---|
| 187 | open(CONF,"$MINDI_CONF/mondorescue.conf.dist") || die "Unable to read mandatory $MINDI_CONF/mondorescue.conf.dist: $!";
|
---|
| 188 | my $md5 = Digest::MD5->new;
|
---|
| 189 | binmode(CONF);
|
---|
| 190 | $md5->addfile(CONF);
|
---|
| 191 | die "Invalid MD5 found sum for $MINDI_CONF/mondorescue.conf.dist: $md5->hexdigest" if ($omd5 ne $md5->hexdigest);
|
---|
| 192 | close(CONF);
|
---|
| 193 |
|
---|
| 194 | pb_conf_add("$ENV{'HOME'}/.mondorescuerc","$MINDI_CONF/mondorescue.conf","$MINDI_CONF/mondorescue.conf.dist");
|
---|
| 195 |
|
---|
| 196 | #
|
---|
| 197 | # Configuration parameters
|
---|
| 198 | #
|
---|
| 199 | $ENV{'PBPROJ'} = "mindi";
|
---|
| 200 | 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");
|
---|
| 201 | 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");
|
---|
| 202 | 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");
|
---|
| 203 |
|
---|
| 204 | #
|
---|
| 205 | # Manage log file
|
---|
| 206 | #
|
---|
| 207 | my $logfile = $mr_logfile->{$ENV{'PBPROJ'}};
|
---|
| 208 |
|
---|
| 209 | if (defined $opts{'l'}) {
|
---|
| 210 | $logfile = $opts{'l'};
|
---|
| 211 | }
|
---|
| 212 | open(pbLOG,"> $logfile") || die "Unable to log to $logfile: $!";
|
---|
| 213 | $pbLOG = \*pbLOG;
|
---|
| 214 | $pbdebug = 0 if ($pbdebug == -1);
|
---|
| 215 | pb_log_init($pbdebug, $pbLOG);
|
---|
| 216 |
|
---|
| 217 | pb_log(0,"mindi start date: $mr_date");
|
---|
| 218 | pb_log(0,"-------------------------------------");
|
---|
| 219 | pb_log(0,"mindi v$MINDI_VERSION");
|
---|
| 220 | pb_log(0,"$ARCH architecture detected");
|
---|
| 221 | pb_log(0,"mindi called with the following arguments: ".join(" ",@ARGV));
|
---|
| 222 | pb_log(0,"-------------------------------------");
|
---|
| 223 | pb_log(0,"MONDO_CACHE: $ENV{'MONDO_CACHE'}") if (defined $ENV{'MONDO_CACHE'});
|
---|
| 224 | pb_log(0,"MINDI_LIB: $MINDI_LIB");
|
---|
| 225 | pb_log(0,"MINDI_CONF: $MINDI_CONF");
|
---|
| 226 | pb_log(0,"MINDI_SBIN: $MINDI_SBIN");
|
---|
| 227 | if (-r "$ENV{'HOME'}/.mondorescuerc") {
|
---|
| 228 | pb_log(0,"-------------------------------------");
|
---|
| 229 | pb_log(0,"Conf file $ENV{'HOME'}/.mondorescuerc");
|
---|
| 230 | pb_display_file("$ENV{'HOME'}/.mondorescuerc");
|
---|
| 231 | }
|
---|
| 232 | if (-r "$MINDI_CONF/mondorescue.conf") {
|
---|
| 233 | pb_log(0,"-------------------------------------");
|
---|
| 234 | pb_log(0,"Conf file $MINDI_CONF/mondorescue.conf");
|
---|
| 235 | pb_display_file("$MINDI_CONF/mondorescue.conf");
|
---|
| 236 | }
|
---|
| 237 | pb_log(0,"-------------------------------------");
|
---|
| 238 |
|
---|
| 239 | #
|
---|
| 240 | # Prepare cache dir
|
---|
| 241 | #
|
---|
| 242 | pb_rm_rf("$mr_cache_dir/*");
|
---|
| 243 | pb_mkdir_p($mr_cache_dir);
|
---|
| 244 |
|
---|
| 245 | #
|
---|
| 246 | # LVM setup
|
---|
| 247 | #
|
---|
| 248 | my $LVM = "none";
|
---|
| 249 | my $LVMCMD = "";
|
---|
| 250 | if (-d "/proc/lvm") {
|
---|
| 251 | # Version 1
|
---|
| 252 | $LVM = "v1";
|
---|
| 253 | } elsif (-d "/dev/mapper") {
|
---|
| 254 | # Version 2
|
---|
| 255 | $LVM = "v2";
|
---|
| 256 | $LVMCMD = "lvm";
|
---|
| 257 | }
|
---|
| 258 | pb_log(0,"LVM set to $LVM");
|
---|
| 259 | pb_log(0,"-------------------------------------");
|
---|