Changeset 2050 in ProjectBuilder


Ignore:
Timestamp:
Feb 20, 2016, 8:37:15 PM (8 years ago)
Author:
Bruno Cornec
Message:
  • Fix a bug in script2v by initializing pbstep to 3 as it wasn't defined (use mode)
  • Only use ECDSA ssh mode when DSA is not available to preserve compatibility
  • Using -s option requires a full path name for the script to work, which is now checked
  • 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
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 0.13.2/pb/bin/pb

    r2046 r2050  
    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");
     
    28072810$pbforce = 0 if (not defined $pbforce);
    28082811$snapme = 0 if (not defined $snapme);
     2812$pbstep = 3 if (not defined $pbstep);
    28092813
    28102814pb_log(2,"DEBUG: pb_script2v($vtype,$pbstep,$pbforce,$snapme)\n");
    2811 pb_log(2,"DEBUG: pb_script2v(pbscript: ".Dumper($pbscript)."\n");
     2815pb_log(2,"DEBUG: pb_script2v(pbscript: ".Dumper($pbscript)."\n") if (defined $pbscript);
    28122816pb_parallel_launchv($pbscript,$vtype,uc($vtype)."Script",$pbstep,$pbimage,$pbforce,$snapme,$pbsnap);
    28132817}
     
    28662870    $pm->start($counter) and next if (defined $pbparallel);
    28672871   
     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    #
    28682877    # Launch a single operation
    2869     my $pbscript = $pbscript->{$v} if (defined $pbscript->{$v});
    2870     $pbscript = $pbscript->{'default'} if (not defined $pbscript);
    2871     ($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);
    28722879   
    28732880    # Skip that VM/RM if something went wrong
     
    28862893sub pb_launchv {
    28872894
    2888 my $pbscript=shift;
     2895my $pbscript1=shift;        # Just the script name to execute, not the hash
    28892896my $vtype = shift;
    28902897my $v = shift;              # Only 1 VM/VE/RM treated here
     
    29122919pb_log(2,"DEBUG: pb_launchv(vtype,v,step,force,snapme,usesnap: $vtype,$v,$pbstep,$pbforce,$snapme,$usesnap)\n");
    29132920pb_log(2,"DEBUG: pb_launchv(pbimage: $pbimage)\n") if (defined $pbimage);
    2914 pb_log(2,"DEBUG: pb_launchv(pbimage: $pbscript)\n") if (defined $pbscript);
     2921pb_log(2,"DEBUG: pb_launchv(pbscript $pbscript1)\n") if (defined $pbscript1);
    29152922pb_log(2,"DEBUG: pb_launchv(action: $action)\n") if (defined $action);
    29162923# Keep only the first VM in case many were given
     
    30973104if (defined $action) {
    30983105    pb_log(2,"DEBUG: Before send2target, vexist: $vexist, vpid: $vpid, vtype: $vtype, v: $v, action: $action\n");
    3099     pb_send2target($action,$pbscript,$v,$vexist,$vpid,$snapme,$pbstep);
     3106    pb_send2target($action,$pbscript1,$v,$vexist,$vpid,$snapme,$pbstep);
    31003107}
    31013108return($vexist,$vpid);
     
    44734480sub pb_ssh_get {
    44744481
    4475 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
    44764483my $target = shift || "localhost";
    44774484my $nport = shift || "22";
     
    44864493# Check whether ecdsa is accepted by the remote host
    44874494my $ecdsa = 0;
     4495my $dsa = 0;
    44884496open(SCAN,"ssh-keyscan -p $nport -t ecdsa $target 2>/dev/null |") || pb_log(0,"Unable to check ECDSA support for $target");
    44894497while(<SCAN>) {
    44904498    $ecdsa = 1 if ($_ =~ /ecdsa-/);
     4499    pb_log(2,"Found ECDSA support on $target ($nport)\n");
    44914500}
    44924501close(SCAN);
    44934502
    4494 # We have specific keys by default
    4495 $keyfile = "$ENV{'HOME'}/.ssh/pb_ecdsa";
    4496 if (!(-e $keyfile) && ($create eq 1)) {
    4497     my $res = pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t ecdsa","Generating ECDSA SSH keys for pb");
    4498     $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
    4499     if (($res != 0) && !(-e $keyfile) && ($create eq 1)) {
     4503open(SCAN,"ssh-keyscan -p $nport -t dsa $target 2>/dev/null |") || pb_log(0,"Unable to check DSA support for $target");
     4504while(<SCAN>) {
     4505    $dsa = 1 if ($_ =~ /dsa-/);
     4506    pb_log(2,"Found DSA support on $target ($nport)\n");
     4507}
     4508close(SCAN);
     4509
     4510# We have specific keys by default - create them if needed
     4511if (!(-e "$ENV{'HOME'}/.ssh/pb_ecdsa") && ($create eq 1)) {
     4512    my $res = pb_system("ssh-keygen -q -b 1024 -N '' -f $ENV{'HOME'}/.ssh/pb_ecdsa -t ecdsa","Generating ECDSA SSH keys for pb");
     4513    if (($res != 0) && !(-e "$ENV{'HOME'}/.ssh/pb_dsa") && ($create eq 1)) {
    45004514        # ecdsa may not be supported if old ssh
    4501         pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating DSA SSH keys for pb");
    4502     }
    4503 }
    4504 
    4505 $keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
    4506 $keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa");
    4507 $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
    4508 $keyfile = "$ENV{'HOME'}/.ssh/pb_ecdsa" if ((-s "$ENV{'HOME'}/.ssh/pb_ecdsa") && ($ecdsa != 0));
     4515        pb_system("ssh-keygen -q -b 1024 -N '' -f $ENV{'HOME'}/.ssh/pb_dsa -t dsa","Generating DSA SSH keys for pb");
     4516    }
     4517}
     4518
     4519#$keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa");
     4520# We still favoud DSA and fall back to ECDSA if not available
     4521if ($dsa != 0) {
     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));
     4524    $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa");
     4525} else {
     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));
     4528    $keyfile = "$ENV{'HOME'}/.ssh/pb_ecdsa" if ((-s "$ENV{'HOME'}/.ssh/pb_ecdsa") && ($ecdsa != 0));
     4529}
    45094530die "Unable to find your public ssh key under $ENV{'HOME'}/.ssh" if (not defined $keyfile);
     4531pb_log(2,"Using ssh key file $keyfile\n");
    45104532return($keyfile);
    45114533}
     
    49214943my $vmhost;
    49224944
     4945pb_log(1,"Entering pb_ssh_setup\n");
    49234946($vmhost) = pb_conf_get($vtype."host");
    49244947# Prepare the key to be used and transfered remotely
Note: See TracChangeset for help on using the changeset viewer.