Changeset 347 in ProjectBuilder


Ignore:
Timestamp:
Apr 3, 2008, 1:18:55 AM (16 years ago)
Author:
Bruno Cornec
Message:

setupvm seems better now

Location:
devel/pb
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r346 r347  
    355355if (defined $opts{'a'}) {
    356356    $pbaccount = $opts{'a'};
     357    die "option -a requires a -s script option" if (not defined $pbscript);
    357358}
    358359if (defined $opts{'P'}) {
     
    431432    pb_launchv("vm",$ENV{'PBV'},1);
    432433} elsif ($action =~ /^setupve$/) {
    433     $pbaccount = "root";
    434434    my $pbscript = pb_setup_v("ve");
    435435    pb_script2v($pbscript,"ve");
    436436} elsif ($action =~ /^setupvm$/) {
    437     $pbaccount = "root";
    438437    my $pbscript = pb_setup_v("vm");
    439438    pb_script2v($pbscript,"vm");
     
    817816
    818817    # Get the running distro to consider
    819     my ($odir,$over,$oarch) = (undef, undef);
     818    my ($odir,$over,$oarch) = (undef, undef, undef);
    820819    if (defined $v) {
    821820        ($odir,$over,$oarch) = split(/-/,$v);
     
    917916    my ($shcmd,$cpcmd,$cptarget,$cp2target);
    918917    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";
    921921        $cptarget = "$mac:$tdir";
    922922        $cp2target = "$mac:$bdir";
     
    11691169    }
    11701170    # Gather all required files to send them to the VM/VE
    1171     # and launch the build thourgh pbscript
     1171    # and launch the build through pbscript
    11721172    pb_send2target($vtype,"$v",$vmexist,$vmpid);
    11731173}
     
    12441244
    12451245# Name of the account to deal with for VM/VE
     1246# Do not use the one passed potentially with -a
    12461247my $pbaccount = pb_conf_get($vtype."login");
     1248
     1249if ($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}
    12471260
    12481261# Prepare the script to be executed on the VM/VE
    12491262# in $ENV{'PBDESTDIR'}/setupv
    1250 
    1251 # Check the SSH environment
    1252 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);
    12561263
    12571264open(SCRIPT,"> $pbscript") || die "Unable to create $pbscript";
     
    12861293chdir "/home/$pbaccount";
    12871294mkdir ".ssh",0700;
    1288 copy("/tmp/pbkey",".ssh/authorized_keys");
     1295# Allow those accessing root to access the build account
     1296copy("\$HOME/.ssh/authorized_keys",".ssh/authorized_keys");
    12891297chmod 0600,".ssh/authorized_keys";
    12901298system 'chown -R $pbaccount:$pbaccount .ssh';
     
    12941302}
    12951303
    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
    13021305$file="/etc/shadow";
    13031306open(PBFILE,$file) || die "Unable to open $file";
     
    13181321
    13191322# pb has to be added to portage group on gentoo
    1320 unlink "/tmp/pbkey";
    13211323
    13221324# Adapt sudoers
     
    13461348EOF
    13471349
    1348 pb_install_pkg_deps(SCRIPT);
     1350pb_install_deps(SCRIPT);
    13491351
    13501352print SCRIPT << 'EOF';
     
    13591361system "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 ..";
    13601362EOF
     1363
     1364# Adds pb_distro_init from Project-Builder::Distribution
     1365foreach 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}
    13611376close(SCRIPT);
    13621377chmod 0755,"$pbscript";
     
    13641379}
    13651380
    1366 pb_install_pkg_deps {
     1381sub pb_install_deps {
    13671382
    13681383my \*SCRIPT = shift;
     
    13701385print SCRIPT << 'EOF';
    13711386# We need to have that pb_distro_init function
     1387# Get it from Project-Builder::Distribution
    13721388my ($ddir, $dver, $dfam, $dtype, $pbsuf) = pb_distro_init();
    13731389print "distro tuple: ".join(',',($ddir, $dver, $dfam, $dtype, $pbsuf))."\n";
     
    14091425}
    14101426
     1427# Return the SSH key file to use
     1428# Potentially create it if needed
     1429
     1430sub pb_ssh_get {
     1431
     1432my $create = shift || 0;    # Do not create keys by default
     1433
     1434# Check the SSH environment
     1435my $keyfile = undef;
     1436
     1437# We have specific keys by default
     1438$keyfile = "$ENV{'HOME'}/.ssh/pb_dsa";
     1439if ((-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");
     1446die "Unable to find your public ssh key under $keyfile" if (not defined $keyfile);
     1447return($keyfile);
     1448}
     1449
     1450
    14111451# Returns the pid of a running VM command using a specific VM file
    14121452sub pb_check_ps {
  • devel/pb/lib/ProjectBuilder/Base.pm

    r344 r347  
    832832#system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
    833833system($cmd);
    834 if ($? == -1) {
     834my $res = $?;
     835if ($res == -1) {
    835836    pb_log(0,"failed to execute ($cmd) : $!\n");
    836837    pb_display_file("$ENV{'PBTMP'}/system.log");
    837 } elsif ($? & 127) {
     838} elsif ($res & 127) {
    838839    pb_log(0, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n");
    839840    pb_display_file("$ENV{'PBTMP'}/system.log");
    840 } elsif ($? == 0) {
     841} elsif ($res == 0) {
    841842    pb_log(0,"OK\n");
    842843} else {
     
    844845    pb_display_file("$ENV{'PBTMP'}/system.log");
    845846}
     847return($res);
    846848}
    847849
Note: See TracChangeset for help on using the changeset viewer.