Changeset 2049 in ProjectBuilder


Ignore:
Timestamp:
Feb 20, 2016, 8:31:42 PM (8 years ago)
Author:
Bruno Cornec
Message:
  • Adds a script to check pb version in VMs/VEs
  • Using -s option requires a full path name for the script to work, which is now checked
  • pb_send2target seems to have a useless parameter. First attempt to check that
  • Do not call pb_ssh_get when pushing packages to ftp repo
  • Update the pbscript hash for key $v with the one passed in param with -s in additin to the default key to fix pb_send2target
  • Use id_* keys only when not in create mode (delivery to repo). Otherwise use pb_* keys
Location:
devel
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r2048 r2049  
    762762if (defined $opts{'s'}) {
    763763    $pbscript{'default'} = $opts{'s'};
     764    die "option -s requires a script having a full path name" if ($pbscript{'default'} !~ /^\//);
    764765}
    765766if (defined $opts{'a'}) {
     
    19691970
    19701971    my $cmt = shift;
    1971     my $pbscript = shift;
     1972    my $pbscript1 = shift;
    19721973    my $v = shift;
    19731974    my $vexist = shift;         # 0 is FALSE
     
    25382539        $cptarget = "CPAN";
    25392540    } else {
    2540         my $keyfile = pb_ssh_get(0,$mac,$nport);
    25412541        my $keyopt = "";
    2542         $keyopt = "-i $keyfile" if ((defined $keyfile) && ($cmt !~ /Packages/));
     2542        if ($cmt !~ /Packages/) {
     2543            my $keyfile = pb_ssh_get(0,$remhost,$nport);
     2544            $keyopt = "-i $keyfile" if (defined $keyfile);
     2545        }
    25432546        my $sshcmd = pb_check_req("ssh",1);
    25442547        my $scpcmd = pb_check_req("scp",1);
     
    26252628
    26262629    # Use the right script name depending on context
    2627     my $pbscript1;
     2630    my $pbscript2;
    26282631    if (($cmt =~ /^(V[EM]|RM)/) || ($cmt =~ /Packages/)){
    2629         $pbscript1 = $pbscript{$v};
     2632        $pbscript2 = $pbscript{$v};
    26302633    } else {
    2631         $pbscript1 = "pbscript";
     2634        $pbscript2 = "pbscript";
    26322635    }
    26332636
     
    26372640    if ($cmt ne "CPAN") {
    26382641        if (($cmt =~ /^VE/) && ($vetype eq "docker") && ($pbstep < 3)) {
    2639             copy("$pbscript1","$context");
    2640             my $s = basename($pbscript1);
     2642            copy("$pbscript2","$context");
     2643            my $s = basename($pbscript2);
    26412644            print DOCKER "COPY $s $cptarget/\n";
    26422645            # call directly with perl to avoid text file busy error messages
     
    26462649            close(DOCKER);
    26472650        } elsif (($cmt =~ /^VE/) && ($vetype eq "docker") && ($pbstep >= 3)) {
    2648             $dkcmd = "/bin/bash $homedir/$tdir-2/".basename($pbscript1);
     2651            $dkcmd = "/bin/bash $homedir/$tdir-2/".basename($pbscript2);
    26492652        } else {
    2650             my $s = basename($pbscript1);
     2653            my $s = basename($pbscript2);
    26512654            $shcmd .= " \"echo \'cd $tdir ; if [ -x $s ]; then ./$s; fi ;  if [ $pbkeep == 0 ]; then rm -f $s; fi\' | bash\"";
    26522655        }
     
    26662669            $tsrc .= " ".basename($f);
    26672670        }
    2668         my $ts = "$ENV{'PBTMP'}/vebuild/".basename($pbscript1);
     2671        my $ts = "$ENV{'PBTMP'}/vebuild/".basename($pbscript2);
    26692672        open(DOCKER," > $ts") || confess "Unable to create $ts";
    26702673        print DOCKER "#!/bin/bash\n";
     
    26772680        print DOCKER "done\n";
    26782681        print DOCKER "(cd $homedir/$tdir-2 ; ls -al)\n";
    2679         print DOCKER pb_get_content($pbscript1);
     2682        print DOCKER pb_get_content($pbscript2);
    26802683        print DOCKER "\n# Get content back from guest in a host dir\n";
    26812684        # Host dir seen as TDIR in container
     
    27472750        }
    27482751    }
    2749     unlink("$pbscript{$v}") if ((($cmt =~ /^(V[ME]|RM)/) || ($cmt =~ /Packages/)) && ($pbkeep eq 0));
     2752    unlink("$pbscript{$v}") if ((($cmt =~ /^(V[ME]|RM)/) || ($cmt =~ /Packages/)) && ($pbkeep eq 0) && ($cmt !~ /Script/));
    27502753
    27512754    pb_log(2,"Before halt, vexist: $vexist, vpid: $vpid\n");
     
    28102813
    28112814pb_log(2,"DEBUG: pb_script2v($vtype,$pbstep,$pbforce,$snapme)\n");
    2812 pb_log(2,"DEBUG: pb_script2v(pbscript: ".Dumper($pbscript)."\n");
     2815pb_log(2,"DEBUG: pb_script2v(pbscript: ".Dumper($pbscript)."\n") if (defined $pbscript);
    28132816pb_parallel_launchv($pbscript,$vtype,uc($vtype)."Script",$pbstep,$pbimage,$pbforce,$snapme,$pbsnap);
    28142817}
     
    28672870    $pm->start($counter) and next if (defined $pbparallel);
    28682871   
     2872    # If launched via script2v then get the script passed as the one for the that VM
     2873    if (not defined $pbscript->{$v}) {
     2874        $pbscript->{$v} = $pbscript->{'default'};
     2875    }
     2876    #
    28692877    # Launch a single operation
    2870     my $pbscript = $pbscript->{$v} if (defined $pbscript->{$v});
    2871     $pbscript = $pbscript->{'default'} if (not defined $pbscript);
    2872     ($vexist,$vpid) = pb_launchv($pbscript,$vtype,$v,$action,$pbstep,$pbforce,$snapme,$pbsnap,$pbimage);
     2878    ($vexist,$vpid) = pb_launchv($pbscript->{$v},$vtype,$v,$action,$pbstep,$pbforce,$snapme,$pbsnap,$pbimage);
    28732879   
    28742880    # Skip that VM/RM if something went wrong
     
    28872893sub pb_launchv {
    28882894
    2889 my $pbscript=shift;
     2895my $pbscript1=shift;        # Just the script name to execute, not the hash
    28902896my $vtype = shift;
    28912897my $v = shift;              # Only 1 VM/VE/RM treated here
     
    29132919pb_log(2,"DEBUG: pb_launchv(vtype,v,step,force,snapme,usesnap: $vtype,$v,$pbstep,$pbforce,$snapme,$usesnap)\n");
    29142920pb_log(2,"DEBUG: pb_launchv(pbimage: $pbimage)\n") if (defined $pbimage);
    2915 pb_log(2,"DEBUG: pb_launchv(pbimage: $pbscript)\n") if (defined $pbscript);
     2921pb_log(2,"DEBUG: pb_launchv(pbscript $pbscript1)\n") if (defined $pbscript1);
    29162922pb_log(2,"DEBUG: pb_launchv(action: $action)\n") if (defined $action);
    29172923# Keep only the first VM in case many were given
     
    30983104if (defined $action) {
    30993105    pb_log(2,"DEBUG: Before send2target, vexist: $vexist, vpid: $vpid, vtype: $vtype, v: $v, action: $action\n");
    3100     pb_send2target($action,$pbscript,$v,$vexist,$vpid,$snapme,$pbstep);
     3106    pb_send2target($action,$pbscript1,$v,$vexist,$vpid,$snapme,$pbstep);
    31013107}
    31023108return($vexist,$vpid);
     
    44744480sub pb_ssh_get {
    44754481
    4476 my $create = shift || 0;    # Do not create keys by default
     4482my $create = shift || 0;    # Do not create keys by default. In that case prefer native keys, not pb's ones
    44774483my $target = shift || "localhost";
    44784484my $nport = shift || "22";
     
    44914497while(<SCAN>) {
    44924498    $ecdsa = 1 if ($_ =~ /ecdsa-/);
     4499    pb_log(2,"Found ECDSA support on $target ($nport)\n");
    44934500}
    44944501close(SCAN);
     
    44974504while(<SCAN>) {
    44984505    $dsa = 1 if ($_ =~ /dsa-/);
     4506    pb_log(2,"Found DSA support on $target ($nport)\n");
    44994507}
    45004508close(SCAN);
     
    45124520# We still favoud DSA and fall back to ECDSA if not available
    45134521if ($dsa != 0) {
    4514     $keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa") ;
    4515     # And we favour a specific key over a generic one
     4522    # And we favour a specific key over a generic one except if in delivery to ftp server
     4523    $keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if ((-s "$ENV{'HOME'}/.ssh/id_dsa") && ($create eq 0));
    45164524    $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
    45174525} else {
    4518     $keyfile = "$ENV{'HOME'}/.ssh/id_ecdsa" if ((-s "$ENV{'HOME'}/.ssh/id_ecdsa") && ($ecdsa != 0));
    4519     # And we favour a specific key over a generic one
     4526    # And we favour a specific key over a generic one except if in delivery to ftp server
     4527    $keyfile = "$ENV{'HOME'}/.ssh/id_ecdsa" if ((-s "$ENV{'HOME'}/.ssh/id_ecdsa") && ($ecdsa != 0) && ($create eq 0));
    45204528    $keyfile = "$ENV{'HOME'}/.ssh/pb_ecdsa" if ((-s "$ENV{'HOME'}/.ssh/pb_ecdsa") && ($ecdsa != 0));
    45214529}
    45224530die "Unable to find your public ssh key under $ENV{'HOME'}/.ssh" if (not defined $keyfile);
     4531pb_log(2,"Using ssh key file $keyfile\n");
    45234532return($keyfile);
    45244533}
     
    49344943my $vmhost;
    49354944
     4945pb_log(1,"Entering pb_ssh_setup\n");
    49364946($vmhost) = pb_conf_get($vtype."host");
    49374947# Prepare the key to be used and transfered remotely
Note: See TracChangeset for help on using the changeset viewer.