Changeset 2050 in ProjectBuilder
- Timestamp:
- Feb 20, 2016, 8:37:15 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
0.13.2/pb/bin/pb
r2046 r2050 762 762 if (defined $opts{'s'}) { 763 763 $pbscript{'default'} = $opts{'s'}; 764 die "option -s requires a script having a full path name" if ($pbscript{'default'} !~ /^\//); 764 765 } 765 766 if (defined $opts{'a'}) { … … 1969 1970 1970 1971 my $cmt = shift; 1971 my $pbscript = shift;1972 my $pbscript1 = shift; 1972 1973 my $v = shift; 1973 1974 my $vexist = shift; # 0 is FALSE … … 2538 2539 $cptarget = "CPAN"; 2539 2540 } else { 2540 my $keyfile = pb_ssh_get(0,$mac,$nport);2541 2541 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 } 2543 2546 my $sshcmd = pb_check_req("ssh",1); 2544 2547 my $scpcmd = pb_check_req("scp",1); … … 2625 2628 2626 2629 # Use the right script name depending on context 2627 my $pbscript 1;2630 my $pbscript2; 2628 2631 if (($cmt =~ /^(V[EM]|RM)/) || ($cmt =~ /Packages/)){ 2629 $pbscript 1= $pbscript{$v};2632 $pbscript2 = $pbscript{$v}; 2630 2633 } else { 2631 $pbscript 1= "pbscript";2634 $pbscript2 = "pbscript"; 2632 2635 } 2633 2636 … … 2637 2640 if ($cmt ne "CPAN") { 2638 2641 if (($cmt =~ /^VE/) && ($vetype eq "docker") && ($pbstep < 3)) { 2639 copy("$pbscript 1","$context");2640 my $s = basename($pbscript 1);2642 copy("$pbscript2","$context"); 2643 my $s = basename($pbscript2); 2641 2644 print DOCKER "COPY $s $cptarget/\n"; 2642 2645 # call directly with perl to avoid text file busy error messages … … 2646 2649 close(DOCKER); 2647 2650 } elsif (($cmt =~ /^VE/) && ($vetype eq "docker") && ($pbstep >= 3)) { 2648 $dkcmd = "/bin/bash $homedir/$tdir-2/".basename($pbscript 1);2651 $dkcmd = "/bin/bash $homedir/$tdir-2/".basename($pbscript2); 2649 2652 } else { 2650 my $s = basename($pbscript 1);2653 my $s = basename($pbscript2); 2651 2654 $shcmd .= " \"echo \'cd $tdir ; if [ -x $s ]; then ./$s; fi ; if [ $pbkeep == 0 ]; then rm -f $s; fi\' | bash\""; 2652 2655 } … … 2666 2669 $tsrc .= " ".basename($f); 2667 2670 } 2668 my $ts = "$ENV{'PBTMP'}/vebuild/".basename($pbscript 1);2671 my $ts = "$ENV{'PBTMP'}/vebuild/".basename($pbscript2); 2669 2672 open(DOCKER," > $ts") || confess "Unable to create $ts"; 2670 2673 print DOCKER "#!/bin/bash\n"; … … 2677 2680 print DOCKER "done\n"; 2678 2681 print DOCKER "(cd $homedir/$tdir-2 ; ls -al)\n"; 2679 print DOCKER pb_get_content($pbscript 1);2682 print DOCKER pb_get_content($pbscript2); 2680 2683 print DOCKER "\n# Get content back from guest in a host dir\n"; 2681 2684 # Host dir seen as TDIR in container … … 2747 2750 } 2748 2751 } 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/)); 2750 2753 2751 2754 pb_log(2,"Before halt, vexist: $vexist, vpid: $vpid\n"); … … 2807 2810 $pbforce = 0 if (not defined $pbforce); 2808 2811 $snapme = 0 if (not defined $snapme); 2812 $pbstep = 3 if (not defined $pbstep); 2809 2813 2810 2814 pb_log(2,"DEBUG: pb_script2v($vtype,$pbstep,$pbforce,$snapme)\n"); 2811 pb_log(2,"DEBUG: pb_script2v(pbscript: ".Dumper($pbscript)."\n") ;2815 pb_log(2,"DEBUG: pb_script2v(pbscript: ".Dumper($pbscript)."\n") if (defined $pbscript); 2812 2816 pb_parallel_launchv($pbscript,$vtype,uc($vtype)."Script",$pbstep,$pbimage,$pbforce,$snapme,$pbsnap); 2813 2817 } … … 2866 2870 $pm->start($counter) and next if (defined $pbparallel); 2867 2871 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 # 2868 2877 # 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); 2872 2879 2873 2880 # Skip that VM/RM if something went wrong … … 2886 2893 sub pb_launchv { 2887 2894 2888 my $pbscript =shift;2895 my $pbscript1=shift; # Just the script name to execute, not the hash 2889 2896 my $vtype = shift; 2890 2897 my $v = shift; # Only 1 VM/VE/RM treated here … … 2912 2919 pb_log(2,"DEBUG: pb_launchv(vtype,v,step,force,snapme,usesnap: $vtype,$v,$pbstep,$pbforce,$snapme,$usesnap)\n"); 2913 2920 pb_log(2,"DEBUG: pb_launchv(pbimage: $pbimage)\n") if (defined $pbimage); 2914 pb_log(2,"DEBUG: pb_launchv(pb image: $pbscript)\n") if (defined $pbscript);2921 pb_log(2,"DEBUG: pb_launchv(pbscript $pbscript1)\n") if (defined $pbscript1); 2915 2922 pb_log(2,"DEBUG: pb_launchv(action: $action)\n") if (defined $action); 2916 2923 # Keep only the first VM in case many were given … … 3097 3104 if (defined $action) { 3098 3105 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); 3100 3107 } 3101 3108 return($vexist,$vpid); … … 4473 4480 sub pb_ssh_get { 4474 4481 4475 my $create = shift || 0; # Do not create keys by default 4482 my $create = shift || 0; # Do not create keys by default. In that case prefer native keys, not pb's ones 4476 4483 my $target = shift || "localhost"; 4477 4484 my $nport = shift || "22"; … … 4486 4493 # Check whether ecdsa is accepted by the remote host 4487 4494 my $ecdsa = 0; 4495 my $dsa = 0; 4488 4496 open(SCAN,"ssh-keyscan -p $nport -t ecdsa $target 2>/dev/null |") || pb_log(0,"Unable to check ECDSA support for $target"); 4489 4497 while(<SCAN>) { 4490 4498 $ecdsa = 1 if ($_ =~ /ecdsa-/); 4499 pb_log(2,"Found ECDSA support on $target ($nport)\n"); 4491 4500 } 4492 4501 close(SCAN); 4493 4502 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)) { 4503 open(SCAN,"ssh-keyscan -p $nport -t dsa $target 2>/dev/null |") || pb_log(0,"Unable to check DSA support for $target"); 4504 while(<SCAN>) { 4505 $dsa = 1 if ($_ =~ /dsa-/); 4506 pb_log(2,"Found DSA support on $target ($nport)\n"); 4507 } 4508 close(SCAN); 4509 4510 # We have specific keys by default - create them if needed 4511 if (!(-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)) { 4500 4514 # 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 4521 if ($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 } 4509 4530 die "Unable to find your public ssh key under $ENV{'HOME'}/.ssh" if (not defined $keyfile); 4531 pb_log(2,"Using ssh key file $keyfile\n"); 4510 4532 return($keyfile); 4511 4533 } … … 4921 4943 my $vmhost; 4922 4944 4945 pb_log(1,"Entering pb_ssh_setup\n"); 4923 4946 ($vmhost) = pb_conf_get($vtype."host"); 4924 4947 # Prepare the key to be used and transfered remotely
Note:
See TracChangeset
for help on using the changeset viewer.