Changeset 347 in ProjectBuilder
- Timestamp:
- Apr 3, 2008, 1:18:55 AM (17 years ago)
- Location:
- devel/pb
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
devel/pb/bin/pb
r346 r347 355 355 if (defined $opts{'a'}) { 356 356 $pbaccount = $opts{'a'}; 357 die "option -a requires a -s script option" if (not defined $pbscript); 357 358 } 358 359 if (defined $opts{'P'}) { … … 431 432 pb_launchv("vm",$ENV{'PBV'},1); 432 433 } elsif ($action =~ /^setupve$/) { 433 $pbaccount = "root";434 434 my $pbscript = pb_setup_v("ve"); 435 435 pb_script2v($pbscript,"ve"); 436 436 } elsif ($action =~ /^setupvm$/) { 437 $pbaccount = "root";438 437 my $pbscript = pb_setup_v("vm"); 439 438 pb_script2v($pbscript,"vm"); … … 817 816 818 817 # Get the running distro to consider 819 my ($odir,$over,$oarch) = (undef, undef );818 my ($odir,$over,$oarch) = (undef, undef, undef); 820 819 if (defined $v) { 821 820 ($odir,$over,$oarch) = split(/-/,$v); … … 917 916 my ($shcmd,$cpcmd,$cptarget,$cp2target); 918 917 if ($cmt ne "ve") { 919 $shcmd = "ssh -q -p $nport $mac"; 920 $cpcmd = "scp -p -P $nport"; 918 my $keyfile = pb_ssh_get(0); 919 $shcmd = "ssh -i $keyfile -q -p $nport $mac"; 920 $cpcmd = "scp -i $keyfile -p -P $nport"; 921 921 $cptarget = "$mac:$tdir"; 922 922 $cp2target = "$mac:$bdir"; … … 1169 1169 } 1170 1170 # Gather all required files to send them to the VM/VE 1171 # and launch the build th ourgh pbscript1171 # and launch the build through pbscript 1172 1172 pb_send2target($vtype,"$v",$vmexist,$vmpid); 1173 1173 } … … 1244 1244 1245 1245 # Name of the account to deal with for VM/VE 1246 # Do not use the one passed potentially with -a 1246 1247 my $pbaccount = pb_conf_get($vtype."login"); 1248 1249 if ($vtype eq "vm") { 1250 # Prepare the key to be used and transfered remotely 1251 my $keyfile = pb_ssh_get(1); 1252 1253 my ($sshhost,$sshport) = pb_conf_get("vmhost","vmport"); 1254 my $nport = $sshport->{$ENV{'PBPROJ'}}; 1255 $nport = "$pbport" if (defined $pbport); 1256 1257 pb_system("cat $keyfile.pub | ssh -q -p $nport -i $keyfile root\@$sshhost->{$ENV{'PBPROJ'}} \"mkdir .ssh ; chmod 700 .ssh ; cat > .ssh/authorized_keys ; chmod 600 .ssh/authorized_keys\"","Copying local keys to $vtype. This will require the root password"); 1258 # once this is done, we can do what we want on the VM remotely 1259 } 1247 1260 1248 1261 # Prepare the script to be executed on the VM/VE 1249 1262 # in $ENV{'PBDESTDIR'}/setupv 1250 1251 # Check the SSH environment1252 my $file = undef;1253 $file = "$ENV{'HOME'}/.ssh/id_rsa.pub" if (-s "$ENV{'HOME'}/.ssh/id_rsa.pub");1254 $file = "$ENV{'HOME'}/.ssh/id_dsa.pub" if (-s "$ENV{'HOME'}/.ssh/id_dsa.pub");1255 die "Unable to find your public ssh key under $file" if (not defined $file);1256 1263 1257 1264 open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript"; … … 1286 1293 chdir "/home/$pbaccount"; 1287 1294 mkdir ".ssh",0700; 1288 copy("/tmp/pbkey",".ssh/authorized_keys"); 1295 # Allow those accessing root to access the build account 1296 copy("\$HOME/.ssh/authorized_keys",".ssh/authorized_keys"); 1289 1297 chmod 0600,".ssh/authorized_keys"; 1290 1298 system 'chown -R $pbaccount:$pbaccount .ssh'; … … 1294 1302 } 1295 1303 1296 # For root 1297 mkdir ".ssh",0700; 1298 copy("/tmp/pbkey",".ssh/authorized_keys"); 1299 chmod 0600,".ssh/authorized_keys"; 1300 1301 # No passwd for pb only keys 1304 # No passwd for build account only keys 1302 1305 $file="/etc/shadow"; 1303 1306 open(PBFILE,$file) || die "Unable to open $file"; … … 1318 1321 1319 1322 # pb has to be added to portage group on gentoo 1320 unlink "/tmp/pbkey";1321 1323 1322 1324 # Adapt sudoers … … 1346 1348 EOF 1347 1349 1348 pb_install_ pkg_deps(SCRIPT);1350 pb_install_deps(SCRIPT); 1349 1351 1350 1352 print SCRIPT << 'EOF'; … … 1359 1361 system "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 .."; 1360 1362 EOF 1363 1364 # Adds pb_distro_init from Project-Builder::Distribution 1365 foreach my $d (@INC) { 1366 my $f = "$d/Project-Builder/Distribution.pm"; 1367 if (-f "$f") { 1368 open(PBD,"$f") || die "Unable to open $f"; 1369 while (<PBD>) { 1370 print SCRIPT $_; 1371 } 1372 close(PBD); 1373 last; 1374 } 1375 } 1361 1376 close(SCRIPT); 1362 1377 chmod 0755,"$pbscript"; … … 1364 1379 } 1365 1380 1366 pb_install_pkg_deps {1381 sub pb_install_deps { 1367 1382 1368 1383 my \*SCRIPT = shift; … … 1370 1385 print SCRIPT << 'EOF'; 1371 1386 # We need to have that pb_distro_init function 1387 # Get it from Project-Builder::Distribution 1372 1388 my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init(); 1373 1389 print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n"; … … 1409 1425 } 1410 1426 1427 # Return the SSH key file to use 1428 # Potentially create it if needed 1429 1430 sub pb_ssh_get { 1431 1432 my $create = shift || 0; # Do not create keys by default 1433 1434 # Check the SSH environment 1435 my $keyfile = undef; 1436 1437 # We have specific keys by default 1438 $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa"; 1439 if ((-s $keyfile) && ($create eq 1)) { 1440 pb_system("ssh-keygen -q -b 1024 -N '' -f $keyfile -t dsa","Generating SSH keys for pb"); 1441 } 1442 1443 $keyfile = "$ENV{'HOME'}/.ssh/id_rsa" if (-s "$ENV{'HOME'}/.ssh/id_rsa"); 1444 $keyfile = "$ENV{'HOME'}/.ssh/id_dsa" if (-s "$ENV{'HOME'}/.ssh/id_dsa"); 1445 $keyfile = "$ENV{'HOME'}/.ssh/pb_dsa" if (-s "$ENV{'HOME'}/.ssh/pb_dsa"); 1446 die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile); 1447 return($keyfile); 1448 } 1449 1450 1411 1451 # Returns the pid of a running VM command using a specific VM file 1412 1452 sub pb_check_ps { -
devel/pb/lib/ProjectBuilder/Base.pm
r344 r347 832 832 #system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log"); 833 833 system($cmd); 834 if ($? == -1) { 834 my $res = $?; 835 if ($res == -1) { 835 836 pb_log(0,"failed to execute ($cmd) : $!\n"); 836 837 pb_display_file("$ENV{'PBTMP'}/system.log"); 837 } elsif ($ ?& 127) {838 } elsif ($res & 127) { 838 839 pb_log(0, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n"); 839 840 pb_display_file("$ENV{'PBTMP'}/system.log"); 840 } elsif ($ ?== 0) {841 } elsif ($res == 0) { 841 842 pb_log(0,"OK\n"); 842 843 } else { … … 844 845 pb_display_file("$ENV{'PBTMP'}/system.log"); 845 846 } 847 return($res); 846 848 } 847 849
Note:
See TracChangeset
for help on using the changeset viewer.