Changeset 320 in ProjectBuilder


Ignore:
Timestamp:
Feb 13, 2008, 6:26:07 PM (16 years ago)
Author:
Bruno Cornec
Message:
  • Param packager => pbpackager for consistency, and PBPACKAGER is an env var usable
  • Base is now a perl package
  • Multiple fixes all around the place with a correct collectl build from http URL
  • Add build2ve/cms2ve/newve/script2ve and mock support
  • build2vm/launchvm => build2v/launchv and has now a parameter
  • send2ssh => send2target, will be able to evolve later + lots of parameter changes to support VE
  • Add file support
  • Add -f option to force rebuilding the chroot
  • Env var PBVM => PBV
  • Update the concepts doc
Location:
devel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r319 r320  
    2727my %opts;                   # CLI Options
    2828my $action;                 # action to realize
    29 my $test = "FALSE";
    30 my $option = "";
    31 my @pkgs;
     29my $test = "FALSE";         # Not used
     30my $force = 0;              # Force VE/VM rebuild
     31my $option = "";            # Not used
     32my @pkgs;                   # list of packages
    3233my $pbtag;                  # Global Tag variable
    3334my $pbver;                  # Global Version variable
     
    3637my %pbtag;                  # per package
    3738my $pbrev;                  # Global REVISION variable
    38 my @date = pb_get_date();
    39 my $pbdate = strftime("%Y-%m-%d", @date);
    4039my $pbaccount;              # Login to use to connect to the VM
    4140my $pbport;                 # Port to use to connect to the VM
     
    4342my $iso;                    # ISO iage for the VM to create
    4443
    45 getopts('a:hi:l:m:P:p:qr:s:tvV:',\%opts);
     44my @date = pb_get_date();
     45my $pbdate = strftime("%Y-%m-%d", @date);
     46
     47getopts('a:fhi:l:m:P:p:qr:s:tvV:',\%opts);
    4648
    4749my ($projectbuilderver,$projectbuilderrev) = pb_version_init();
     
    5456    #$debug = $opts{'v'};
    5557    pb_log(0,"Debug value: $debug\n");
     58}
     59if (defined $opts{'f'}) {
     60    $force=1;
    5661}
    5762if (defined $opts{'q'}) {
     
    7883# Handle virtual machines if any
    7984if (defined $opts{'m'}) {
    80     $ENV{'PBVM'} = $opts{'m'};
     85    $ENV{'PBV'} = $opts{'m'};
    8186}
    8287if (defined $opts{'s'}) {
     
    136141} elsif ($action =~ /^pkg2ssh$/) {
    137142    pb_pkg2ssh();
     143} elsif ($action =~ /^build2ve$/) {
     144    pb_build2v("ve");
    138145} elsif ($action =~ /^build2vm$/) {
    139     pb_build2vm();
     146    pb_build2v("vm");
     147} elsif ($action =~ /^cms2ve$/) {
     148    pb_cms2build();
     149    pb_build2v("ve");
    140150} elsif ($action =~ /^cms2vm$/) {
    141151    pb_cms2build();
    142     pb_build2vm();
     152    pb_build2v("vm");
    143153} elsif ($action =~ /^launchvm$/) {
    144     pb_launchvm($ENV{'PBVM'},0);
     154    pb_launchv("vm",$ENV{'PBV'},0);
     155} elsif ($action =~ /^launchve$/) {
     156    pb_launchv("ve",$ENV{'PBV'},0);
    145157} elsif ($action =~ /^script2vm$/) {
    146     pb_script2vm($pbscript);
     158    pb_script2v($pbscript,"vm");
     159} elsif ($action =~ /^script2ve$/) {
     160    pb_script2v($pbscript,"ve");
    147161} elsif ($action =~ /^newver$/) {
    148162    pb_newver();
    149 } elsif ($action =~ /^newchroot$/) {
    150     pb_launchchroot($ENV{'PBCHROOT'},1);
     163} elsif ($action =~ /^newve$/) {
     164    pb_launchv("ve",$ENV{'PBV'},1);
    151165} elsif ($action =~ /^newvm$/) {
    152     pb_launchvm($ENV{'PBVM'},1);
     166    pb_launchv("vm",$ENV{'PBV'},1);
    153167} elsif ($action =~ /^newproj$/) {
    154168    # Nothing to do - already done in pb_env_init
     
    168182
    169183    # declare packager for filtering
    170     my ($tmp) = pb_conf_get("packager");
     184    my ($tmp) = pb_conf_get("pbpackager");
    171185    my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
    172186
     
    227241        my %build;
    228242
    229         my ($ptr) = pb_conf_get_if("vmlist","chrootlist");
     243        my ($ptr) = pb_conf_get_if("vmlist","velist");
    230244        foreach my $d (split(/,/,$ptr->{$ENV{'PBPROJ'}})) {
    231245            my ($name,$ver,$arch) = split(/-/,$d);
     
    240254            # Find all build files first relatively to PBROOT
    241255            # Find also all specific files referenced in the .pb conf file
    242             my %bfiles = {};
    243             my %pkgfiles = {};
     256            my %bfiles = ();
     257            my %pkgfiles = ();
    244258            pb_log(2,"DEBUG dir: $ENV{'PBCONF'}/$pbpkg\n");
    245259            $build{"$ddir-$dver"} = "yes";
     
    347361    $pkg = { } if (not defined $pkg);
    348362
    349     # declare packager
    350     my ($tmp) = pb_conf_get("packager");
    351     my $pbpackager = $tmp->{$ENV{'PBPROJ'}};
     363    # declare packager (via env var in VM/VE
     364    my $pbpackager;
     365    if (not defined $ENV{'PBPACKAGER'}) {
     366        my ($tmp) = pb_conf_get("pbpackager");
     367        $pbpackager = $tmp->{$ENV{'PBPROJ'}};
     368    } else {
     369        $pbpackager = $ENV{'PBPACKAGER'};
     370    }
    352371
    353372    chdir "$ENV{'PBBUILDDIR'}";
     
    466485
    467486sub pb_build2ssh {
    468     pb_send2ssh("Sources");
     487    pb_send2target("Sources");
    469488}
    470489
    471490sub pb_pkg2ssh {
    472     pb_send2ssh("Packages");
     491    pb_send2target("Packages");
    473492}
    474493
    475494# By default deliver to the the public site hosting the
    476 # ftp structure (or whatever) or a VM
    477 sub pb_send2ssh {
     495# ftp structure (or whatever) or a VM/VE
     496sub pb_send2target {
    478497
    479498    my $cmt = shift;
    480     my $vm = shift || undef;
     499    my $v = shift || undef;
    481500    my $vmexist = shift || 0;           # 0 is FALSE
    482501    my $vmpid = shift || 0;             # 0 is FALSE
    483     my $host = shift || "sshhost";
    484     my $login = shift || "sshlogin";
    485     my $dir = shift || "sshdir";
    486     my $port = shift || "sshport";
    487     my $tmout = shift || "vmtmout";
     502
     503    my $host = "sshhost";
     504    my $login = "sshlogin";
     505    my $dir = "sshdir";
     506    my $port = "sshport";
     507    my $tmout = "sshtmout";
     508    my $path = "sshpath";
     509    my $conf = "sshconf";
     510    my $rebuild = "sshrebuild";
     511    if ($cmt eq "vm") {
     512        $login = "vmlogin";
     513        $dir = "pbdir";
     514        $tmout = "vmtmout";
     515        $rebuild = "vmrebuild";
     516        # Specific VM
     517        $host = "vmhost";
     518        $port = "vmport";
     519    } elsif ($cmt eq "ve") {
     520        $login = "velogin";
     521        $dir = "pbdir";
     522        $tmout = "vetmout";
     523        # Specific VE
     524        $path = "vepath";
     525        $conf = "veconf";
     526        $rebuild = "verebuild";
     527    }
    488528    my $cmd = "";
    489529
     
    493533
    494534    # Get the running distro to consider
    495     my ($odir,$over) = (undef, undef);
    496     if (defined $vm) {
    497         ($odir,$over) = split(/_/,$vm);
     535    my ($odir,$over,$oarch) = (undef, undef);
     536    if (defined $v) {
     537        ($odir,$over,$oarch) = split(/-/,$v);
    498538    }
    499539    my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($odir,$over);
     
    511551        ($pbver,$pbtag) = split(/-/,$vertag);
    512552
    513         if (($cmt eq "Sources") || ($cmt eq "VMs")) {
     553        if (($cmt eq "Sources") || ($cmt eq "vm") || ($cmt eq "ve")) {
    514554            $src = "$src $ENV{'PBDESTDIR'}/$pbpkg-$pbver.tar.gz";
    515555            if ($cmd eq "") {
     
    520560        }
    521561    }
    522     if ($cmt eq "VMs") {
    523         $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBCONF'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb $ENV{'PBETC'}";
     562    if (($cmt eq "vm") || ($cmt eq "ve")) {
     563        $src="$src $ENV{'PBDESTDIR'}/pbscript $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb $ENV{'PBDESTDIR'}/$pbprojver-$pbprojtag.pb $ENV{'PBETC'}";
    524564    } elsif ($cmt eq "Script") {
    525565        $src="$src $ENV{'PBDESTDIR'}/pbscript";
     
    538578        }
    539579    }
    540     # Remove potential leading spaces (cause pb with basename)
     580    # Remove potential leading spaces (cause problem with basename)
    541581    $src =~ s/^ *//;
    542582    my $basesrc = "";
     
    545585    }
    546586
    547     pb_log(2,"Sources handled ($cmt): $src\n");
    548     my ($sshhost,$sshlogin,$sshdir,$sshport,$vmtmout,$testver) = pb_conf_get($host,$login,$dir,$port,$tmout,"testver");
    549     my $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
    550     # Overwrite account value if passed as parameter
    551     $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
     587    pb_log(0,"Sources handled ($cmt): $src\n");
     588    my ($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf) = pb_conf_get($host,$login,$dir,$port,$tmout,$rebuild,$path,$conf);
     589    pb_log(2,"ssh: ".Dumper(($sshhost,$sshlogin,$sshdir,$sshport,$vtmout,$vrebuild,$vepath,$veconf))."\n");
     590    # Not mandatory
     591    my ($testver) = pb_conf_get_if("testver");
     592
     593    my $mac;
     594    # Useless for VE
     595    if ($cmt ne "ve") {
     596        $mac = "$sshlogin->{$ENV{'PBPROJ'}}\@$sshhost->{$ENV{'PBPROJ'}}";
     597        # Overwrite account value if passed as parameter
     598        $mac = "$pbaccount\@$sshhost->{$ENV{'PBPROJ'}}" if (defined $pbaccount);
     599    }
     600
    552601    my $tdir;
    553602    my $bdir;
    554603    if (($cmt eq "Sources") || ($cmt eq "Script")) {
    555604        $tdir = "$sshdir->{$ENV{'PBPROJ'}}/src";
    556     } elsif ($cmt eq "VMs") {
    557         $tdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/delivery";
    558         $bdir = dirname("$sshdir->{$ENV{'PBPROJ'}}")."/build";
     605    } elsif (($cmt eq "vm") || ($cmt eq "ve")) {
     606        $tdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/delivery";
     607        $bdir = $sshdir->{$ENV{'PBPROJ'}}."/$ENV{'PBPROJ'}/build";
    559608        # Remove a potential $ENV{'HOME'} as bdir should be relative to pb's home
    560609        $bdir =~ s|\$ENV.+\}/||;
    561610    } elsif ($cmt eq "Packages") {
    562611        $tdir = "$sshdir->{$ENV{'PBPROJ'}}/$ddir/$dver";
    563         if ((defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} eq "true")) {
     612        if ((defined $testver) && (defined $testver->{$ENV{'PBPROJ'}}) && ($testver->{$ENV{'PBPROJ'}} eq "true")) {
    564613            # This is a test pkg => target dir is under test
    565614            $tdir .= "/test";
     
    568617        return;
    569618    }
    570     my $nport = $sshport->{$ENV{'PBPROJ'}};
    571     $nport = "$pbport" if (defined $pbport);
     619
     620    # Useless for VE
     621    my $nport;
     622    if ($cmt ne "ve") {
     623        $nport = $sshport->{$ENV{'PBPROJ'}};
     624        $nport = "$pbport" if (defined $pbport);
     625    }
    572626
    573627    # Remove a potential $ENV{'HOME'} as tdir should be relative to pb's home
    574628    $tdir =~ s|\$ENV.+\}/||;
    575629
    576     my $tm = $vmtmout->{$ENV{'PBPROJ'}};
    577     pb_system("ssh -q -p $nport $mac \"mkdir -p $tdir ; cd $tdir ; echo \'for i in $basesrc; do if [ -f \$i ]; then rm -f \$i; fi; done\ ; $cmd' | bash\"","Preparing $tdir on $mac");
    578     pb_system("cd $ENV{'PBBUILDDIR'} ; scp -p -P $nport $src $mac:$tdir 2> /dev/null","$cmt delivery in $tdir on $mac");
    579     pb_system("ssh -q -p $nport $mac \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $mac  if needed");
    580     if ($cmt eq "VMs") {
     630    my $tm = $vtmout->{$ENV{'PBPROJ'}};
     631
     632    # ssh communication if not VE
     633    my ($shcmd,$cpcmd,$cptarget,$cp2target);
     634    if ($cmt ne "ve") {
     635        $shcmd = "ssh -q -p $nport $mac";
     636        $cpcmd = "scp -p -P $nport";
     637        $cptarget = "$mac:$tdir";
     638        $cp2target = "$mac:$bdir";
     639    } else {
     640        my $tp = $vepath->{$ENV{'PBPROJ'}};
     641        $shcmd = "sudo chroot $tp/$v /bin/su - $sshlogin->{$ENV{'PBPROJ'}} -c ";
     642        $cpcmd = "cp -a ";
     643        $cptarget = "$tp/$tdir";
     644        $cp2target = "$tp/$bdir";
     645    }
     646
     647    pb_system("$shcmd \"mkdir -p $tdir ; cd $tdir ; echo \'for i in $basesrc; do if [ -f \$i ]; then rm -f \$i; fi; done\ ; $cmd' | bash\"","Preparing $tdir on $cptarget");
     648    pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $src $cptarget 2> /dev/null","$cmt delivery in $cptarget");
     649    # For VE we need to change the owner manually - To be tested if needed
     650    #if ($cmt eq "ve") {
     651    #pb_system("cd $cptarget ; sudo chown -R $sshlogin->{$ENV{'PBPROJ'}} .","$cmt chown in $cptarget to $sshlogin->{$ENV{'PBPROJ'}}");
     652    #}
     653    pb_system("$shcmd \"echo \'cd $tdir ; if [ -f pbscript ]; then ./pbscript; fi\' | bash\"","Executing pbscript on $cptarget if needed");
     654    if (($cmt eq "vm") || ($cmt eq "ve")) {
    581655        # Get back info on pkg produced, compute their name and get them from the VM
    582         pb_system("scp -p -P $nport $mac:$bdir/pbgen-$pbprojver-$pbprojtag $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $bdir on $mac");
     656        pb_system("$cpcmd $cp2target/pbgen-$pbprojver-$pbprojtag $ENV{'PBBUILDDIR'} 2> /dev/null","Get package names in $cp2target");
    583657        open(KEEP,"$ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to read $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
    584658        my $src = <KEEP>;
     
    587661        $src =~ s/^ *//;
    588662        pb_mkdir_p("$ENV{'PBBUILDDIR'}/$odir/$over");
    589         # Change pgben to make the next send2ssh happy
     663        # Change pgben to make the next send2target happy
    590664        my $made = "";
    591665        open(KEEP,"> $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag") || die "Unable to write $ENV{'PBBUILDDIR'}/pbgen-$pbprojver-$pbprojtag";
    592666        foreach my $p (split(/ +/,$src)) {
    593667            my $j = basename($p);
    594             pb_system("scp -p -P $nport $mac:\'$bdir/$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $bdir from $mac");
     668            pb_system("$cpcmd $cp2target/\'$p\' $ENV{'PBBUILDDIR'}/$odir/$over 2> /dev/null","Package recovery of $j in $cp2target");
    595669            $made="$made $odir/$over/$j" if (($dtype ne "rpm") || ($j !~ /.src.rpm$/));
    596670        }
    597671        print KEEP "$made\n";
    598672        close(KEEP);
    599         pb_system("ssh -q -p $nport $mac \"rm -rf $tdir $bdir\"","VM cleanup on $mac");
    600         pb_send2ssh("Packages","$odir"."_"."$over");
    601         if (! $vmexist) {
    602             pb_system("ssh -q -p $nport $mac \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $vm halt (pid $vmpid)");
     673        pb_system("$shcmd \"rm -rf $tdir $bdir\"","$cmt cleanup");
     674        pb_send2target("Packages","$odir"."_"."$over");
     675        if ((! $vmexist) && ($cmt eq "vm")) {
     676            pb_system("$shcmd \"sudo /sbin/halt -p \"; sleep $tm ; echo \'if [ -d /proc/$vmpid ]; then kill -9 $vmpid; fi \' | bash ; sleep 10","VM $v halt (pid $vmpid)");
    603677        }
    604678        pb_rm_rf("$ENV{'PBBUILDDIR'}/$odir");
     
    606680}
    607681
    608 sub pb_script2vm {
     682sub pb_script2v {
    609683    my $pbscript=shift;
     684    my $vtype=shift;
    610685
    611686    # Prepare the script to be executed on the VM
     
    616691    }
    617692
    618     my ($vm,$all) = pb_get_vm();
     693    my ($vm,$all) = pb_get_v($vtype);
     694    my ($vmexist,$vmpid) = (undef,undef);
    619695
    620696    foreach my $v (@$vm) {
     697        # Launch the VM/VE
     698        if ($vtype eq "vm") {
     699            ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
     700
     701            # Skip that VM if something went wrong
     702            next if (($vmpid == 0) && ($vmexist ==0));
     703        }
     704
     705        # Gather all required files to send them to the VM
     706        # and launch the build through pbscript
     707        pb_send2target("Script","$v",$vmexist,$vmpid);
     708
     709    }
     710}
     711
     712sub pb_launchv {
     713    my $vtype = shift;
     714    my $v = shift;
     715    my $create = shift || 0;        # By default do not create a VM
     716
     717    die "No VM/VE defined, unable to launch" if (not defined $v);
     718    # Keep only the first VM in case many were given
     719    $v =~ s/,.*//;
     720
     721    # Which is our local arch ? (standardize on i386 for those platforms)
     722    my $arch = `uname -m`;
     723    chomp($arch);
     724    $arch =~ s/i.86/i386/;
     725
     726    # Launch the VMs/VEs
     727    if ($vtype eq "vm") {
     728        die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
     729
     730        my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
     731
     732        my $vmtype = $ptr->{$ENV{'PBPROJ'}};
     733        if (not defined $ENV{'PBVMOPT'}) {
     734            $ENV{'PBVMOPT'} = "";
     735        }
     736        if (defined $vmopt->{$ENV{'PBPROJ'}}) {
     737            $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
     738        }
     739        my $nport = $vmport->{$ENV{'PBPROJ'}};
     740        $nport = "$pbport" if (defined $pbport);
     741   
     742        my $cmd;
     743        my $vmcmd;      # has to be used for pb_check_ps
     744        my $vmm;        # has to be used for pb_check_ps
     745        if ($vmtype eq "qemu") {
     746            my $qemucmd32;
     747            my $qemucmd64;
     748            if ($arch eq "x86_64") {
     749                $qemucmd32 = "/usr/bin/qemu-system-i386";
     750                $qemucmd64 = "/usr/bin/qemu";
     751            } else {
     752                $qemucmd32 = "/usr/bin/qemu";
     753                $qemucmd64 = "/usr/bin/qemu-system-x86_64";
     754            }
     755        if ($v =~ /x86_64/) {
     756                $vmcmd = "$qemucmd64 -no-kqemu";
     757            } else {
     758                $vmcmd = "$qemucmd32";
     759            }
     760            $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$v.qemu";
     761            if ($create != 0) {
     762                $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
     763            }
     764            $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
     765        } elsif ($vmtype eq "xen") {
     766        } elsif ($vmtype eq "vmware") {
     767        } else {
     768            die "VM of type $vmtype not supported. Report to the dev team";
     769        }
     770        my ($tmpcmd,$void) = split(/ +/,$cmd);
     771        my $vmexist = pb_check_ps($tmpcmd,$vmm);
     772        my $vmpid = 0;
     773        if (! $vmexist) {
     774            if ($create != 0) {
     775                if (($vmtype eq "qemu") || ($vmtype eq "xen")) {
     776                    pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
     777                } elsif ($vmtype eq "vmware") {
     778                } else {
     779                }
     780            }
     781            if (! -f "$vmm") {
     782                pb_log(0,"Unable to find VM $vmm\n");
     783            } else {
     784                pb_system("$cmd &","Launching the VM $vmm");
     785                pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $v to come up");
     786                $vmpid = pb_check_ps($tmpcmd,$vmm);
     787            }
     788        } else {
     789            pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
     790        }
     791        return($vmexist,$vmpid);
     792    # VE here
     793    } else {
     794        # Get VE context
     795        my ($ptr,$vepath,$vetmout,$verebuild,$veconf) = pb_conf_get("vetype","vepath","vetmout","verebuild","veconf");
     796        my $vetype = $ptr->{$ENV{'PBPROJ'}};
     797
     798        # Get distro context
     799        my ($name,$ver,$darch) = split(/-/,$v);
     800        chomp($darch);
     801        my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init($name,$ver);
     802
     803        if ($vetype eq "chroot") {
     804            # Architecture consistency
     805            if ($arch ne $darch) {
     806                die "Unable to launch a VE of architecture $darch on a $arch platform" if (not (($darch eq "x86_64") && ($arch =~ /i?86/)));
     807            }
     808
     809            if (($create != 0) || ($verebuild->{$ENV{'PBPROJ'}} eq "true") || ($force == 1)) {
     810                # We have to rebuild the chroot
     811                if ($dtype eq "rpm") {
     812                    pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
     813                    # Once setup we need to install some packages, the pb account, ...
     814                    pb_system("sudo /usr/sbin/mock --install --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" -r $v su","Configuring the mock VE");
     815                    #pb_system("sudo /usr/sbin/mock --init --resultdir=\"/tmp\" --configdir=\"$veconf->{$ENV{'PBPROJ'}}\" --basedir=\"$vepath->{$ENV{'PBPROJ'}}\" -r $v","Creating the mock VE");
     816                } elsif ($dtype eq "deb") {
     817                    pb_system("","Creating the pbuilder VE");
     818                } elsif ($dtype eq "ebuild") {
     819                    die "Please teach the dev team how to build gentoo chroot";
     820                } else {
     821                    die "Unknown distribution type $dtype. Report to dev team";
     822                }
     823            }
     824            # Nothing more to do for VE. No real launch
     825        } else {
     826            die "VE of type $vetype not supported. Report to the dev team";
     827        }
     828    }
     829}
     830
     831sub pb_build2v {
     832
     833my $vtype = shift;
     834
     835# Prepare the script to be executed on the VM/VE
     836# in $ENV{'PBDESTDIR'}/pbscript
     837my ($ntp) = pb_conf_get($vtype."ntp");
     838my $vntp = $ntp->{$ENV{'PBPROJ'}};
     839
     840open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
     841print SCRIPT "#!/bin/bash\n";
     842print SCRIPT "echo ... Execution needed\n";
     843print SCRIPT "# This is in directory delivery\n";
     844print SCRIPT "# Setup the variables required for building\n";
     845print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
     846print SCRIPT "# Preparation for pb\n";
     847print SCRIPT "mv .pbrc \$HOME\n";
     848print SCRIPT "cd ..\n";
     849# Force new date to be in the future compared to the date of the tar file by adding 1 minute
     850my @date=pb_get_date();
     851$date[1]++;
     852my $upddate = strftime("%m%d%H%M%Y", @date);
     853print SCRIPT "echo Setting up date on $vntp...\n";
     854# Or use ntpdate if available TBC
     855print SCRIPT "sudo date $upddate\n";
     856# This exports avoids pb_env_init to deal with PBCONF stuff
     857print SCRIPT "export PBCONF=/tmp\n";
     858print SCRIPT "export PBVER=$ENV{'PBVER'}\n";
     859print SCRIPT "export PBTAG=$ENV{'PBTAG'}\n";
     860print SCRIPT "export PBPACKAGER=\"$ENV{'PBPACKAGER'}\"\n";
     861print SCRIPT "# Build\n";
     862# Get list of packages to build
     863my $ptr = pb_get_pkg($defpkgdir,$extpkgdir);
     864@pkgs = @$ptr;
     865my $p = join(' ',@pkgs) if (@pkgs);
     866print SCRIPT "echo Building packages on $vtype...\n";
     867print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
     868close(SCRIPT);
     869chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
     870
     871my ($v,$all) = pb_get_v($vtype);
     872
     873# Send tar files when we do a global generation
     874pb_build2ssh() if ($all == 1);
     875
     876my ($vmexist,$vmpid) = (undef,undef);
     877
     878foreach my $v (@$v) {
     879    if ($vtype eq "vm") {
    621880        # Launch the VM
    622         my ($vmexist,$vmpid) = pb_launchvm($v,0);
    623 
    624         # Skip that VM if it something went wrong
    625         next if (($vmpid == 0) && ($vmexist ==0));
    626 
    627         # Gather all required files to send them to the VM
    628         # and launch the build thourgh pbscript
    629         pb_send2ssh("Script","$v",$vmexist,$vmpid,"vmhost","vmlogin","$ENV{'PBDESTDIR'}/pbrc","vmport","vmtmout");
    630 
    631     }
    632 }
    633 
    634 sub pb_launchchroot {
    635     # Virtual env.
    636     my $ve = shift;
    637     my $create = shift || 0;        # By default do not create a chroot
    638 
    639     #die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
    640     #die "No VM defined, unable to launch" if (not defined $ve);
    641 
    642     # Keep only the first chroot in case many were given
    643     $ve =~ s/,.*//;
    644 
    645     # Launch the chroot
    646     my ($ptr,$veopt,$veport,$vepath,$vetmout,$vesize) = pb_conf_get("vetype","veopt","veport","vepath","vetmout","vesize");
    647     my $vetype = $ptr->{$ENV{'PBPROJ'}};
    648     if (not defined $ENV{'PBCHROOTOPT'}) {
    649         $ENV{'PBCHROOTOPT'} = "";
    650     }
    651     if (defined $veopt->{$ENV{'PBPROJ'}}) {
    652         $ENV{'PBVMOPT'} .= " $veopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $veopt->{$ENV{'PBPROJ'}}/);
    653     }
    654     my $nport = $veport->{$ENV{'PBPROJ'}};
    655     $nport = "$pbport" if (defined $pbport);
    656 
    657     my $cmd;
    658     my $vecmd;      # has to be used for pb_check_ps
    659     my $vem;        # has to be used for pb_check_ps
    660     if ($vetype eq "qemu") {
    661         my $arch = `uname -m`;
    662         chomp($arch);
    663         my $qemucmd32;
    664         my $qemucmd64;
    665         if ($arch eq "x86_64") {
    666             $qemucmd32 = "/usr/bin/qemu-system-i386";
    667             $qemucmd64 = "/usr/bin/qemu";
    668         } else {
    669             $qemucmd32 = "/usr/bin/qemu";
    670             $qemucmd64 = "/usr/bin/qemu-system-x86_64";
    671         }
    672         if ($ve =~ /_64/) {
    673             $vecmd = "$qemucmd64 -no-kqemu";
    674         } else {
    675             $vecmd = "$qemucmd32";
    676         }
    677         $vem = "$vepath->{$ENV{'PBPROJ'}}/$ve.qemu";
    678         if ($create != 0) {
    679             $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
    680         }
    681         $cmd = "$vecmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vem"
    682     } elsif ($vetype eq "xen") {
    683     } elsif ($vetype eq "vmware") {
    684     } else {
    685         die "VM of type $vetype not supported. Report to the dev team";
    686     }
    687     my ($tmpcmd,$void) = split(/ +/,$cmd);
    688     my $veexist = pb_check_ps($tmpcmd,$vem);
    689     my $vepid = 0;
    690     if (! $veexist) {
    691         if ($create != 0) {
    692             pb_system("/usr/bin/qemu-img create -f qcow2 $vem $vesize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
    693         }
    694         if (! -f "$vem") {
    695             pb_log(0,"Unable to find VM $vem\n");
    696         } else {
    697             pb_system("$cmd &","Launching the VM $vem");
    698             pb_system("sleep $vetmout->{$ENV{'PBPROJ'}}","Waiting for VM $ve to come up");
    699             $vepid = pb_check_ps($tmpcmd,$vem);
    700         }
    701     } else {
    702         pb_log(0,"Found an existing VM $vem (pid $veexist)\n");
    703     }
    704     return($veexist,$vepid);
    705 }
    706 
    707 sub pb_launchvm {
    708     my $vm = shift;
    709     my $create = shift || 0;        # By default do not create a VM
    710 
    711     die "-i iso parameter needed" if (((not defined $iso) || ($iso eq "")) && ($create != 0));
    712     die "No VM defined, unable to launch" if (not defined $vm);
    713     # Keep only the first VM in case many were given
    714     $vm =~ s/,.*//;
    715 
    716     # Launch the VMs
    717     my ($ptr,$vmopt,$vmport,$vmpath,$vmtmout,$vmsize) = pb_conf_get("vmtype","vmopt","vmport","vmpath","vmtmout","vmsize");
    718     my $vmtype = $ptr->{$ENV{'PBPROJ'}};
    719     if (not defined $ENV{'PBVMOPT'}) {
    720         $ENV{'PBVMOPT'} = "";
    721     }
    722     if (defined $vmopt->{$ENV{'PBPROJ'}}) {
    723         $ENV{'PBVMOPT'} .= " $vmopt->{$ENV{'PBPROJ'}}" if ($ENV{'PBVMOPT'} !~ / $vmopt->{$ENV{'PBPROJ'}}/);
    724     }
    725     my $nport = $vmport->{$ENV{'PBPROJ'}};
    726     $nport = "$pbport" if (defined $pbport);
    727 
    728     my $cmd;
    729     my $vmcmd;      # has to be used for pb_check_ps
    730     my $vmm;        # has to be used for pb_check_ps
    731     if ($vmtype eq "qemu") {
    732         my $arch = `uname -m`;
    733         chomp($arch);
    734         my $qemucmd32;
    735         my $qemucmd64;
    736         if ($arch eq "x86_64") {
    737             $qemucmd32 = "/usr/bin/qemu-system-i386";
    738             $qemucmd64 = "/usr/bin/qemu";
    739         } else {
    740             $qemucmd32 = "/usr/bin/qemu";
    741             $qemucmd64 = "/usr/bin/qemu-system-x86_64";
    742         }
    743         if ($vm =~ /_64/) {
    744             $vmcmd = "$qemucmd64 -no-kqemu";
    745         } else {
    746             $vmcmd = "$qemucmd32";
    747         }
    748         $vmm = "$vmpath->{$ENV{'PBPROJ'}}/$vm.qemu";
    749         if ($create != 0) {
    750             $ENV{'PBVMOPT'} .= " -cdrom $iso -boot d";
    751         }
    752         $cmd = "$vmcmd $ENV{'PBVMOPT'} -redir tcp:$nport:10.0.2.15:22 $vmm"
    753     } elsif ($vmtype eq "xen") {
    754     } elsif ($vmtype eq "vmware") {
    755     } else {
    756         die "VM of type $vmtype not supported. Report to the dev team";
    757     }
    758     my ($tmpcmd,$void) = split(/ +/,$cmd);
    759     my $vmexist = pb_check_ps($tmpcmd,$vmm);
    760     my $vmpid = 0;
    761     if (! $vmexist) {
    762         if ($create != 0) {
    763             if (($vmtype eq "qemu") || ($vmtype eq "xen")) {
    764                 pb_system("/usr/bin/qemu-img create -f qcow2 $vmm $vmsize->{$ENV{'PBPROJ'}}","Creating the QEMU VM");
    765             } elsif ($vmtype eq "vmware") {
    766             } else {
    767             }
    768         }
    769         if (! -f "$vmm") {
    770             pb_log(0,"Unable to find VM $vmm\n");
    771         } else {
    772             pb_system("$cmd &","Launching the VM $vmm");
    773             pb_system("sleep $vmtmout->{$ENV{'PBPROJ'}}","Waiting for VM $vm to come up");
    774             $vmpid = pb_check_ps($tmpcmd,$vmm);
    775         }
    776     } else {
    777         pb_log(0,"Found an existing VM $vmm (pid $vmexist)\n");
    778     }
    779     return($vmexist,$vmpid);
    780 }
    781 
    782 sub pb_build2vm {
    783     # Prepare the script to be executed on the VM
    784     # in $ENV{'PBDESTDIR'}/pbscript
    785     my ($ntp) = pb_conf_get("vmntp");
    786     my $vmntp = $ntp->{$ENV{'PBPROJ'}};
    787     open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
    788     print SCRIPT "#!/bin/bash\n";
    789     print SCRIPT "echo ... Execution needed\n";
    790     print SCRIPT "# This is in directory delivery\n";
    791     print SCRIPT "# Setup the variables required for building\n";
    792     print SCRIPT "export PBPROJ=$ENV{'PBPROJ'}\n";
    793     print SCRIPT "# Preparation for pb\n";
    794     print SCRIPT "mkdir -p ../pbconf\n";
    795     print SCRIPT "mv $ENV{'PBPROJ'}.pb ../pbconf\n";
    796     print SCRIPT "mv .pbrc \$HOME\n";
    797     print SCRIPT "cd ..\n";
    798     # Force new date to be in the future compared to the date of the tar file by adding 1 minute
    799     my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
    800     $date[1]++;
    801     my $upddate = strftime("%m%d%H%M%Y", @date);
    802     print SCRIPT "echo Setting up date on $vmntp...\n";
    803     # Or use ntpdate if available
    804     print SCRIPT "sudo date $upddate\n";
    805     print SCRIPT "export PBROOT=\`pwd\`\n";
    806     print SCRIPT "# Build\n";
    807     my $p = "";
    808     $p = join(' ',@ARGV) if (defined $ARGV[0]);
    809     print SCRIPT "echo Building packages on VM...\n";
    810     print SCRIPT "pb -p $ENV{'PBPROJ'} build2pkg $p\n";
    811     close(SCRIPT);
    812     chmod 0755,"$ENV{'PBDESTDIR'}/pbscript";
    813 
    814     my ($vm,$all) = pb_get_vm();
    815 
    816     # Send tar files when we do a global generation
    817     pb_build2ssh() if ($all == 1);
    818 
    819     foreach my $v (@$vm) {
    820         # Launch the VM
    821         my ($vmexist,$vmpid) = pb_launchvm($v,0);
     881        my ($vmexist,$vmpid) = pb_launchv($vtype,$v,0);
    822882
    823883        # Skip that VM if it something went wrong
    824884        next if (($vmpid == 0) && ($vmexist == 0));
    825 
    826         # Gather all required files to send them to the VM
    827         # and launch the build thourgh pbscript
    828         pb_send2ssh("VMs","$v",$vmexist,$vmpid,"vmhost","vmlogin","$ENV{'PBDESTDIR'}/pbrc","vmport","vmtmout");
    829     }
     885    }
     886    # Gather all required files to send them to the VM/VE
     887    # and launch the build thourgh pbscript
     888    pb_send2target($vtype,"$v",$vmexist,$vmpid);
     889}
    830890}
    831891
     
    858918
    859919#
    860 # Return the list of VMs we are working on
     920# Return the list of VMs/VEs we are working on
    861921# $all is a flag to know if we return all of them
    862922# or only some (if all we publish also tar files in addition to pkgs
    863923#
    864 sub pb_get_vm {
    865 
    866 my @vm;
     924sub pb_get_v {
     925
     926my $vtype = shift;
     927my @v;
    867928my $all = 0;
    868 
    869 # Get VM list
    870 if ((not defined $ENV{'PBVM'}) || ($ENV{'PBVM'} =~ /^all$/)) {
    871     my ($ptr) = pb_conf_get("vmlist");
    872     my $ptr2 = $ptr->{$ENV{'PBPROJ'}};
    873     $ptr2 =~ s/,/_64,/g;
    874     $ptr2 =~ s/$/_64/g;
    875     $ENV{'PBVM'} = "$ptr->{$ENV{'PBPROJ'}},$ptr2";
     929my $vlist;
     930my $pbv = 'PBV';
     931
     932if ($vtype eq "vm") {
     933    $vlist = "vmlist";
     934} elsif ($vtype eq "ve") {
     935    $vlist = "velist";
     936}
     937# Get VM/VE list
     938if ((not defined $ENV{$pbv}) || ($ENV{$pbv} =~ /^all$/)) {
     939    my ($ptr) = pb_conf_get($vlist);
     940    $ENV{$pbv} = $ptr->{$ENV{'PBPROJ'}};
    876941    $all = 1;
    877942}
    878 pb_log(2,"VMs: $ENV{'PBVM'}\n");
    879 @vm = split(/,/,$ENV{'PBVM'});
    880 return(\@vm,$all);
     943pb_log(2,"$vtype: $ENV{$pbv}\n");
     944@v = split(/,/,$ENV{$pbv});
     945return(\@v,$all);
     946}
     947
     948sub pb_setup_v {
     949# Function to create a potentialy missing pb account on the VM/VE, and adds it to sudo
     950# Needs to use root account to connect to the VM/VE
     951
     952# pb will take your local public SSH key to access
     953# the pb account in the VM later on
     954
     955my $vtype = shift;
     956
     957my $file = "$ENV{'HOME'}/.ssh/id_dsa.pub";
     958die "Unable to find your public ssh key as $file";
     959
     960open(SCRIPT,"> $ENV{'PBDESTDIR'}/pbscript") || die "Unable to create $ENV{'PBDESTDIR'}/pbscript";
     961print SCRIPT << 'EOF';
     962#!/usr/bin/perl -w
     963
     964$file="/etc/passwd";
     965open(PBFILE,$file) || die "Unable to open $file";
     966my $found = 0;
     967while (<PBFILE>) {
     968    $found = 1 if (/^pb:/);
     969}
     970close(PBFILE);
     971
     972if ( $found == 0 ) {
     973    if ( ! -d "/home" ) {
     974        mkdir "/home";
     975    }
     976    system "groupadd pb";
     977    system "useradd pb -g pb -m -d /home/pb";
     978}
     979
     980# For root
     981mkdir ".ssh",0700;
     982system 'cp /tmp/pbkey .ssh/authorized_keys';
     983chmod 0600,".ssh/authorized_keys";
     984
     985# For pb
     986chdir "/home/pb";
     987mkdir ".ssh",0700;
     988system 'cp /tmp/pbkey .ssh/authorized_keys';
     989chmod 0600,".ssh/authorized_keys";
     990system 'chown -R pb:pb .ssh';
     991
     992# No passwd for pb only keys
     993$file="/etc/shadow";
     994open(PBFILE,$file) || die "Unable to open $file";
     995open(PBOUT,"> $file.new") || die "Unable to open $file.new";
     996while (<PBFILE>) {
     997    s/^pb:\!\!:/pb:*:/;
     998    s/^pb:\!:/pb:*:/;   #SLES 9 e.g.
     999    print PBOUT $_;
     1000}
     1001close(PBFILE);
     1002close(PBOUT);
     1003rename("$file.new",$file);
     1004chmod 0640,$file;
     1005
     1006# pb has to be added to portage group on gentoo
     1007unlink "/tmp/pbkey";
     1008
     1009my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
     1010print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
     1011
     1012# Get and install pb
     1013if ( $ddir eq "fedora" ) {
     1014    system "yum clean all";
     1015    system "yum update -y";
     1016    my $arch=`uname -m`;
     1017    my $opt = "";
     1018    chomp($arch);
     1019    if ($arch eq "x86_64") {
     1020        $opt="--exclude=*.i?86";
     1021    }
     1022
     1023    system "yum -y $opt install rpm-build wget patch ntp sudo perl-DateManip perl-ExtUtils-MakeMaker";
     1024} elsif (( $dfam eq "rh" ) || ($ddir eq "sles") || (($ddir eq "suse") && (($dver eq "10.1") || ($dver eq "10.0"))) || (($ddir eq "mandrake") && ($dver eq "10.1"))) {
     1025    # Suppose pkg are installed already
     1026    system "rpm -e lsb 2>&1 > /dev/null";
     1027    system "rm -rf DateManip* ; wget http://search.cpan.org/CPAN/authors/id/S/SB/SBECK/Date-Manip-5.46.tar.gz ; tar xvfz Date-Manip-5.46.tar.gz ; cd Date-Manip* ; perl Makefile.PL ; make ; make install ; cd .. ";
     1028} elsif ($ddir eq "suse") {
     1029    # New OpenSuSE
     1030    system "export TERM=linux ; liste=\"\" ; for i in make wget patch sudo perl-DateManip perl-File-HomeDir xntp; do rpm -q \$i 1> /dev/null 2> /dev/null ; if [ \$\? != 0 ]; then liste=\"\$liste \$i\"; fi; done; echo \"Liste: \$liste\" ; if [ \"\$liste\" != \"\" ]; then yast2 -i \$liste ; fi";
     1031} elsif ( $dfam eq "md" ) {
     1032        system "urpmi.update -a ; urpmi --auto rpm-build wget sudo patch ntp-client perl-DateManip";
     1033} elsif ( $dfam eq "du" ) {
     1034    if (( $dver eq "3.1" ) && ($ddir eq "debian")) {
     1035        system "apt-get update; apt-get -y install wget patch ssh sudo debian-builder dh-make fakeroot ntpdate libdate-manip-perl";
     1036    } else  {
     1037        system "apt-get update; apt-get -y install wget patch openssh-server dpkg-dev sudo debian-builder dh-make fakeroot ntpdate rses5-dev libdate-manip-perl";
     1038    }
     1039} elsif ( $dfam eq "gen" ) {
     1040        system "emerge -u system ; emerge wget sudo ntp DateManip";
     1041} else {
     1042    print "No pkg to install\n";
     1043}
     1044
     1045# Adapt sudoers
     1046$file="/etc/sudoers";
     1047open(PBFILE,$file) || die "Unable to open $file";
     1048open(PBOUT,"> $file.new") || die "Unable to open $file.new";
     1049while (<PBFILE>) {
     1050    next if (/^pb   /);
     1051    s/Defaults[ \t]+requiretty//;
     1052    print PBOUT $_;
     1053}
     1054close(PBFILE);
     1055print PBOUT "pb   ALL=(ALL) NOPASSWD:ALL\n";
     1056close(PBOUT);
     1057rename("$file.new",$file);
     1058chmod 0440,$file;
     1059
     1060# Suse wants sudoers as 640
     1061if (($ddir eq "sles") || (($ddir eq "suse")) && ($dver ne "10.3")) {
     1062    chmod 0640,$file;
     1063}
     1064
     1065# Sync date
     1066system "/usr/sbin/ntpdate ntp.pool.org";
     1067
     1068system "rm -rf project-builder-* ; wget --passive-ftp ftp://ftp.mondorescue.org/src/project-builder-latest.tar.gz ; tar xvfz project-builder-latest.tar.gz ; cd project-builder-* ; perl Makefile.PL ; make ; make install ; cd ..";
     1069EOF
     1070close(SCRIPT);
    8811071}
    8821072
     
    9591149    print "-m machine: Name of the Virtual Machines (VM) you want\n";
    9601150    print "            to build on (coma separated). All if none precised\n";
    961     print "            (or use the env variable PBVM)       \n";
     1151    print "            (or use the env variable PBV)       \n";
    9621152    print "\n";
    9631153    print "-s script:  Name of the script you want\n";
     
    10031193    print "\t              VM type supported are QEMU            \n";
    10041194    print "\n";
    1005     print "\tbuild2chroot: Create packages in a chroot, creating it if needed\n";
     1195    print "\tbuild2ve:     Create packages in VEs, creating it if needed\n";
    10061196    print "\t              and send those packages to a SSH host once built\n";
    10071197    print "\n";
    10081198    print "\tcms2vm:       cms2build + build2vm\n";
    10091199    print "\n";
     1200    print "\tcms2ve:       cms2build + build2ve\n";
     1201    print "\n";
    10101202    print "\tlaunchvm:     Launch one virtual machine\n";
     1203    print "\n";
     1204    print "\tlaunchve:     Launch one virtual environment\n";
    10111205    print "\n";
    10121206    print "\tscript2vm:    Launch one virtual machine if needed        \n";
    10131207    print "\t              and executes a script on it                 \n";
    10141208    print "\n";
     1209    print "\tscript2ve:    Execute a script in a virtual environment       \n";
     1210    print "\n";
    10151211    print "\tnewvm:        Create a new virtual machine\n";
    10161212    print "\n";
    1017     print "\tnewchroot:    Create a new chroot environment\n";
     1213    print "\tnewve:        Create a new virtual environment\n";
    10181214    print "\n";
    10191215    print "\tnewver:       Create a new version of the project derived \n";
  • devel/pb/lib/ProjectBuilder/Base.pm

    r319 r320  
    1212use File::Basename;
    1313use File::Path;
     14use File::stat;
    1415use File::Copy;
    1516use File::Temp qw(tempdir);
     
    3132
    3233our @ISA = qw(Exporter);
    33 our @EXPORT = qw(pb_env_init pb_conf_read pb_conf_get pb_conf_get_if pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_filter_file_inplace pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout pb_get_date pb_log pb_log_init pb_get_pkg $debug $LOG);
     34our @EXPORT = qw(pb_env_init pb_conf_read pb_conf_read_if pb_conf_get pb_conf_get_if pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_filter_file_inplace pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout pb_get_date pb_log pb_log_init pb_get_pkg $debug $LOG);
    3435
    3536$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
     
    180181
    181182#
     183# The following part is only useful when in cms2build
     184# In VMs/VEs we want to skip that by providing a good PBCONF env var.
     185# return values in that case are useless
     186#
     187return if (defined $ENV{'PBCONF'});
     188
     189#
    182190# Check pbconf compliance
    183191#
     
    216224        my $maxmtime = 0;
    217225        foreach my $d (readdir(DIR)) {
     226            pb_log(3,"Looking at \'$d\'...");
    218227            next if ($d =~ /^\./);
    219             next if (! -d $d);
    220             my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)
    221                           = stat($d);
     228            next if (! -d "$ENV{'PBCONF'}/$d");
     229            my $s = stat("$ENV{'PBCONF'}/$d");
     230            next if (not defined $s);
     231            pb_log(3,"KEEP\n");
    222232            # Keep the most recent
    223             pb_log(2,"Looking at $d: $mtime\n");
    224             if ($mtime > $maxmtime) {
     233            pb_log(2," $s->mtime\n");
     234            if ($s->mtime > $maxmtime) {
    225235                $ENV{'PBROOT'} = "$ENV{'PBCONF'}/$d";
    226                 $maxmtime = $mtime;
     236                $maxmtime = $s->mtime;
    227237            }
    228238        }
     
    251261if ((-f "$ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
    252262    # List of pkg to build by default (mandatory)
    253     my ($defpkgdir) = pb_conf_get("defpkgdir");
     263    my ($defpkgdir,$pbpackager) = pb_conf_get("defpkgdir","pbpackager");
    254264    # List of additional pkg to build when all is called (optional)
    255265    # Valid version names (optional)
     
    288298    }
    289299    die "Invalid tag name $ENV{'PBTAG'} in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBTAG'} !~ /[0-9.]+/);
     300
     301
     302    if (not defined $ENV{'PBPACKAGER'}) {
     303        if ((defined $pbpackager) && (defined $pbpackager->{$ENV{'PBPROJ'}})) {
     304            $ENV{'PBPACKAGER'}=$pbpackager->{$ENV{'PBPROJ'}};
     305        } else {
     306            die "No pbpackager found in $ENV{'PBROOT'}/$ENV{'PBPROJ'}.pb";
     307        }
     308    }
    290309} else {
    291310    if (defined $pbinit) {
     
    317336# Packager label
    318337#
    319 #packager $ENV{'PBPROJ'} = "William Porte <bill\@$ENV{'PBPROJ'}.org>"
     338#pbpackager $ENV{'PBPROJ'} = "William Porte <bill\@$ENV{'PBPROJ'}.org>"
    320339#
    321340
     
    960979    push @ptr,$h{$param};
    961980}
    962 pb_log(2,"DEBUG: h:".Dumper(%h)." param:".Dumper(@param)." ptr:".Dumper(@ptr)."\n");
    963981return(@ptr);
    964982}
     
    10551073    } else {
    10561074        $tmp = $destdir."/".basename($source);
     1075        pb_mkdir_p($destdir);
    10571076    }
    10581077    pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
    10591078} elsif ($scheme eq "dir") {
    1060     if (-d $source) {
    1061         $tmp = $destdir;
    1062     } else {
    1063         $tmp = $destdir."/".basename($source);
    1064     }
    1065     pb_system("cp -a $source $tmp","Exporting $source from DIR to $tmp");
     1079    pb_system("cp -a $path $destdir","Copying $uri from DIR to $destdir");
    10661080} elsif (($scheme eq "http") || ($scheme eq "ftp")) {
    10671081    my $f = basename($path);
    10681082    unlink "$ENV{'PBTMP'}/$f";
    10691083    if (-x "/usr/bin/wget") {
    1070         pb_system("/usr/bin/wget -nv -O $ENV{'PBTMP'}/$f $uri","Downloading $uri with wget to $ENV{'PBTMP'}/$f\n");
     1084        pb_system("/usr/bin/wget -nv -O $ENV{'PBTMP'}/$f $uri"," ");
    10711085    } elsif (-x "/usr/bin/curl") {
    10721086        pb_system("/usr/bin/curl $uri -o $ENV{'PBTMP'}/$f","Downloading $uri with curl to $ENV{'PBTMP'}/$f\n");
     
    10791093    my $mm = mimetype($path);
    10801094    pb_log(2,"mimetype: $mm\n");
     1095    pb_mkdir_p($destdir);
    10811096
    10821097    if ($mm =~ /\/x-bzip-compressed-tar$/) {
    10831098        # tar+bzip2
     1099        pb_system("cd $destdir ; tar xfj $path","Extracting $path in $destdir");
    10841100    } elsif ($mm =~ /\/x-lzma-compressed-tar$/) {
    10851101        # tar+lzma
     1102        pb_system("cd $destdir ; tar xfY $path","Extracting $path in $destdir");
    10861103    } elsif ($mm =~ /\/x-compressed-tar$/) {
    10871104        # tar+gzip
     1105        pb_system("cd $destdir ; tar xfz $path","Extracting $path in $destdir");
    10881106    } elsif ($mm =~ /\/x-tar$/) {
    10891107        # tar
     1108        pb_system("cd $destdir ; tar xf $path","Extracting $path in $destdir");
    10901109    } elsif ($mm =~ /\/zip$/) {
    10911110        # zip
    1092     }
    1093     pb_log(0,"scheme file not implemented yet\n");
     1111        pb_system("cd $destdir ; unzip $path","Extracting $path in $destdir");
     1112    }
     1113    # Maybe we created an extra level of dir under destdir
     1114    opendir(DIR,$destdir) || die "Unable to open $destdir";
     1115    my $cnt = 0;
     1116    my $d0;
     1117    foreach my $d (readdir(DIR)) {
     1118        pb_log(3,"Looking at \'$d\'...");
     1119        next if ($d =~ /^\./);
     1120        $cnt++;
     1121        $d0 = $d;
     1122    }
     1123    closedir(DIR);
     1124    # Fix that by moving everything below that extra dir under destdir
     1125    # and remove the extra dir
     1126    if ($cnt == 1) {
     1127        pb_system("cd $destdir/$d0 ; mv * .??* .. 2>/dev/null");
     1128        pb_rm_rf("$destdir/$d0");
     1129    }
    10941130} elsif ($scheme eq "cvs") {
    10951131    my $dir=dirname($destdir);
     
    11211157return if ($authors eq "/dev/null");
    11221158open(SAUTH,$authors) || die "Unable to open $authors";
    1123 open(DAUTH,"> $dest/AUTHORS") || die "Unable to create $dest/AUTHORS";
     1159# Save a potentially existing AUTHORS file and write instead toi AUTHORS.pb
     1160my $ext = "";
     1161if (-f "$dest/AUTHORS") {
     1162    $ext = ".pb";
     1163}
     1164open(DAUTH,"> $dest/AUTHORS$ext") || die "Unable to create $dest/AUTHORS$ext";
    11241165print DAUTH "Authors of the project are:\n";
    11251166print DAUTH "===========================\n";
     
    11291170    print DAUTH "$gcos";
    11301171    if (defined $scheme) {
    1131         print DAUTH " ($nick under $scheme)\n";
     1172        # Do not give a scheme for flat types
     1173        my $endstr="";
     1174        if ("$ENV{'PBREVISION'}" ne "flat") {
     1175            $endstr = " under $scheme";
     1176        }
     1177        print DAUTH " ($nick$endstr)\n";
    11321178    } else {
    11331179        print DAUTH "\n";
     
    11391185
    11401186sub pb_cms_log {
     1187
    11411188my $scheme = shift;
    11421189my $pkgdir = shift;
     
    11471194pb_create_authors($authors,$dest,$scheme);
    11481195
    1149 if ($scheme eq "svn") {
     1196if ($scheme =~ /^svn/) {
    11501197    if (! -f "$dest/ChangeLog") {
    11511198        if (-x "/usr/bin/svn2cl") {
     
    11561203        }
    11571204    }
    1158 } elsif ($scheme eq "flat") {
     1205} elsif (($scheme eq "file") || ($scheme eq "dir") || ($scheme eq "http") || ($scheme eq "ftp")) {
    11591206    if (! -f "$dest/ChangeLog") {
    11601207        pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
     
    12221269
    12231270if ($scheme =~ /^svn/) {
    1224     pb_system("svn co $url $destination","Checking $url to $destination ");
     1271    pb_system("svn co $url $destination","Checking out $url to $destination ");
    12251272} elsif ($scheme eq "flat") {
    12261273} elsif ($scheme eq "cvs") {
  • devel/pb/lib/ProjectBuilder/Changelog.pm

    r315 r320  
    5252my $ver;
    5353my $ver2;
    54 my ($packager) = pb_conf_get("packager");
     54my ($packager) = pb_conf_get("pbpackager");
    5555
    5656# If we don't need to do it, or don't have it fake something
  • devel/pbconf/pb.pb

    r293 r320  
    99# Which CMS system is used
    1010#
    11 cms pb = svn
     11pburl pb =  svn+ssh://www.dploy.org/mondo/svn/pb
    1212
    1313#
    1414# Packager label
    1515#
    16 packager pb = Bruno Cornec <bruno@project-builder.org>
     16pbpackager pb = Bruno Cornec <bruno@project-builder.org>
    1717
    1818#
     
    3232# a QEMU rhel_3 here means that the VM will be named rhel_3.qemu
    3333#
    34 vmlist pb = mandrake_10.1,mandrake_10.2,mandriva_2006.0,mandriva_2007.0,mandriva_2007.1,mandriva_2008.0,redhat_7.3,redhat_9,fedora_4,fedora_5,fedora_6,fedora_7,rhel_3,rhel_4,rhel_5,suse_10.0,suse_10.1,suse_10.2,suse_10.3,sles_9,sles_10,gentoo_nover,debian_3.1,debian_4.0,ubuntu_6.06,ubuntu_7.04,ubuntu_7.10
     34vmlist collectl = mandrake-10.1-i386,mandrake-10.2-i386,mandriva-2006.0-i386,mandriva-2007.0-i386,mandriva-2007.1-i386,mandriva-2008.0-i386,redhat-7.3-i386,redhat-9-i386,fedora-4-i386,fedora-5-i386,fedora-6-i386,rhel-3-i386,rhel-4-i386,rhel-5-i386,suse-10.0-i386,suse-10.1-i386,suse-10.2-i386,suse-10.3-i386,sles-9-i386,sles-10-i386,gentoo-nover-i386,debian-3.1-i386,debian-4.0-i386,ubuntu-6.06-i386,ubuntu-7.04-i386,ubuntu-7.10-i386,mandriva-2007.0-x86_64,mandriva-2007.1-x86_64,mandriva-2008.0-x86_64,fedora-6-x86_64,fedora-8-x86_64,rhel-4-x86_64,rhel-5-x86_64,suse-10.2-x86_64,suse-10.3-x86_64,sles-10-x86_64,gentoo-nover-x86_64,debian-4.0-x86_64,ubuntu-7.04-x86_64,ubuntu-7.10-x86_64
    3535
     36velist pb = fedora-7-i386
     37
     38pbarch pb = noarch
     39
     40vetype pb = chroot
     41ventp default =  pool.ntp.org
     42velogin pb = pb
     43vepath pb = /var/lib/mock
     44veconf pb = /etc/mock
     45verebuild pb = false
    3646#
    3747# Valid values for vmtype are
Note: See TracChangeset for help on using the changeset viewer.