source: ProjectBuilder/devel/pbmkbm/bin/pbmkbm

Last change on this file was 2496, checked in by Bruno Cornec, 4 years ago

call pb_conf_init before using conf files

File size: 19.4 KB
RevLine 
[1341]1#!/usr/bin/perl -w
2#
3# pbmkbm, a project-builder.org utility to make boot media
4#
5# $Id$
6#
[2488]7# Copyright B. Cornec 2011-today
[1341]8# Provided under the GPL v2
9
10# Syntax: see at end
11
12use strict 'vars';
13use Getopt::Long qw(:config auto_abbrev no_ignore_case);
[1671]14use Carp qw/confess cluck/;
[1341]15use Data::Dumper;
16use English;
17use File::Basename;
18use File::Copy;
[1414]19use File::Find;
[1402]20use POSIX qw(strftime);
21
[1341]22use ProjectBuilder::Version;
23use ProjectBuilder::Base;
24use ProjectBuilder::Env;
25use ProjectBuilder::Conf;
26use ProjectBuilder::Distribution;
[1348]27use ProjectBuilder::VE;
[1341]28
29# Global variables
30my %opts; # CLI Options
31
32=pod
33
34=head1 NAME
35
36pbmkbm - a project-builder.org utility to make boot media
37
38=head1 DESCRIPTION
39
40pbmkbm creates a bootable media (CD/DVD, USB device, Network, tape, ...)
41with a minimal distribution in it, suited for building packages for example.
42It aims at supporting all distributions supported by project-builder.org
43(RHEL, RH, Fedora, OpeSUSE, SLES, Mandriva, ...)
44
45It is inspired by work done by Jean-Marc André around the HP SSSTK and
46aim at replacing the mindi project (http://www.mondorescue.org), but
47fully integrated with project-builder.org
48
49pbmkbm works in different phases. The first one is to check all
50
51pbmkbm needs to gather a certain number of components that could come
52from various sources and could be put on a different target media.
53We need a kernel, an initrd/initramfs for additional modules and init script,
54a root filesystem and a boot configuration file.
55Kernel, modules could come either from the local installed system
56(typically for disaster recovery context) or from a kernel package of a
[1348]57given configuration or a referenced content.
[1341]58Utilities could come from busybox, local utilities or set of packages.
59The root filesystem is made with them.
60The initrd/initramfs could be made internaly or by calling dracut.
[1348]61The boot config file is generated from analysis content or provided externally.
[1341]62
63=head1 SYNOPSIS
64
[1348]65pbmkbm [-vhq][-t boot-type [-d device]][-b boot-method][-m os-ver-arch]
[1341]66[-s script][-a pkg1[,pkg2,...]] [target-dir]
67
[1348]68pbmkbm [--verbose][--help][--man][--quiet][--type boot-type [--device device]]
69[--machine os-ver-arch][--boot boot-method]
70[--script script][--add pkg1,[pkg2,...]] [target-dir]
[1341]71
72=head1 OPTIONS
73
74=over 4
75
76=item B<-v|--verbose>
77
78Print a brief help message and exits.
79
80=item B<-h|--help>
81
82Print a brief help message and exits.
83
84=item B<--man>
85
86Prints the manual page and exits.
87
88=item B<-q|--quiet>
89
90Do not print any output.
91
[1348]92=item B<-t|--type boot-type>
93
94Type of the boot device to generate. A boot-type can be:
95
96=over 4
97
98=item B<iso>
99
100Generate an ISO9660 image format (suitable to be burned later on or loopback mounted. Uses isolinux.
101
102=item B<usb>
103
104Generate a USB image format (typically a key of external hard drive). Uses syslinux.
105
106=item B<pxe>
107
108Generate a PXE environement (suitable to be integrated in a PXElinux configuration). Uses pxelinux.
109
110=back
111
112=item B<-d|--device device-file>
113
114Name of the device or file on which you want to create the boot media.
115
116=item B<-b|--boot boot-method>
117
118This is the boot method to use to create the boot media. A boot-method can be:
119
120=over 4
121
122=item B<native>
123
124Use the tools of the native distribution to create the boot media. No other dependency.
125
126=item B<ve>
127
128Use the project-builder.org virtual environment notion to create the boot media. No other dependency outside of the project.
129
130=item B<busybox>
131
132Use the busybox tool to create the boot media. Cf: L<http://www.busybox.net>
133
134=item B<dracut>
135
136Use the dracut tool to create the boot media. Cf: L<http://www.dracut.net>
137
138=back
139
[1341]140=item B<-s|--script script>
141
[1413]142Name of the script you want to execute on the related boot media at the end of the build.
[1341]143
144=item B<-a|--add pkg1[,pkg2,...]>
145
[1348]146Additional packages to add from the distribution you want to install on the related boot media
147at the end of the build.
[1341]148
[1348]149=item B<-m|--machine os-ver-arch>
150
151This is the target tuple operating system-version-architecture for which you want to create the boot media.
152
[1341]153=back
154
155=head1 ARGUMENTS
156
[1348]157target-dir is the directory under which the boot media will be build.
158
[1341]159=over 4
160
161=back
162
163=head1 EXAMPLE
164
[1348]165To setup a USB busybox based boot media on the /dev/sdb device for a Fedora 12 distribution with an i386 architecture issue:
[1341]166
[1348]167pbmkbm -t usb -d /dev/sdb -m fedora-12-i386 -b busybox
[1341]168
[1348]169To setup an ISO image under /tmp for a RHEL 6 x86_64 distribution issue using the native environment:
170
171pbmkbm -t iso -d /tmp -m rhel-6-x86_64 -b ve
172
[1341]173=head1 WEB SITES
174
175The main Web site of the project is available at L<http://www.project-builder.org/>.
176Bug reports should be filled using the trac instance of the project at L<http://trac.project-builder.org/>.
177
178=head1 USER MAILING LIST
179
180Cf: L<http://www.mondorescue.org/sympa/info/pb-announce> for announces and
181L<http://www.mondorescue.org/sympa/info/pb-devel> for the development of the pb project.
182
183=head1 CONFIGURATION FILE
184
[2279]185Uses Project-Builder.org configuration file (/etc/pb/pb.yml or /usr/local/etc/pb/pb.yml)
[1341]186
187=head1 AUTHORS
188
189The Project-Builder.org team L<http://trac.project-builder.org/> lead by Bruno Cornec L<mailto:bruno@project-builder.org>.
190
191=head1 COPYRIGHT
192
193Project-Builder.org is distributed under the GPL v2.0 license
194described in the file C<COPYING> included with the distribution.
195
196=cut
197
198# ---------------------------------------------------------------------------
199
200my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
201my $appname = "pbmkbm";
202$ENV{'PBPROJ'} = $appname;
203
[1671]204$Global::pb_stop_on_error = 0; # False by default
205
[1341]206# Initialize the syntax string
207
208pb_syntax_init("$appname Version $projectbuilderver-$projectbuilderrev\n");
209pb_temp_init();
[2496]210pb_conf_init($appname);
[1341]211
212GetOptions("help|?|h" => \$opts{'h'},
[1348]213 "man" => \$opts{'man'},
[1341]214 "verbose|v+" => \$opts{'v'},
215 "quiet|q" => \$opts{'q'},
216 "log-files|l=s" => \$opts{'l'},
217 "script|s=s" => \$opts{'s'},
218 "machine|m=s" => \$opts{'m'},
219 "add|a=s" => \$opts{'a'},
[1348]220 "device|d=s" => \$opts{'d'},
221 "type|t=s" => \$opts{'t'},
222 "boot|b=s" => \$opts{'b'},
[1341]223 "version|V=s" => \$opts{'V'},
[1671]224 "stop-on-error!" => \$Global::pb_stop_on_error,
[1341]225) || pb_syntax(-1,0);
226
227if (defined $opts{'h'}) {
228 pb_syntax(0,1);
229}
230if (defined $opts{'man'}) {
231 pb_syntax(0,2);
232}
233if (defined $opts{'v'}) {
234 $pbdebug = $opts{'v'};
235}
236if (defined $opts{'q'}) {
237 $pbdebug=-1;
238}
239if (defined $opts{'l'}) {
[1672]240 open(pbLOG,"> $opts{'l'}") || confess "ERROR: Unable to log to $opts{'l'}: $!";
[1341]241 $pbLOG = \*pbLOG;
242 $pbdebug = 0 if ($pbdebug == -1);
243}
244pb_log_init($pbdebug, $pbLOG);
[1402]245pb_log(1,"$appname Version $projectbuilderver-$projectbuilderrev\n");
246my @date = pb_get_date();
247my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
[1341]248
[1402]249pb_log(1,"Start: $pbdate\n");
250
[1341]251# Get VE name
252$ENV{'PBV'} = $opts{'m'};
253
254#
255# Initialize distribution info from pb conf file
256#
257my $pbos = pb_distro_get_context($ENV{'PBV'});
[1348]258pb_log(0,"Starting boot media build for $pbos->{'name'}-$pbos->{'version'}-$pbos->{'arch'}\n");
[1341]259
[2252]260pb_env_init_pbrc(); # to get content of HOME/.pbrc.yml
[1348]261
[1414]262# Global hash containing all the configuration information
263my %mkbm;
264
[1341]265#
266# Check target dir
267# Create if not existent and use default if none given
268#
[1414]269$mkbm{'targetdir'} = shift @ARGV;
[1341]270
271#
272# Check for command requirements
273#
[1671]274my ($req,$opt,$pbstoponerr) = pb_conf_get_if("oscmd","oscmdopt","pbstoponerr");
275$Global::pb_stop_on_error = 1 if ((defined $pbstoponerr) && (defined $pbstoponerr->{$ENV{'PBPROJ'}}) && ($pbstoponerr->{$ENV{'PBPROJ'}} =~ /true/oi));
276#pb_check_requirements($req,$opt,$appname);
[1341]277
[1348]278# After that we will need root access
[1672]279confess "ERROR: $appname needs to be run as root" if ($EFFECTIVE_USER_ID != 0);
[1348]280
281#
282# Where is our build target directory
283#
[1414]284if (not defined $mkbm{'targetdir'}) {
285 $mkbm{'targetdir'} = "/var/cache/pbmkbm";
[1702]286 my ($vestdpath) = pb_conf_get_if("cachedir");
287 $mkbm{'targetdir'} = "$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}" if ((defined $vestdpath) && (defined $vestdpath->{'default'}));
288 $mkbm{'targetdir'} = "$vestdpath->{'pbmkbm'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}" if ((defined $vestdpath) && (defined $vestdpath->{'pbmkbm'}));
[1414]289 pb_log(1,"No target-dir specified, using $mkbm{'targetdir'}\n");
[1341]290}
291
[1348]292# Point to the right subdir and create it if needed
[1414]293pb_mkdir_p($mkbm{'targetdir'}) if (! -d $mkbm{'targetdir'});
[1341]294
[1402]295# Log information on our system
296# TODO: this should be put in a subfunction
297my ($logcmd) = pb_conf_get("logcmd");
298my ($logopt) = pb_conf_get_if("logopt");
299# check that the command is there first and then use it.
300if ($logcmd->{$appname} ne "internal") {
301 $logcmd = pb_check_req($logcmd->{$appname},1);
302 if (not defined $logcmd) {
303 pb_log(1,"INFO: command $logcmd->{$appname} doesn't exist. No log report is available\n");
304 } else {
305 my $c = $logcmd->{$appname};
306 $c .= " $logopt->{$appname}" if (defined $logopt->{$appname});
307 pb_system("$c","Creating a log report of your system");
308 }
309} else {
310 # We provide our own internal log reporter as a std one isn't found
311 my ($lcmds,$lfiles) = pb_conf_get_if("logcommands","logfiles");
312 pb_log(1,"------------------\n");
313 if (defined $lcmds->{$appname}) {
314 foreach my $c (split(/,/,$lcmds->{$appname})) {
315 my $lcmd = $c;
316 $lcmd =~ s/ .*$//;
317 $lcmd = pb_check_req($lcmd,1);
318 if (not defined $lcmd) {
[1408]319 pb_log(1,"INFO: command $c doesn't exist\n");
[1402]320 pb_log(1,"------------------\n");
321 next;
322 }
323 pb_log(1,"Execution of $c\n");
324 pb_log(1,"------------------\n");
325 pb_system($c,"",1);
326 pb_log(1,"------------------\n");
327 }
328 }
329 if (defined $lfiles->{$appname}) {
330 foreach my $f (split(/,/,$lfiles->{$appname})) {
331 if (! -e $f) {
332 pb_log(1,"INFO: $f doesn't exist\n");
333 pb_log(1,"------------------\n");
334 next;
335 }
336 if (! -r $f) {
337 pb_log(1,"INFO: $f isn't readable\n");
338 pb_log(1,"------------------\n");
339 next;
340 }
341 if ((-f $f) || (-l $f)) {
342 if (! open(FILE,$f)) {
343 pb_log(1,"INFO: Unable to open $f\n");
344 pb_log(1,"------------------\n");
345 next;
346 }
347 pb_log(1,"Content of $f\n");
348 pb_log(1,"------------------\n");
349 while (<FILE>) {
350 pb_log(1,$_);
351 }
352 close(FILE);
353 pb_log(1,"------------------\n");
354 } elsif (-d $f) {
355 my $dh;
356 if (! opendir($dh,$f)) {
357 pb_log(1,"INFO: Unable to opendir $f\n");
358 pb_log(1,"------------------\n");
359 next;
360 }
361 pb_log(1,"Content of directory $f\n");
362 pb_log(1,"----------------------------\n");
363 while (readdir $dh) {
364 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$f/$_");
365 my $str = sprintf("%10s %2s %5s %5s %10s %14s %s",$mode,$ino,$uid,$gid,$size,$mtime,$_);
366 pb_log(1,"$str\n");
367 }
368 closedir($dh);
369 pb_log(1,"------------------\n");
370 } else {
371 pb_log(1,"INFO: $f is special\n");
372 pb_log(1,"------------------\n");
373 }
374 }
375 }
376}
[1348]377
378# Now the preparation is over, we need to do something useful :-)
379# But it all depends on how we're asked to do it.
[1341]380#
[1348]381# First we need to copy into the target dir all the relevant content
382pb_mkbm_create_content();
383
384# Then we need to package this content in the destination format
385pb_mkbm_create_media();
386
[1402]387@date = pb_get_date();
388$pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
389
390pb_log(1,"End: $pbdate\n");
391
[1661]392pb_exit();
393
[1348]394sub pb_mkbm_create_content {
395
396pb_log(1,"Creating boot media content\n");
[1350]397
398# If not defined use VE mode by default
399$opts{'b'} = "ve" if (not defined $opts{'b'});
400
[1402]401# Hash of target content
402# atribute could be, copy, remove, link, dir
403my %targettree;
404
[1348]405if ($opts{'b'} eq "ve") {
[1402]406 # Use project-builder VE mecanism to create a good VE !
[1900]407 # TODO: This call is now assuming default vetype and image
[1352]408 pb_ve_launch($ENV{'PBV'},1);
[1348]409} elsif ($opts{'b'} eq "native") {
410 # Use native tools to create a good VE !
[1402]411} elsif ($opts{'b'} eq "drakut") {
412 # Use drakut to create a good VE !
413} elsif ($opts{'b'} eq "busybox") {
414 # Use busybox to create a good VE !
415 pb_mkbm_create_busybox_ve(\%targettree);
[1348]416} else {
[1672]417 confess "ERROR: Unknown method $opts{'b'} used to create the media content";
[1348]418}
[1352]419
[1402]420# Create the directory structure needed on the target dir
[2488]421my ($tdirs,$bdirs,$bfiles,$bcmds) = pb_distro_get($pbos,("mkbmtargetdirs","mkbmbootdirs","mkbmbootfiles","mkbmbootcmds"));
[1403]422# Create empty dirs for these
423foreach my $d (split(/,/,$tdirs)) {
[1408]424 $targettree{$d} = "emptydir";
[1403]425}
426# And copy dirs for those
[1672]427foreach my $d (split(/,/,$bfiles),split(/,/,$bdirs)) {
428 pb_mkbm_store_in_tree($d,\%targettree);
[1403]429}
[1672]430pb_log(2,"INFO: Target Tree is now: ".Dumper(%targettree)."\n");
[1352]431# Once the environment is made, add what is needed for this boot media to it.
[1402]432# Keyboard
[1414]433pb_mkbm_find_keyboard(\%targettree);
[1402]434# Terminfo
[1671]435pb_mkbm_find_terminfo(\%targettree);
[1402]436# List of commands
437# List of dependencies
[1408]438# Kernel - We use 2 objects, the running kernel and the target kernel which could be different
439my %rkernel;
440my %tkernel;
441pb_mkbm_find_kernel(\%rkernel);
[1672]442pb_mkbm_find_modules($rkernel{"release"},\%targettree,\%rkernel);
[1402]443# Initrd
444# init
445# BootLoader and its configuration
[1403]446# Additional data files coming from a potential caller (MondoRescue/Mindi e.g. with fstab, LVM, mountlist, ...)
[1671]447pb_log(1,"INFO: Target Tree is now: ".Dumper(%targettree)."\n");
[1413]448pb_log(1,"End of boot media creation\n");
[1348]449}
450
[1402]451sub pb_mkbm_create_busybox_ve {
452
453my $tgtree = shift;
454
[1413]455pb_log(1,"Analyzing your busybox's configuration\n");
[1402]456# First, check which are the supported command in that version of busybox
457# and create the links for it in the target VE
458
[2488]459my $busycmd = pb_distro_get($pbos,"ospathcmd-busybox");
[2434]460open(BUSY,"$busycmd |") || (cluck "ERROR: Unable to execute $busycmd" && return);
[1402]461my $cmdlist = 0;
462while (<BUSY>) {
463 pb_log(3,"busybox line : $_");
464 chomp($_);
465 # After these words, we have the list of functions, so trigger their analysis
466 if ($_ =~ /defined functions:/) {
467 $cmdlist = 1;
468 next;
469 }
470 # Analyse the list of commands provided by that busybox (, separated)
471 if ($cmdlist == 1) {
472 pb_log(3,"Analyzing that busybox line\n");
473 foreach my $c (split(/,/,$_)) {
474 $c =~ s/\s*//g;
475 # skip empty strings
476 next if ($c =~ /^$/);
477 my $c1 = pb_check_req($c,0);
478 if (defined $c1) {
479 $tgtree->{$c1} = "link:$busycmd";
480 } else {
481 # When not found on the system, create the link under /usr/bin by default
482 $tgtree->{"/usr/bin/$c"} = "link:$busycmd";
483 }
484 }
485 }
486}
[1414]487pb_log(1,"Target Tree is now: ".Dumper($tgtree)."\n");
[1402]488close(BUSY);
[1413]489pb_log(1,"End of busybox analysis\n");
[1402]490}
491
[1413]492sub pb_mkbm_find_keyboard {
493
[1414]494my $tgtree = shift;
495
[1413]496pb_log(1,"Analyzing your keyboard's configuration\n");
[2488]497my $keyfile = pb_distro_get($pbos,"ospathcmd-keyfile");
498confess "ERROR: Unable to read the keyfile $keyfile" if (! -r $keyfile);
499my $keymapdir = pb_distro_get($pbos,"ospathcmd-keymapdir");
500confess "ERROR: Unable to read the keymapdir $keymapdir" if (! -d $keymapdir);
501my $keymapre = pb_distro_get($pbos,"ospathcmd-keymapre");
[1413]502
[1671]503# if a direct keymap file is given as keyfile, use only the first existing one and return
[1414]504my $foundkmap = 0;
505foreach my $f (split(/,/,$keyfile)) {
506 next if ($f !~ /\.gz$/);
507 $foundkmap = 1;
[1672]508 if ((-l $f) || (-r $f)) {
509 pb_mkbm_store_in_tree($f,$tgtree);
[1414]510 pb_log(1,"Using Keymap file $f\n");
511 last;
512 } else {
513 next;
514 }
515}
516return() if ($foundkmap eq 1);
517
518pb_log(1,"Using Keyfile $keyfile and Keymap directory $keymapdir\n");
519my $locale="";
[1672]520open(KEYMAP,"$keyfile") || confess "ERROR: Unable to read $keyfile";
[1414]521# Depending on the format of the keymap we look for various strings
522while (<KEYMAP>) {
523 $locale =~ $keymapre;
524}
525close(KEYMAP);
526pb_log(1,"Found locale $locale\n");
527
[1413]528pb_log(1,"End of keyboard analysis\n");
529}
530
[1671]531sub pb_mkbm_find_terminfo {
532
533my $tgtree = shift;
534
535pb_log(1,"Analyzing your terminfo's configuration\n");
[2488]536my $termdir = pb_distro_get($pbos,"ospathcmd-termdir");
537confess "ERROR: Unable to read the keymapdir $termdir" if (! -d $termdir);
[1671]538$tgtree->{$termdir} = "recurdir";
539
540pb_log(1,"End of terminfo analysis\n");
541}
542
[1408]543sub pb_mkbm_find_kernel {
544
545my $kernel = shift;
546
[1413]547pb_log(1,"Analyzing your kernel's configuration\n");
548$kernel->{"is_xen"} = undef;
[1408]549# See if we're booted from a Xen kernel
550# From http://wiki.xensource.com/xenwiki/XenCommonProblems#head-26434581604cc8357d9762aaaf040e8d87b37752
551if ( -f "/proc/xen/capabilities") {
552 # It's a Xen kernel
553 pb_log(2,"INFO: We found a Xen Kernel running\n");
[1413]554 $kernel->{"is_xen"} = 1;
[1408]555}
[1413]556$kernel->{"release"} = pb_get_osrelease();
[1408]557
[2488]558my $kfile = pb_distro_get_if($pbos,"mkbmkernelfile");
[1408]559if ((defined $kfile) && ($kfile ne "")) {
560 pb_log(1,"INFO: You specified your kernel as $kfile, so using it\n");
[1413]561 $kernel->{"file"} = $kfile;
[1408]562} else {
[2488]563 $kernel->{"dir"} = pb_distro_get($pbos,"mkbmkerneldir");
[1672]564 confess "ERROR: The mkbmkerneldir content ($kernel->{'dir'}) doesn't refer to a directory\n" if (! -d $kernel->{"dir"});
[1413]565 pb_log(1,"INFO: Analyzing directory $kernel->{'dir'} to find your kernel\n");
[2488]566 $kernel->{"namere"} = pb_distro_get($pbos,"mkbmkernelnamere");
[1408]567
[1413]568 # TODO: Look at a better way to find the name of the kernel we run
569 # look at /proc/sys/kernel/bootloader_type /proc/sys/kernel/bootloader_version
570 # to have a better guess
571 my $dh;
[1672]572 confess "ERROR: Unable to open the mkbmkerneldir content ($kernel->{'dir'})\n" if (! opendir($dh,$kernel->{"dir"}));
[1413]573 while (readdir $dh) {
574 pb_log(3,"Potential kernel file: $_\n");
575 # Skip non-files
576 next if (! -f "$kernel->{'dir'}/$_");
577 # Skip files not correpsonding to the RE planned
578 next if ($_ !~ /$kernel->{"namere"}/);
579 # We now have a candidate. Analyze further
580 pb_log(3,"Potential kernel file 2: $_\n");
581 eval
582 {
583 require File::MimeInfo;
584 File::MimeInfo->import();
585 };
586 if ($@) {
587 # File::MimeInfo not found
[1672]588 confess "ERROR: Install File::MimeInfo to handle kernel file detection\n";
[1413]589 }
590 my $mm = mimetype("$kernel->{'dir'}/$_");
591 # Skip symlinks
592 next if ($mm =~ /inode\/symlink/);
593 pb_log(2,"file $_ mimetype: $mm\n");
594 if ($mm =~ /\/x-gzip/) {
595 # on ia64 kernel are gzip compressed
596 }
597 next if (pb_get_content("$kernel->{'dir'}/$_") !~ /$kernel->{"release"}/);
598 pb_log(3,"Potential kernel file 3: $_\n");
599 $kernel->{"file"} = "$kernel->{'dir'}/$_";
600 #my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$f/$_");
601 }
602 closedir($dh);
[1408]603}
[1413]604pb_log(1,"INFO: kernel is ".Dumper($kernel)."\n");
605pb_log(1,"End of kernel analysis\n");
[1408]606}
607
[1672]608sub pb_mkbm_find_modules {
609
610my $krel = shift;
611my $tgtree = shift;
612my $kernel = shift;
613
[2488]614my $lsmod = pb_distro_get($pbos,"ospathcmd-lsmod");
615my $depmod = pb_distro_get($pbos,"ospathcmd-depmod");
[1672]616open(LSMOD,"$lsmod") || confess "ERROR: Unable to read $lsmod: $!";
617while (<LSMOD>) {
618 my ($mod,$void) = split(/\s+/);
619 open(DEPMOD,"$depmod -S $kernel->{'release'} $mod |") || confess "ERROR: Unable to read $depmod -S $kernel->{'release'} $mod: $!";
620 while (<DEPMOD>) {
621 chomp();
622 s/^insmod //;
623 s/\s+$//;
624 pb_mkbm_store_in_tree($_,$tgtree);
625 }
626 close(DEPMOD);
627}
628close(LSMOD);
629}
630
[1348]631sub pb_mkbm_create_media {
632
633}
634
[1672]635
636sub pb_mkbm_store_in_tree {
637
638my $f = shift;
639my $tgtree = shift;
640
641if (-d $f) {
642 $tgtree->{$f} = "recurdir";
643} elsif (-l $f) {
644 $tgtree->{$f} = "link:$f";
645 pb_log(3,"INFO: Storing link $f in tree\n");
646} elsif (-r $f) {
647 $tgtree->{$f} = "file";
648 pb_log(3,"INFO: Storing file $f in tree\n");
649} else {
650 pb_log(3,"INFO: file $f doesn't exist\n");
651}
652}
653
[1341]654# Get the package list to download, store them in a cache directory
655#
[1352]656#my ($mkbmcachedir) = pb_conf_get_if("mkbmcachedir");
[2488]657#my ($pkgs) = pb_distro_get($pbos,"mkbmmindep");
[1341]658
659#
660# /proc needed
661#
[1352]662#pb_system("mount -o bind /proc $targetdir/proc","Mounting /proc");
[1341]663
664# Installed additional packages we were asked to
[1352]665#if (defined $opts{'a'}) {
666#$opts{'a'} =~ s/,/ /g;
667#pb_system("chroot $targetdir /bin/bash -c \"$pbos->{'install'} $opts{'a'} \"","Adding packages to OS by running $pbos->{'install'} $opts{'a'}");
668#}
[1341]669
670#
671# Clean up
672#
[1352]673#pb_log(1,"Cleaning up\n");
674#pb_system("umount $targetdir/proc","Unmounting /proc");
[1341]675
676# Executes post-install step if asked for
[1352]677#if ($opts{'s'}) {
678#pb_system("$opts{'s'} $targetdir","Executing the post-install script: $opts{'s'} $targetdir");
679#}
Note: See TracBrowser for help on using the repository browser.