Perl kernel



#!/usr/bin/perl
use Switch;
use diagnostics;


$latest_patch_build = `ls -l /project/bats2302/ncgl_loads4/ncgltar/ncgl130/rhe_40 | grep latest_patch_build`;
@patch_build_path_tmp = split(/-> /, $latest_patch_build);
$patch_build_path = $patch_build_path_tmp[1];
chomp($patch_build_path);
system "rm /home/eimnpqz/kernel_patch/aaa/*";
$working_directory = "/projects/UCCS/eimnpqz/kernel/RPMs";
$patch_id_info_tmp = `cleartool lsact -l -cac | grep /vob/siren/tools/PATCHES/VSE40/eimnpqz_ | grep CHECKEDOUT`;
@c = split(/\@\@/,$patch_id_info_tmp);


@b = split(/\//,$c[0]);
$activity_id = $b[6];


print "activity id is $activity_id\n";


print "/vob/siren/tools/PATCHES/VSE40/$activity_id.admin\n";
#$adminFile = "/vob/siren/tools/PATCHES/VSE40/$activity_id.admin";
#$recordFile = "/vob/siren/tools/PATCHES/VSE40/$activity_id.record";
#$buildFile = "/vob/siren/tools/PATCHES/VSE40/$activity_id.build";


$adminFile = "/home/eimnpqz/kernel_patch/$activity_id.admin";
$recordFile = "/home/eimnpqz/kernel_patch/$activity_id.record";
$buildFile = "/home/eimnpqz/kernel_patch/$activity_id.build";


$admin_templete = "/home/eimnpqz/kernel_patch/patch_admin_templete";
$base_file = "/home/eimnpqz/kernel_patch/patch_base_info";
$pne_file = "/home/eimnpqz/kernel_patch/pne_parcel_config";
#open(BASEFILE, "$base_file") || die "Can't open file : $base_file \n";
open( BFile, $base_file ) || die ("can't open the base file. \n");
@baseInfo = <BFile>;


#get rpm pne and sysroot files from base file
sub getItemList {


        my @item_group;
        my $str = $_[0];
        print "nowwwwwwwwwwwwwwwwwwwwwwwww it is $str\n";
        switch ($str){
                case "sysroot" { $tag="Sysroots:"; $filterString='\.tar\.bz2\s+$';}
                case "rpm" { $tag="RPMs:"; $filterString='\.rpm\s+$';}
                case "pne" { $tag="Outputs:"; $filterString='-pne\s+$';}


        }


print "test1\n";


        $itemstartRecording = 0;


        #get all the item info to group
                                        #remove the files which are not end of ""
        foreach $line (@baseInfo) {
                $_ = $line;
                #get all the file list under "item:"
                if (/$tag/) {
                        print "have one item. \n";
                        $itemstartRecording = 1;
                        $itemCount += 1;
        #               push(@item_group,@{item_.$itemCount});


                        next;
                }


                if($itemstartRecording == 1) {
                        if(/N\/A/){
                                $itemstartRecording = 0;
                                $itemCount -= 1;
        #                       pop(@item_group);
                        } else {
                                print "find the item; \n";


                                if (/^$/){
                                        print "meet the blank line.\n";
                                        $itemstartRecording = 0;
                                        push(@item_group,@{item_.$itemCount});
        print "@item_group\n";
                                } else {
                                        print "add line to group.\n";
                                        print $line;
                                        if (/$filterString/){
                                                push(@{item_.$itemCount}, $line);
                                                print "*****so far there are $itemCount group\n";
                                        }
                                }
                        }
                }
        }


        print "\n";
        foreach $line (@item_group) {
                $line=~s/^\s+|\s+$//g;
        #       $line=~s/ +$//;
        }


        $count=0;
        while ($count <= $#item_group){
                my $j = $count +1;
                #find the duplicate items, remember their positions
                while ($j <= $#item_group){
                        if ($item_group[$count] eq $item_group[$j]) {
                                push(@deleteIndex, $j);
                        }
                        $j+=1;
                }


                #delete them
                if ($#deleteIndex != -1){
                        my $k=0;
                        while( $k <= $#deleteIndex  ){
                                $pos=pop(@deleteIndex);
                                splice(@item_group, $pos, 1);
                                $k+=1;
                        }
                }
                $count+=1;
        }


        @item_group;


} #end of getItemList


open(BUILD, "+>$buildFile") || die ("can't find the build file");


#build file writer
sub writeBuildFile {
        my @items = @_;
        print "item is @items\n";
        my $local_line;
        foreach $local_line (@items) {
                print BUILD ("$local_line\n");
        }
} #end of writeBuildFile




#################################################
#
################################################
sub getPneParcelConfig {
        my $pneItem = $_[0];


        my @tmpItems = split(/\//, $pneItem);
        my $pneName = $tmpItems[2];
        my @pneTypegrp = split(/-/,$pneName);
        my $pneType = $pneTypegrp[0];
        print "pneItem is $pneItem\n";
        print "pneName is $pneName\n";
print "pneType is $pneType\n";


        my $parcelType;
        my $lineIndex = 0;
        my $startRecord = 0;
        my $parcelType = "";
        foreach (@pneFile) {
                if (/$pneType/) {
                        my @tmpItems = split(/\s+/);
                        $parcelType = $tmpItems[1];
print "lineIndex is $lineIndex\n";
print "tmpItems is @tmpItems\n";
                        $lineIndex+=1;
                        next;
                }


                if($startRecord && /<\/PARCEL>/) {
                        push(@pneConfig,"$_\n");
                        $startRecord = 0;
                        last;
                }


                if ($startRecord) {
                        push(@pneConfig,$_);
                        next;
                }




                if (($parcelType ne "") && />$parcelType</) {
print "get the parcel type\n";
print "now is $_\n";
print "lineIndex is $lineIndex\n";
                $startRecord = 1;


                        my $lastLineIndex = $lineIndex-1;
                        print "pneItem[$lineIndex-1] is $pneFile[$lastLineIndex]\n";
                        push(@pneConfig,$pneFile[$lastLineIndex]);
                        push(@pneConfig,$_);
                }
                $lineIndex+=1;
        }
        @pneConfig;
} #end of getPneParcelConfig










########################################################
# get config xml file for RPM
#######################################################
sub getRPMConfig {
        my $rpmItem = $_[0];


        my @tmpItems = split(/\//, $rpmItem);
        my $rpmName = $tmpItems[4];
        $rpmType = $rpmName;
        $rpmType=~s/-[0-9]*\.[0-9]*\.[0-9]*.*rpm$//g;
        print "rpmType is $rpmType\n";


        push(@rpmConfig, "   <PARCEL>\n");
        push(@rpmConfig, "      <PARCEL_NAME>$rpmType<\/PARCEL_NAME>\n");
        push(@rpmConfig, "      <COMPILE_DIR><\/COMPILE_DIR>\n");
        push(@rpmConfig, "      <PARCEL_REQUIRES_REBOOT>Y<\/PARCEL_REQUIRES_REBOOT>\n");
        push(@rpmConfig, "   <\/PARCEL>\n\n");
        @rpmConfig;


} # end of getRPMConfig




@sysroot_list=&getItemList("sysroot");
@rpm_list=&getItemList("rpm");
@pne_list=&getItemList("pne");
print "\n";
print "@sysroot_list\n";
print "@rpm_list\n";
print "@pne_list\n";




# step 11 : Create List of RPMs and PNEs and Update Build File


if ($#pne_list != -1){


        &writeBuildFile("PNEs");
        &writeBuildFile(@pne_list);


}


if ($#rpm_list != -1) {
        &writeBuildFile("\nRPMs");
        &writeBuildFile(@rpm_list);


}


if($#sysroot_list != -1) {
        &writeBuildFile("\nSysroots");
        &writeBuildFile(@sysroot_list);
}


system "cat $buildFile";
# end of step 11


#step 12.1 : Update Parcel Section of Admin File
if ($#pne_list != -1){
        #step 12: Update Parcel Section of Admin File
        open(PNE, "$pne_file") || die ("can't open the file $pne_file");


        @pneFile=<PNE>;


        foreach (@pne_list){
                my $pneItem = $_;
                @parcelconfig = &getPneParcelConfig($pneItem);


                print "@parcelconfig\n";


                #write pne files to .build file
                &writeBuildFile("\n\n@parcelconfig");
        }
}


#step 12.2
if ($#rpm_list != -1){


        foreach(@rpm_list){
                my $rpmItem = $_;
                &getRPMConfig($rpmItem);


                print "@rpmConfig\n";


        }
}


#update admin file in patch admin file
open (ADMIN_TMP, $admin_templete) || die ("can't open the admin templete file");
@admin_tmp = <ADMIN_TMP>;


$parcelLineIndex = `sed -n '/<PARCEL>/=' $admin_templete`;


$parcelLineIndex-=1;
push(@newConfigContent, @parcelconfig);
push(@newConfigContent, @rpmConfig);


splice(@admin_tmp, $parcelLineIndex, 1, @newConfigContent);
print "@admin_tmp\n";


#end of step 12


#
foreach (@rpm_list) {
        my $rpmDir = $_;
        $rpmDir =~s/^\.\.\.//g;
print "rpmdir is $rpmDir\n";
print "cp $patch_build_path/ncgl$rpmDir $working_directory\n";
        my $output = `cp $patch_build_path/ncgl/$rpmDir $working_directory`;
        print "output is $output\n"
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值