Changeset 2106 in ProjectBuilder


Ignore:
Timestamp:
Jul 21, 2016, 3:10:20 AM (5 years ago)
Author:
Bruno Cornec
Message:
  • Start fixing #108 by adding functions to sign files and file transfer for deb Release content
  • Fix again the tdir setup
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r2104 r2106  
    21952195        $tdir = "$remdir/$delivery->{$ENV{'PBPROJ'}}";
    21962196    } elsif ($cmt eq "Packages") {
     2197        my $debarch = "";
     2198
    21972199        if (($pbos->{'type'} eq "rpm") || ($pbos->{'type'} eq "pkg") || ($pbos->{'type'} eq "hpux") || ($pbos->{'type'} eq "tgz")) {
    21982200            # put packages under an arch subdir
     
    23432345            # Cf: http://www.debian.org/doc/manuals/repository-howto/repository-howto.fr.html
    23442346            # This dirname removes ver
    2345             my $debarch = $pbos->{'arch'};
    2346             $debarch = "amd64" if ($pbos->{'arch'} eq "x86_64");
     2347            my $debarch = pb_get_debarch($pbos);
     2348            my $projcomponent = pb_get_debpc($pbos);
    23472349            my $rpd = dirname("$pbrepo->{$ENV{'PBPROJ'}}/$repodir");
    23482350            # Remove extra . in path to fix #522
    23492351            $rpd =~ s|/./|/|g;
    2350             my ($projcomponent_map) = pb_conf_get_if("projcomponent");
    2351             pb_log(2,"projcomponent = ".Dumper($projcomponent_map)."\n");
    2352             my $projcomponent = $projcomponent_map->{$ENV{PBPROJ}};
    2353             $projcomponent ||= 'contrib';
    23542352            print PBS << "EOF";
    23552353#!/bin/bash
     
    25872585            # Nothing to do here
    25882586        } else {
    2589             pb_system("$shcmd \"rm -rf $tdir ; mkdir -p $tdir ; $cmd\' | bash -e\"","Preparing $tdir on $cptarget");
     2587            pb_system("$shcmd \"rm -rf $tdir ; mkdir -p $tdir ; cd $tdir ; $cmd\"","Preparing $tdir on $cptarget");
    25902588        }
    25912589    } else {
     
    27232721    }
    27242722    my $ret = pb_system("$shcmd","Executing pbscript on $cptarget if needed",$cmdverb);
     2723   
     2724    # If target is deb family then sign Release file for Packages
     2725    if (($cmt =~ /Packages/) && ($pbos->{'type'} eq "deb")) {
     2726        my $debarch = pb_get_debarch($pbos);
     2727        my $projcomponent = pb_get_debpc($pbos);
     2728        for my $f ("dists/$pbos->{'version'}/$projcomponent/binary-$debarch/Release","dists/$pbos->{'version'}/$projcomponent/source/Release","dists/$pbos->{'version'}/Release") {
     2729            pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd $cptarget/$f . 2> /dev/null","Getting deb $f file from $cptarget");
     2730            pb_sign_file("$ENV{'PBBUILDDIR'}/Release");
     2731            pb_system("cd $ENV{'PBBUILDDIR'} ; $cpcmd Release.gpg $cptarget/$f 2> /dev/null","Putting back deb $f file to $cptarget");
     2732        }
     2733    }
    27252734
    27262735    if ($cmt =~ /^(V[EM]|RM)build/) {
     
    48334842}
    48344843
    4835 sub pb_sign_pkgs {
    4836 
    4837 my $pbos = shift;
    4838 my $made = shift;
    4839 
    4840 pb_log(2,"entering pb_sign_pkg: $made ".Dumper($pbos)."\n");
     4844sub pb_sign_setenv {
     4845
    48414846my ($passfile, $passphrase, $passpath) = pb_conf_get_if("pbpassfile","pbpassphrase","pbpasspath");
    48424847$ENV{'PBPASSPHRASE'} = $passphrase->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSPHRASE'}) && (defined $passphrase->{$ENV{'PBPROJ'}}));
     
    48444849$ENV{'PBPASSPATH'} = $passpath->{$ENV{'PBPROJ'}} if ((not defined $ENV{'PBPASSPATH'})&& (defined $passpath->{$ENV{'PBPROJ'}})) ;
    48454850
     4851eval
     4852{
     4853    require RPM4::Sign;
     4854    RPM4::Sign->import();
     4855};
     4856if ($@) {
     4857    # RPM4::Sign not found
     4858    pb_log(1,"WARNING: Install RPM4::Sign to benefit from automatic package signing.\n");
     4859} else {
     4860    return(undef) if (((not defined $ENV{'PBPASSPHRASE'}) and (not defined $ENV{'PBPASSFILE'})) || (not defined $ENV{'PBPACKAGER'}) || (not defined $ENV{'PBPASSPATH'}));
     4861    my $sign = RPM4::Sign->new(
     4862        passphrase => $ENV{'PBPASSPHRASE'},
     4863        name => $ENV{'PBPACKAGER'},
     4864        path => $ENV{'PBPASSPATH'},
     4865        password_file => $ENV{'PBPASSFILE'},
     4866    );
     4867    return(undef) if (not defined $sign);
     4868    return(undef) if (not defined $sign->{name});
     4869    return(undef) if (not defined $sign->{path});
     4870    return(undef) if ((not defined $sign->{passphrase}) && (not defined $sign->{password_file}));
     4871    return(undef) if (not defined $sign->{keyid});
     4872
     4873    return($sign);
     4874}
     4875}
     4876
     4877sub pb_sign_file {
     4878
     4879my $file = shift;
     4880
     4881eval
     4882{
     4883    require Crypt::OpenPGP;
     4884    Crypt::OpenPGP->import();
     4885};
     4886if ($@) {
     4887    # Crypt::OpenPGP not found
     4888    pb_log(1,"WARNING: Install Crypt::OpenPGP to benefit from debian Release file signing.\n");
     4889} else {
     4890    my $sign = pb_sign_setenv();
     4891    my $pgp = Crypt::OpenPGP->new;
     4892    my $pgpsign = $pgp->sign(
     4893        Filename   => $file,
     4894        KeyID      => $sign->{keyid},
     4895        Passphrase => $sign->{passphrase},
     4896        Detach     => 1,
     4897        Armour     => 1,
     4898    );
     4899    open(DEST, "> $file.gpg") || confess "Unable to write to $file.gpg";
     4900    print DEST $pgpsign if (defined $pgpsign);
     4901    close(DEST);
     4902}
     4903}
     4904
     4905sub pb_sign_pkgs {
     4906
     4907my $pbos = shift;
     4908my $made = shift;
     4909
     4910pb_log(2,"entering pb_sign_pkg: $made ".Dumper($pbos)."\n");
     4911pb_sign_setenv();
    48464912# Remove extra spaces
    48474913$made =~ s/\s+/ /g;
     
    48504916
    48514917if ($pbos->{'type'} eq "rpm") {
    4852     eval
    4853     {
    4854         require RPM4::Sign;
    4855         RPM4::Sign->import();
    4856     };
    4857     if ($@) {
    4858         # RPM4::Sign not found
    4859         pb_log(1,"WARNING: Install RPM4::Sign to benefit from automatic package signing.\n");
    4860     } else {
    4861         return if (((not defined $ENV{'PBPASSPHRASE'}) and (not defined $ENV{'PBPASSFILE'})) || (not defined $ENV{'PBPACKAGER'}) || (not defined $ENV{'PBPASSPATH'}));
    4862         my $sign = RPM4::Sign->new(
    4863             passphrase => $ENV{'PBPASSPHRASE'},
    4864             name => $ENV{'PBPACKAGER'},
    4865             path => $ENV{'PBPASSPATH'},
    4866             password_file => $ENV{'PBPASSFILE'},
    4867         );
    4868         return if (not defined $sign);
    4869         return if (not defined $sign->{name});
    4870         return if (not defined $sign->{path});
    4871         return if ((not defined $sign->{passphrase}) && (not defined $sign->{password_file}));
    4872         return if (not defined $sign->{keyid});
    4873 
    4874         pb_log(0,"Signing RPM packages...\n");
    4875         pb_log(2,"pb_sign_pkg: pkgs:".Dumper(split(/ /,$made))."\n");
    4876         $sign->rpmssign(split(/ /,$made));
    4877     }
     4918    my $sign = pb_sign_setenv();
     4919    pb_log(0,"Signing RPM packages...\n");
     4920    pb_log(2,"pb_sign_pkg: pkgs:".Dumper(split(/ /,$made))."\n");
     4921    $sign->rpmssign(split(/ /,$made));
    48784922} elsif ($pbos->{'type'} eq "deb") {
    48794923    my $changes = "";
     
    50115055}
    50125056
     5057# Returns debian architecture
     5058#
     5059sub pb_get_debarch {
     5060
     5061my $pbos = shift;
     5062
     5063my $debarch = $pbos->{'arch'};
     5064$debarch = "amd64" if ($pbos->{'arch'} eq "x86_64");
     5065
     5066return($debarch);
     5067}
     5068
     5069sub pb_get_debpc {
     5070
     5071my ($projcomponent_map) = pb_conf_get_if("projcomponent");
     5072pb_log(2,"projcomponent = ".Dumper($projcomponent_map)."\n");
     5073my $projcomponent = $projcomponent_map->{$ENV{PBPROJ}};
     5074$projcomponent ||= 'contrib';
     5075
     5076return($projcomponent);
     5077}
     5078
    501350791;
Note: See TracChangeset for help on using the changeset viewer.