Changeset 1402 in ProjectBuilder for devel/pbmkbm/bin/pbmkbm


Ignore:
Timestamp:
Feb 3, 2012, 12:17:04 AM (12 years ago)
Author:
Bruno Cornec
Message:

r4487@cabanilles: bruno | 2012-02-01 16:21:48 +0100

  • Fix the -t option without param for pb
  • add a function to analyze busybox countent and create appropriate structure for pbmkbm
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pbmkbm/bin/pbmkbm

    r1352 r1402  
    1616use File::Basename;
    1717use File::Copy;
     18use POSIX qw(strftime);
     19
    1820use ProjectBuilder::Version;
    1921use ProjectBuilder::Base;
     
    235237}
    236238pb_log_init($pbdebug, $pbLOG);
     239pb_log(1,"$appname Version $projectbuilderver-$projectbuilderrev\n");
     240my @date = pb_get_date();
     241my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
     242
     243pb_log(1,"Start: $pbdate\n");
    237244
    238245# Get VE name
     
    256263# Check for command requirements
    257264#
    258 my ($req,$opt) = pb_conf_get_if("mkbmcmd","mkbmcmdopt");
     265my ($req,$opt) = pb_conf_get_if("oscmd","oscmdopt");
    259266pb_check_requirements($req,$opt,$appname);
    260267
     
    265272# Where is our build target directory
    266273#
    267 
    268274if (not defined $targetdir) {
    269275    $targetdir = "/var/cache/pbmkbm";
    270276    my ($vestdpath) = pb_conf_get("mkbmpath");
    271277    $targetdir = "$vestdpath->{'default'}/$pbos->{'name'}/$pbos->{'version'}/$pbos->{'arch'}" if (defined $vestdpath->{'default'});
    272 }
    273 
    274 die pb_log(0,"No target-dir specified and no default mkbmpath found in $ENV{'PBETC'}\n") if (not defined $targetdir);
     278    pb_log(1,"No target-dir specified, using $targetdir\n");
     279}
    275280
    276281# Point to the right subdir and create it if needed
    277282pb_mkdir_p($targetdir) if (! -d $targetdir);
    278283
     284# Log information on our system
     285# TODO: this should be put in a subfunction
     286my ($logcmd) = pb_conf_get("logcmd");
     287my ($logopt) = pb_conf_get_if("logopt");
     288# check that the command is there first and then use it.
     289if ($logcmd->{$appname} ne "internal") {
     290    $logcmd = pb_check_req($logcmd->{$appname},1);
     291    if (not defined $logcmd) {
     292        pb_log(1,"INFO: command $logcmd->{$appname} doesn't exist. No log report is available\n");
     293    } else {
     294        my $c = $logcmd->{$appname};
     295        $c .= " $logopt->{$appname}" if (defined $logopt->{$appname});
     296        pb_system("$c","Creating a log report of your system");
     297    }
     298} else {
     299    # We provide our own internal log reporter as a std one isn't found
     300    my ($lcmds,$lfiles) = pb_conf_get_if("logcommands","logfiles");
     301    pb_log(1,"------------------\n");
     302    if (defined $lcmds->{$appname}) {
     303        foreach my $c (split(/,/,$lcmds->{$appname})) {
     304            my $lcmd = $c;
     305            $lcmd =~ s/ .*$//;
     306            $lcmd = pb_check_req($lcmd,1);
     307            if (not defined $lcmd) {
     308                pb_log(1,"INFO: command $lcmd (in $c) doesn't exist\n");
     309                pb_log(1,"------------------\n");
     310                next;
     311            }
     312            pb_log(1,"Execution of $c\n");
     313            pb_log(1,"------------------\n");
     314            pb_system($c,"",1);
     315            pb_log(1,"------------------\n");
     316        }
     317    }
     318    if (defined $lfiles->{$appname}) {
     319        foreach my $f (split(/,/,$lfiles->{$appname})) {
     320            if (! -e $f) {
     321                pb_log(1,"INFO: $f doesn't exist\n");
     322                pb_log(1,"------------------\n");
     323                next;
     324            }
     325            if (! -r $f) {
     326                pb_log(1,"INFO: $f isn't readable\n");
     327                pb_log(1,"------------------\n");
     328                next;
     329            }
     330            if ((-f $f) || (-l $f)) {
     331                if (! open(FILE,$f)) {
     332                    pb_log(1,"INFO: Unable to open $f\n");
     333                    pb_log(1,"------------------\n");
     334                    next;
     335                }
     336                pb_log(1,"Content of $f\n");
     337                pb_log(1,"------------------\n");
     338                while (<FILE>) {
     339                    pb_log(1,$_);
     340                }
     341                close(FILE);
     342                pb_log(1,"------------------\n");
     343            } elsif (-d $f) {
     344                my $dh;
     345                if (! opendir($dh,$f)) {
     346                    pb_log(1,"INFO: Unable to opendir $f\n");
     347                    pb_log(1,"------------------\n");
     348                    next;
     349                }
     350                pb_log(1,"Content of directory $f\n");
     351                pb_log(1,"----------------------------\n");
     352                while (readdir $dh) {
     353                    my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat("$f/$_");
     354                    my $str = sprintf("%10s %2s %5s %5s %10s %14s %s",$mode,$ino,$uid,$gid,$size,$mtime,$_);
     355                    pb_log(1,"$str\n");
     356                }
     357                closedir($dh);
     358                pb_log(1,"------------------\n");
     359            } else {
     360                pb_log(1,"INFO: $f is special\n");
     361                pb_log(1,"------------------\n");
     362            }
     363        }
     364    }
     365}
    279366
    280367# Now the preparation is over, we need to do something useful :-)
     
    287374pb_mkbm_create_media();
    288375
     376@date = pb_get_date();
     377$pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
     378
     379pb_log(1,"End: $pbdate\n");
     380
    289381sub pb_mkbm_create_content {
    290382
     
    294386$opts{'b'} = "ve" if (not defined $opts{'b'});
    295387
     388# Hash of target content
     389# atribute could be, copy, remove, link, dir
     390my %targettree;
     391
    296392if ($opts{'b'} eq "ve") {
    297     # Use existing tools to create a good VE !
     393    # Use project-builder VE mecanism to create a good VE !
    298394    pb_ve_launch($ENV{'PBV'},1);
    299395} elsif ($opts{'b'} eq "native") {
    300396    # Use native tools to create a good VE !
     397} elsif ($opts{'b'} eq "drakut") {
     398    # Use drakut to create a good VE !
     399} elsif ($opts{'b'} eq "busybox") {
     400    # Use busybox to create a good VE !
     401    pb_mkbm_create_busybox_ve(\%targettree);
    301402} else {
    302403    die "Unknown method $opts{'b'} used to create the media content";
    303404}
    304405
     406# Create the directory structure needed on the target dir
     407$targettree->{"/bin"} = "dir";
     408
    305409# Once the environment is made, add what is needed for this boot media to it.
     410# Keyboard
     411# Terminfo
     412# List of commands
     413# List of dependencies
     414# Kernel
     415# Initrd
     416# init
     417# BootLoader and its configuration
     418# Additional data files coming from a potential caller (MondoRescue e.g. with fstab, LVM, mountlist, ...)
     419}
     420
     421sub pb_mkbm_create_busybox_ve {
     422
     423my $tgtree = shift;
     424
     425# First, check which are the supported command in that version of busybox
     426# and create the links for it in the target VE
     427
     428my $busycmd = pb_distro_get_param($pbos,pb_conf_get("ospathcmd-busybox"));
     429open(BUSY,"$busycmd |") || die "Unable to execute $busycmd";
     430my $cmdlist = 0;
     431while (<BUSY>) {
     432    pb_log(3,"busybox line : $_");
     433    chomp($_);
     434    # After these words, we have the list of functions, so trigger their analysis
     435    if ($_ =~ /defined functions:/) {
     436        $cmdlist = 1;
     437        next;
     438    }
     439    # Analyse the list of commands provided by that busybox (, separated)
     440    if ($cmdlist == 1) {
     441        pb_log(3,"Analyzing that busybox line\n");
     442        foreach my $c (split(/,/,$_)) {
     443            $c =~ s/\s*//g;
     444            # skip empty strings
     445            next if ($c =~ /^$/);
     446            my $c1 = pb_check_req($c,0);
     447            if (defined $c1) {
     448                $tgtree->{$c1} = "link:$busycmd";
     449            } else {
     450                # When not found on the system, create the link under /usr/bin by default
     451                $tgtree->{"/usr/bin/$c"} = "link:$busycmd";
     452            }
     453        }
     454    }
     455}
     456pb_log(2,"Target Tree is now: ".Dumper($tgtree)."\n");
     457close(BUSY);
    306458}
    307459
Note: See TracChangeset for help on using the changeset viewer.