source: devel/mindi/bin/mindi @ 2003

Last change on this file since 2003 was 2003, checked in by bruno, 11 years ago

New devel branch to host an attempt at doing a perl rewrite of the project using pb componnts.

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