source: devel/pb/lib/ProjectBuilder/Base.pm @ 355

Last change on this file since 355 was 355, checked in by Bruno Cornec, 12 years ago

Fix a problem in build2vm where the new name of the distro wasn't correctly handled when trying to get packages pushed to the ftp server.

File size: 51.0 KB
Line 
1#!/usr/bin/perl -w
2#
3# Base subroutines for the Project-Builder project
4#
5# $Id$
6#
7
8package ProjectBuilder::Base;
9
10use strict;
11use lib qw (lib);
12use File::Basename;
13use File::Path;
14use File::stat;
15use File::Copy;
16use File::Temp qw(tempdir);
17use Data::Dumper;
18use POSIX qw(strftime);
19use Time::localtime qw(localtime);
20use Date::Manip;
21use English;
22
23# Inherit from the "Exporter" module which handles exporting functions.
24 
25use Exporter;
26 
27# Export, by default, all the functions into the namespace of
28# any code which uses this module.
29 
30our $debug = 0;
31our $LOG = \*STDOUT;
32
33our @ISA = qw(Exporter);
34our @EXPORT = qw(pb_env_init pb_conf_read pb_conf_read_if pb_conf_get pb_conf_get_if pb_cms_init pb_mkdir_p pb_system pb_rm_rf pb_get_filters pb_filter_file pb_filter_file_pb pb_filter_file_inplace pb_cms_export pb_cms_log pb_cms_isdiff pb_cms_copy pb_cms_checkout pb_get_date pb_log pb_log_init pb_get_pkg pb_cms_get_pkg pb_get_uri pb_cms_get_uri $debug $LOG);
35
36sub pb_env_init {
37
38my $proj=shift || undef;
39my $pbinit=shift || undef;
40my $action=shift;
41my $ver;
42my $tag;
43
44$ENV{'PBETC'} = "$ENV{'HOME'}/.pbrc";
45
46#
47# Check project name
48# Could be with env var PBPROJ
49# or option -p
50# if not define take the first in conf file
51#
52if ((defined $ENV{'PBPROJ'}) &&
53    (not (defined $proj))) {
54    $proj = $ENV{'PBPROJ'};
55}
56
57#
58# We get the pbconf file for that project
59# and use its content
60#
61my ($pbconf) = pb_conf_read("$ENV{'PBETC'}","pbconfurl");
62pb_log(2,"DEBUG pbconfurl: ".Dumper($pbconf)."\n");
63
64my %pbconf = %$pbconf;
65if (not defined $proj) {
66    # Take the first as the default project
67    $proj = (keys %pbconf)[0];
68    if (defined $proj) {
69        pb_log(1,"WARNING: using $proj as default project as none has been specified\n");
70        pb_log(1,"         Please either create a pbconfurl reference for project $proj in $ENV{'PBETC'}\n");
71        pb_log(1,"         or call pb with the -p project option or use the env var PBPROJ\n");
72        pb_log(1,"         if you want to use another project\n");
73    }
74}
75die "No project defined - use env var PBPROJ or -p proj or a pbconfurl entry in $ENV{'PBETC'}" if (not (defined $proj));
76
77# That's always the environment variable that will be used
78$ENV{'PBPROJ'} = $proj;
79pb_log(2,"PBPROJ: $ENV{'PBPROJ'}\n");
80
81if (not defined ($pbconf{$ENV{'PBPROJ'}})) {
82    die "Please create a pbconfurl reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n";
83}
84
85#
86# Detect the root dir for hosting all the content generated with pb
87#
88# Tree will look like this:
89#
90#             maint pbdefdir                         PBDEFDIR            dev dir (optional)
91#                  |                                                        |
92#            ------------------------                                --------------------
93#            |                      |                                |                  |
94#         pbproj1                pbproj2             PBPROJ       pbproj1           pbproj2   PBPROJDIR
95#            |                                                       |
96#  ---------------------------------------------                ----------
97#  *      *        *       |        |          |                *        *
98# tag    dev    pbconf    ...     build     delivery PBCONFDIR dev      tag                 
99#  |               |                           |     PBDESTDIR           |
100#  ---          ------                        pbrc   PBBUILDDIR       -------
101#    |          |    |                                                |     |
102#   1.1        dev  tag                                              1.0   1.1                PBDIR
103#                    |
104#                 -------
105#                 |     |
106#                1.0   1.1                           PBROOTDIR
107#                       |
108#               ----------------------------------
109#               |          |           |         |
110#             pkg1      pbproj1.pb   pbfilter   pbcl
111#               |
112#        -----------------
113#        |      |        |
114#       rpm    deb    pbfilter
115#
116#
117# (*) By default, if no relocation in .pbrc, dev dir is taken in the maint pbdefdir (when appropriate)
118# Names under a pbproj and the corresponding pbconf should be similar
119#
120
121my ($pbdefdir) = pb_conf_get_if("pbdefdir");
122
123if (not defined $ENV{'PBDEFDIR'}) {
124    if ((not defined $pbdefdir) || (not defined $pbdefdir->{$ENV{'PBPROJ'}})) {
125        pb_log(1,"WARNING: no pbdefdir defined, using /var/cache\n");
126        pb_log(1,"         Please create a pbdefdir reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
127        pb_log(1,"         if you want to use another directory\n");
128        $ENV{'PBDEFDIR'} = "/var/cache";
129    } else {
130        # That's always the environment variable that will be used
131        $ENV{'PBDEFDIR'} = $pbdefdir->{$ENV{'PBPROJ'}};
132    }
133}
134# Expand potential env variable in it
135eval { $ENV{'PBDEFDIR'} =~ s/(\$ENV.+\})/$1/eeg };
136
137pb_log(2,"PBDEFDIR: $ENV{'PBDEFDIR'}\n");
138#
139# Set delivery directory
140#
141$ENV{'PBDESTDIR'}="$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}/delivery";
142
143pb_log(2,"PBDESTDIR: $ENV{'PBDESTDIR'}\n");
144#
145# Removes all directory existing below the delivery dir
146# as they are temp dir only
147# Files stay and have to be cleaned up manually if needed
148# those files serves as communication channels between pb phases
149# Removing them prevents a following phase to detect what has been done before
150#
151if (-d $ENV{'PBDESTDIR'}) {
152    opendir(DIR,$ENV{'PBDESTDIR'}) || die "Unable to open directory $ENV{'PBDESTDIR'}: $!";
153    foreach my $d (readdir(DIR)) {
154        next if ($d =~ /^\./);
155        next if (-f "$ENV{'PBDESTDIR'}/$d");
156        pb_rm_rf("$ENV{'PBDESTDIR'}/$d") if (-d "$ENV{'PBDESTDIR'}/$d");
157    }
158    closedir(DIR);
159}
160if (! -d "$ENV{'PBDESTDIR'}") {
161    pb_mkdir_p($ENV{'PBDESTDIR'}) || die "Unable to recursively create $ENV{'PBDESTDIR'}";
162}
163
164#
165# Set build directory
166#
167$ENV{'PBBUILDDIR'}="$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}/build";
168if (! -d "$ENV{'PBBUILDDIR'}") {
169    pb_mkdir_p($ENV{'PBBUILDDIR'}) || die "Unable to recursively create $ENV{'PBBUILDDIR'}";
170}
171
172pb_log(2,"PBBUILDDIR: $ENV{'PBBUILDDIR'}\n");
173#
174# Set temp directory
175#
176if (not defined $ENV{'TMPDIR'}) {
177    $ENV{'TMPDIR'}="/tmp";
178}
179$ENV{'PBTMP'} = tempdir( "pb.XXXXXXXXXX", DIR => $ENV{'TMPDIR'}, CLEANUP => 1 );
180pb_log(2,"PBTMP: $ENV{'PBTMP'}\n");
181
182#
183# The following part is only useful when in cms2build
184# In VMs/VEs we want to skip that by providing good env vars.
185# return values in that case are useless
186#
187if ($action =~ /^cms2/) {
188
189    #
190    # Check pbconf cms compliance
191    #
192    pb_cms_compliant("pbconfdir",'PBCONFDIR',"$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}/pbconf",$pbconf{$ENV{'PBPROJ'}},$pbinit);
193
194    # Check where is our PBROOTDIR (release tag name can't be guessed the first time)
195    #
196    if (not defined $ENV{'PBROOTDIR'}) {
197        if (! -f ("$ENV{'PBDESTDIR'}/pbrc")) {
198            opendir(DIR,$ENV{'PBCONFDIR'}) || die "Unable to open directory $ENV{'PBCONFDIR'}: $!";
199            my $maxmtime = 0;
200            foreach my $d (readdir(DIR)) {
201                pb_log(3,"Looking at \'$d\'...");
202                next if ($d =~ /^\./);
203                next if (! -d "$ENV{'PBCONFDIR'}/$d");
204                my $s = stat("$ENV{'PBCONFDIR'}/$d");
205                next if (not defined $s);
206                pb_log(3,"KEEP\n");
207                # Keep the most recent
208                pb_log(2," $s->mtime\n");
209                if ($s->mtime > $maxmtime) {
210                    $ENV{'PBROOTDIR'} = "$ENV{'PBCONFDIR'}/$d";
211                    $maxmtime = $s->mtime;
212                }
213            }
214            closedir(DIR);
215            die "No directory found under $ENV{'PBCONFDIR'}" if (not defined $ENV{'PBROOTDIR'});
216            pb_log(1,"WARNING: no pbroot defined, using $ENV{'PBROOTDIR'}\n");
217            pb_log(1,"         Please use -r release if you want to use another release\n");
218        } else {
219            my ($pbroot) = pb_conf_read_if("$ENV{'PBDESTDIR'}/pbrc","pbroot");
220            # That's always the environment variable that will be used
221            die "Please remove inconsistent $ENV{'PBDESTDIR'}/pbrc" if ((not defined $pbroot) || (not defined $pbroot->{$ENV{'PBPROJ'}}));
222            $ENV{'PBROOTDIR'} = $pbroot->{$ENV{'PBPROJ'}};
223        }
224    } else {
225        # transform in full path if relative
226        $ENV{'PBROOTDIR'} = "$ENV{'PBCONFDIR'}/$ENV{'PBROOTDIR'}" if ($ENV{'PBROOTDIR'} !~ /^\//);
227        pb_mkdir_p($ENV{'PBROOTDIR'}) if (defined $pbinit);
228        die "$ENV{'PBROOTDIR'} is not a directory" if (not -d $ENV{'PBROOTDIR'});
229    }
230
231    my %version = ();
232    my %defpkgdir = ();
233    my %extpkgdir = ();
234    my %filteredfiles = ();
235    my %supfiles = ();
236   
237    if ((-f "$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") and (not defined $pbinit)) {
238        # List of pkg to build by default (mandatory)
239        my ($defpkgdir,$pbpackager, $pkgv, $pkgt) = pb_conf_get("defpkgdir","pbpackager","projver","projtag");
240        # List of additional pkg to build when all is called (optional)
241        # Valid version names (optional)
242        # List of files to filter (optional)
243        # Project version and tag (optional)
244        my ($extpkgdir, $version, $filteredfiles, $supfiles) = pb_conf_get_if("extpkgdir","version","filteredfiles","supfiles");
245        pb_log(2,"DEBUG: defpkgdir: ".Dumper($defpkgdir)."\n");
246        pb_log(2,"DEBUG: extpkgdir: ".Dumper($extpkgdir)."\n");
247        pb_log(2,"DEBUG: version: ".Dumper($version)."\n");
248        pb_log(2,"DEBUG: filteredfiles: ".Dumper($filteredfiles)."\n");
249        pb_log(2,"DEBUG: supfiles: ".Dumper($supfiles)."\n");
250        # Global
251        %defpkgdir = %$defpkgdir;
252        %extpkgdir = %$extpkgdir if (defined $extpkgdir);
253        %version = %$version if (defined $version);
254        %filteredfiles = %$filteredfiles if (defined $filteredfiles);
255        %supfiles = %$supfiles if (defined $supfiles);
256        #
257        # Get global Version/Tag
258        #
259        if (not defined $ENV{'PBPROJVER'}) {
260            if ((defined $pkgv) && (defined $pkgv->{$ENV{'PBPROJ'}})) {
261                $ENV{'PBPROJVER'}=$pkgv->{$ENV{'PBPROJ'}};
262            } else {
263                die "No projver found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
264            }
265        }
266        die "Invalid version name $ENV{'PBPROJVER'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb" if (($ENV{'PBPROJVER'} !~ /[0-9.]+/) && (not defined $version) && ($ENV{'PBPROJVER'} =~ /$version{$ENV{'PBPROJ'}}/));
267       
268        if (not defined $ENV{'PBPROJTAG'}) {
269            if ((defined $pkgt) && (defined $pkgt->{$ENV{'PBPROJ'}})) {
270                $ENV{'PBPROJTAG'}=$pkgt->{$ENV{'PBPROJ'}};
271            } else {
272                die "No projtag found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
273            }
274        }
275        die "Invalid tag name $ENV{'PBPROJTAG'} in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb" if ($ENV{'PBPROJTAG'} !~ /[0-9.]+/);
276   
277   
278        if (not defined $ENV{'PBPACKAGER'}) {
279            if ((defined $pbpackager) && (defined $pbpackager->{$ENV{'PBPROJ'}})) {
280                $ENV{'PBPACKAGER'}=$pbpackager->{$ENV{'PBPROJ'}};
281            } else {
282                die "No pbpackager found in $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
283            }
284        }
285    } else {
286        if (defined $pbinit) {
287            my $ptr = pb_get_pkg();
288            my @pkgs = @$ptr;
289            @pkgs = ("pkg1") if (not @pkgs);
290   
291            open(CONF,"> $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb") || die "Unable to create $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
292            print CONF << "EOF";
293#
294# Project Builder configuration file
295# For project $ENV{'PBPROJ'}
296#
297# \$Id\$
298#
299
300#
301# What is the project URL
302#
303#pburl $ENV{'PBPROJ'} = svn://svn.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
304#pburl $ENV{'PBPROJ'} = svn://svn+ssh.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
305#pburl $ENV{'PBPROJ'} = cvs://cvs.$ENV{'PBPROJ'}.org/$ENV{'PBPROJ'}/devel
306#pburl $ENV{'PBPROJ'} = http://www.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
307#pburl $ENV{'PBPROJ'} = ftp://ftp.$ENV{'PBPROJ'}.org/src/$ENV{'PBPROJ'}-devel.tar.gz
308#pburl $ENV{'PBPROJ'} = file:///src/$ENV{'PBPROJ'}-devel.tar.gz
309#pburl $ENV{'PBPROJ'} = dir:///src/$ENV{'PBPROJ'}-devel
310
311# Check whether project is well formed
312# (containing already a directory with the project-version name)
313#pbwf $ENV{'PBPROJ'} = 1
314
315#
316# Packager label
317#
318#pbpackager $ENV{'PBPROJ'} = William Porte <bill\@$ENV{'PBPROJ'}.org>
319#
320
321# For delivery to a machine by SSH (potentially the FTP server)
322# Needs hostname, account and directory
323#
324#sshhost $ENV{'PBPROJ'} = www.$ENV{'PBPROJ'}.org
325#sshlogin $ENV{'PBPROJ'} = bill
326#sshdir $ENV{'PBPROJ'} = /$ENV{'PBPROJ'}/ftp
327#sshport $ENV{'PBPROJ'} = 22
328
329#
330# For Virtual machines management
331# Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
332# followed by '-' and by release number
333# followed by '-' and by architecture
334# a .vmtype extension will be added to the resulting string
335# a QEMU rhel-3-i286 here means that the VM will be named rhel-3-i386.qemu
336#
337#vmlist $ENV{'PBPROJ'} = mandrake-10.1-i386,mandrake-10.2-i386,mandriva-2006.0-i386,mandriva-2007.0-i386,mandriva-2007.1-i386,mandriva-2008.0-i386,redhat-7.3-i386,redhat-9-i386,fedora-4-i386,fedora-5-i386,fedora-6-i386,fedora-7-i386,fedora-8-i386,rhel-3-i386,rhel-4-i386,rhel-5-i386,suse-10.0-i386,suse-10.1-i386,suse-10.2-i386,suse-10.3-i386,sles-9-i386,sles-10-i386,gentoo-nover-i386,debian-3.1-i386,debian-4.0-i386,ubuntu-6.06-i386,ubuntu-7.04-i386,ubuntu-7.10-i386,mandriva-2007.0-x86_64,mandriva-2007.1-x86_64,mandriva-2008.0-x86_64,fedora-6-x86_64,fedora-7-x86_64,fedora-8-x86_64,rhel-4-x86_64,rhel-5-x86_64,suse-10.2-x86_64,suse-10.3-x86_64,sles-10-x86_64,gentoo-nover-x86_64,debian-4.0-x86_64,ubuntu-7.04-x86_64,ubuntu-7.10-x86_64
338
339#
340# Valid values for vmtype are
341# qemu, (vmware, xen, ... TBD)
342#vmtype $ENV{'PBPROJ'} = qemu
343
344# Hash for VM stuff on vmtype
345#vmntp default = pool.ntp.org
346
347# We suppose we can commmunicate with the VM through SSH
348#vmhost $ENV{'PBPROJ'} = localhost
349#vmlogin $ENV{'PBPROJ'} = pb
350#vmport $ENV{'PBPROJ'} = 2222
351
352# Timeout to wait when VM is launched/stopped
353#vmtmout default = 120
354
355# per VMs needed paramaters
356#vmopt $ENV{'PBPROJ'} = -m 384 -daemonize
357#vmpath $ENV{'PBPROJ'} = /home/qemu
358#vmsize $ENV{'PBPROJ'} = 5G
359
360#
361# For Virtual environment management
362# Naming convention to follow: distribution name (as per ProjectBuilder::Distribution)
363# followed by '-' and by release number
364# followed by '-' and by architecture
365# a .vetype extension will be added to the resulting string
366# a chroot rhel-3-i286 here means that the VE will be named rhel-3-i386.chroot
367#
368#velist $ENV{'PBPROJ'} = fedora-7-i386
369
370# VE params
371#vetype $ENV{'PBPROJ'} = chroot
372#ventp default = pool.ntp.org
373#velogin $ENV{'PBPROJ'} = pb
374#vepath $ENV{'PBPROJ'} = /var/lib/mock
375#veconf $ENV{'PBPROJ'} = /etc/mock
376#verebuild $ENV{'PBPROJ'} = false
377
378#
379# Global version/tag for the project
380#
381#projver $ENV{'PBPROJ'} = devel
382#projtag $ENV{'PBPROJ'} = 1
383
384# Hash of valid version names
385#version $ENV{'PBPROJ'} = devel,stable
386
387# Adapt to your needs:
388# Optional if you need to overwrite the global values above
389#
390EOF
391       
392            foreach my $pp (@pkgs) {
393                print CONF << "EOF";
394#pkgver $pp = stable
395#pkgtag $pp = 3
396EOF
397            }
398            foreach my $pp (@pkgs) {
399                print CONF << "EOF";
400# Hash of default package/package directory
401#defpkgdir $pp = dir-$pp
402EOF
403            }
404   
405            print CONF << "EOF";
406# Hash of additional package/package directory
407#extpkgdir minor-pkg = dir-minor-pkg
408
409# List of files per pkg on which to apply filters
410# Files are mentioned relatively to pbroot/defpkgdir
411EOF
412            foreach my $pp (@pkgs) {
413                print CONF << "EOF";
414#filteredfiles $pp = Makefile.PL,configure.in,install.sh,$pp.8
415#supfiles $pp = $pp.init
416EOF
417            }
418            close(CONF);
419            pb_mkdir_p("$ENV{'PBROOTDIR'}/pbfilter") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter";
420            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/all.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/all.pbf";
421            print CONF << "EOF";
422#
423# \$Id\$
424#
425# Filter for all files
426#
427# PBSRC is replaced by the source package format
428#filter PBSRC = ftp://ftp.$ENV{'PBPROJ'}.org/src/%{name}-%{version}.tar.gz
429
430# PBVER is replaced by the version (\$pbver in code)
431filter PBVER = \$pbver
432
433# PBDATE is replaced by the date (\$pbdate in code)
434filter PBDATE = \$pbdate
435
436# PBLOG is replaced by the changelog if value is yes
437#filter PBLOG = yes
438
439# PBTAG is replaced by the tag (\$pbtag in code)
440filter PBTAG = \$pbtag
441
442# PBREV is replaced by the revision (\$pbrev in code)
443filter PBREV = \$pbrev
444
445# PBPKG is replaced by the package name (\$pbpkg in code)
446filter PBPKG = \$pbpkg
447
448# PBPACKAGER is replaced by the packager name (\$pbpackager in code)
449filter PBPACKAGER = \$pbpackager
450
451# PBDESC contains the description of the package
452#filter PBDESC = "Bla-Bla"
453
454# PBURL contains the URL of the Web site of the project
455#filter PBURL = http://www.$ENV{'PBPROJ'}.org
456EOF
457            close(CONF);
458            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/rpm.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/rpm.pbf";
459            print CONF << "EOF";
460#
461# \$Id\$
462#
463# Filter for rpm build
464#
465
466# PBGRP is replaced by the RPM group of apps
467# Cf: http://fedoraproject.org/wiki/RPMGroups
468#filter PBGRP = Applications/Archiving
469
470# PBLIC is replaced by the license of the application
471# Cf: http://fedoraproject.org/wiki/Licensing
472#filter PBLIC = GPL
473
474# PBDEP is replaced by the list of dependencies
475#filter PBDEP =
476
477# PBSUF is replaced by the package suffix (\$pbsuf in code)
478filter PBSUF = \$pbsuf
479
480# PBOBS is replaced by the Obsolete line
481#filter PBOBS =
482
483EOF
484            close(CONF);
485            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/deb.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/deb.pbf";
486            print CONF << "EOF";
487#
488# \$Id\$
489#
490# Filter for debian build
491#
492# PBGRP is replaced by the group of apps
493filter PBGRP = utils
494
495# PBLIC is replaced by the license of the application
496# Cf:
497#filter PBLIC = GPL
498
499# PBDEP is replaced by the list of dependencies
500#filter PBDEP =
501
502# PBSUG is replaced by the list of suggestions
503#filter PBSUG =
504
505# PBREC is replaced by the list of recommandations
506#filter PBREC =
507
508EOF
509            close(CONF);
510            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/md.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/md.pbf";
511            print CONF << "EOF";
512# Specific group for Mandriva for $ENV{'PBPROJ'}
513# Cf: http://wiki.mandriva.com/en/Development/Packaging/Groups
514#filter PBGRP = Archiving/Backup
515
516# PBLIC is replaced by the license of the application
517# Cf: http://wiki.mandriva.com/en/Development/Packaging/Licenses
518#filter PBLIC = GPL
519
520EOF
521            close(CONF);
522            open(CONF,"> $ENV{'PBROOTDIR'}/pbfilter/novell.pbf") || die "Unable to create $ENV{'PBROOTDIR'}/pbfilter/novell.pbf";
523            print CONF << "EOF";
524# Specific group for SuSE for $ENV{'PBPROJ'}
525# Cf: http://en.opensuse.org/SUSE_Package_Conventions/RPM_Groups
526#filter PBGRP = Productivity/Archiving/Backup
527
528# PBLIC is replaced by the license of the application
529# Cf: http://en.opensuse.org/Packaging/SUSE_Package_Conventions/RPM_Style#1.6._License_Tag
530#filter PBLIC = GPL
531
532EOF
533            close(CONF);
534            foreach my $pp (@pkgs) {
535                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/deb") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb";
536                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/control") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/control";
537                print CONF << "EOF";
538Source: PBPKG
539Section: PBGRP
540Priority: optional
541Maintainer: PBPACKAGER
542Build-Depends: debhelper (>= 4.2.20), PBDEP
543Standards-Version: 3.6.1
544
545Package: PBPKG
546Architecture: amd64 i386 ia64
547Section: PBGRP
548Priority: optional
549Depends: \${shlibs:Depends}, \${misc:Depends}, PBDEP
550Recommends: PBREC
551Suggests: PBSUG
552Description:
553 PBDESC
554 .
555 Homepage: PBURL
556
557EOF
558                close(CONF);
559                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/copyright") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/copyright";
560                print CONF << "EOF";
561This package is debianized by PBPACKAGER
562`date`
563
564The current upstream source was downloaded from
565ftp://ftp.$ENV{'PBPROJ'}.org/src/.
566
567Upstream Authors: Put their name here
568
569Copyright:
570
571   This package is free software; you can redistribute it and/or modify
572   it under the terms of the GNU General Public License as published by
573   the Free Software Foundation; version 2 dated June, 1991.
574
575   This package is distributed in the hope that it will be useful,
576   but WITHOUT ANY WARRANTY; without even the implied warranty of
577   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
578   GNU General Public License for more details.
579
580   You should have received a copy of the GNU General Public License
581   along with this package; if not, write to the Free Software
582   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
583   MA 02110-1301, USA.
584
585On Debian systems, the complete text of the GNU General
586Public License can be found in /usr/share/common-licenses/GPL.
587
588EOF
589                close(CONF);
590                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/changelog") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/changelog";
591                print CONF << "EOF";
592PBLOG
593EOF
594                close(CONF);
595                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/compat") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/compat";
596                print CONF << "EOF";
5974
598EOF
599                close(CONF);
600                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.dirs";
601                print CONF << "EOF";
602EOF
603                close(CONF);
604                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/$pp.docs";
605                print CONF << "EOF";
606INSTALL
607COPYING
608AUTHORS
609NEWS
610README
611EOF
612                close(CONF);
613                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/deb/rules") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/deb/rules";
614                print CONF << 'EOF';
615#!/usr/bin/make -f
616# -*- makefile -*-
617# Sample debian/rules that uses debhelper.
618# GNU copyright 1997 to 1999 by Joey Hess.
619#
620# $Id$
621#
622
623# Uncomment this to turn on verbose mode.
624#export DH_VERBOSE=1
625
626# Define package name variable for a one-stop change.
627PACKAGE_NAME = PBPKG
628
629# These are used for cross-compiling and for saving the configure script
630# from having to guess our platform (since we know it already)
631DEB_HOST_GNU_TYPE   ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
632DEB_BUILD_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
633
634CFLAGS = -Wall -g
635
636ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
637        CFLAGS += -O0
638else
639        CFLAGS += -O2
640endif
641ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
642        INSTALL_PROGRAM += -s
643endif
644config.status: configure
645        dh_testdir
646
647        # Configure the package.
648        CFLAGS="$(CFLAGS)" ./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr
649 --mandir=\$${prefix}/share/man
650
651# Build both architecture dependent and independent
652build: build-arch build-indep
653
654# Build architecture dependent
655build-arch: build-arch-stamp
656
657build-arch-stamp:  config.status
658        dh_testdir
659
660        # Compile the package.
661        $(MAKE)
662
663        touch build-stamp
664
665# Build architecture independent
666build-indep: build-indep-stamp
667
668build-indep-stamp:  config.status
669        # Nothing to do, the only indep item is the manual which is available as html in original source
670        touch build-indep-stamp
671
672# Clean up
673clean:
674        dh_testdir
675        dh_testroot
676        rm -f build-arch-stamp build-indep-stamp #CONFIGURE-STAMP#
677        # Clean temporary document directory
678        rm -rf debian/doc-temp
679        # Clean up.
680        -$(MAKE) distclean
681        rm -f config.log
682ifneq "$(wildcard /usr/share/misc/config.sub)" ""
683        cp -f /usr/share/misc/config.sub config.sub
684endif
685ifneq "$(wildcard /usr/share/misc/config.guess)" ""
686        cp -f /usr/share/misc/config.guess config.guess
687endif
688
689        dh_clean
690
691# Install architecture dependent and independent
692install: install-arch install-indep
693
694# Install architecture dependent
695install-arch: build-arch
696        dh_testdir
697        dh_testroot
698        dh_clean -k -s
699        dh_installdirs -s
700
701        # Install the package files into build directory:
702        # - start with upstream make install
703        $(MAKE) install prefix=$(CURDIR)/debian/$(PACKAGE_NAME)/usr mandir=$(CURDIR)/debian/$(PACKAGE_NAME)/us
704r/share/man
705        # - copy html manual to temporary location for renaming
706        mkdir -p debian/doc-temp
707        dh_install -s
708
709# Install architecture independent
710install-indep: build-indep
711        dh_testdir
712        dh_testroot
713        dh_clean -k -i
714        dh_installdirs -i
715        dh_install -i
716
717# Must not depend on anything. This is to be called by
718# binary-arch/binary-indep
719# in another 'make' thread.
720binary-common:
721        dh_testdir
722        dh_testroot
723        dh_installchangelogs ChangeLog
724        dh_installdocs
725        dh_installman
726        dh_link
727        dh_strip
728        dh_compress
729        dh_fixperms
730        dh_installdeb
731        dh_shlibdeps
732        dh_gencontrol
733        dh_md5sums
734        dh_builddeb
735
736# Build architecture independant packages using the common target.
737binary-indep: build-indep install-indep
738        $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common
739
740# Build architecture dependant packages using the common target.
741binary-arch: build-arch install-arch
742        $(MAKE) -f debian/rules DH_OPTIONS=-a binary-common
743
744# Build architecture depdendent and independent packages
745binary: binary-arch binary-indep
746.PHONY: clean binary
747
748EOF
749                close(CONF);
750                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/rpm") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm";
751                open(CONF,"> $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/rpm/$pp.spec";
752                print CONF << 'EOF';
753#
754# $Id$
755#
756
757Summary:        bla-bla
758Summary(fr):    french bla-bla
759
760Name:           PBPKG
761Version:        PBVER
762Release:        PBTAGPBSUF
763License:        PBLIC
764Group:          PBGRP
765Url:            PBURL
766Source:         PBSRC
767BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(id -u -n)
768#Requires:       PBDEP
769
770%description
771PBDESC
772
773%description -l fr
774french desc
775
776%prep
777%setup -q
778
779%build
780%configure
781make %{?_smp_mflags}
782
783%install
784%{__rm} -rf $RPM_BUILD_ROOT
785make DESTDIR=$RPM_BUILD_ROOT install
786
787%clean
788%{__rm} -rf $RPM_BUILD_ROOT
789
790%files
791%defattr(-,root,root)
792%doc ChangeLog
793%doc INSTALL COPYING README AUTHORS NEWS
794
795%changelog
796PBLOG
797
798EOF
799                close(CONF);
800                pb_mkdir_p("$ENV{'PBROOTDIR'}/$pp/pbfilter") || die "Unable to create $ENV{'PBROOTDIR'}/$pp/pbfilter";
801   
802                pb_log(0,"\nDo not to forget to commit the pbconf directory in your CMS if needed\n");
803            }
804        } else {
805            die "Unable to open $ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb";
806        }
807    }
808    umask 0022;
809    return(\%filteredfiles, \%supfiles, \%defpkgdir, \%extpkgdir);
810} else {
811    # Setup the variables from what has been stored at the end of cms2build
812    my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbroot");
813    $ENV{'PBROOTDIR'} = $var->{$ENV{'PBPROJ'}};
814
815    ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","projver");
816    $ENV{'PBPROJVER'} = $var->{$ENV{'PBPROJ'}};
817
818    ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","projtag");
819    $ENV{'PBPROJTAG'} = $var->{$ENV{'PBPROJ'}};
820
821    ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/pbrc","pbpackager");
822    $ENV{'PBPACKAGER'} = $var->{$ENV{'PBPROJ'}};
823
824    return;
825}
826}
827
828# Internal mkdir -p function
829sub pb_mkdir_p {
830my @dir = @_;
831my $ret = mkpath(@dir, 0, 0755);
832return($ret);
833}
834
835# Internal rm -rf function
836sub pb_rm_rf {
837my @dir = @_;
838my $ret = rmtree(@dir, 0, 0);
839return($ret);
840}
841
842# Internal system function
843sub pb_system {
844
845my $cmd=shift;
846my $cmt=shift || $cmd;
847
848pb_log(0,"$cmt... ");
849#system("$cmd 2>&1 > $ENV{'PBTMP'}/system.log");
850system($cmd);
851pb_log(1,"Executing $cmd\n");
852my $res = $?;
853if ($res == -1) {
854    pb_log(0,"failed to execute ($cmd) : $!\n");
855    pb_display_file("$ENV{'PBTMP'}/system.log");
856} elsif ($res & 127) {
857    pb_log(0, "child ($cmd) died with signal ".($? & 127).", ".($? & 128) ? 'with' : 'without'." coredump\n");
858    pb_display_file("$ENV{'PBTMP'}/system.log");
859} elsif ($res == 0) {
860    pb_log(0,"OK\n");
861} else {
862    pb_log(0, "child ($cmd) exited with value ".($? >> 8)."\n");
863    pb_display_file("$ENV{'PBTMP'}/system.log");
864}
865return($res);
866}
867
868sub pb_display_file {
869
870my $file=shift;
871
872return if (not -f $file);
873open(FILE,"$file");
874while (<FILE>) {
875    print $_;
876}
877close(FILE);
878}
879
880# Function which returns a pointer on a table
881# corresponding to a set of values queried in the conf file
882# and test the returned vaue as they need to exist in that case
883sub pb_conf_get {
884
885my @param = @_;
886my @return = pb_conf_get_if(@param);
887
888die "No params found for $ENV{'PBPROJ'}" if (not @return);
889
890foreach my $i (0..$#param) {
891    die "No $param[$i] defined for $ENV{'PBPROJ'}" if (not defined $return[$i]);
892}
893return(@return);
894}
895
896# Function which returns a pointer on a table
897# corresponding to a set of values queried in the conf file
898# Those value may be undef if they do not exist
899sub pb_conf_get_if {
900
901my @param = @_;
902
903# Everything is returned via ptr1
904my @ptr1 = ();
905my @ptr2 = ();
906@ptr1 = pb_conf_read_if("$ENV{'PBETC'}", @param) if (defined $ENV{'PBETC'});
907@ptr2 = pb_conf_read_if("$ENV{'PBROOTDIR'}/$ENV{'PBPROJ'}.pb", @param) if ((defined $ENV{'PBROOTDIR'}) and (defined $ENV{'PBPROJ'}));
908
909my $p1;
910my $p2;
911
912pb_log(2,"DEBUG: pb_conf_get param1: ".Dumper(@ptr1)."\n");
913pb_log(2,"DEBUG: pb_conf_get param2: ".Dumper(@ptr2)."\n");
914
915foreach my $i (0..$#param) {
916    $p1 = $ptr1[$i];
917    $p2 = $ptr2[$i];
918    # Always try to take the param from the home dir conf file in priority
919    # in order to mask what could be defined under the CMS to allow for overloading
920    if (not defined $p2) {
921        # No ref in CMS project conf file so use the home dir one.
922        $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if ((not defined $p1->{$ENV{'PBPROJ'}}) && (defined $p1->{'default'}));
923    } else {
924        # Ref found in CMS project conf file
925        if (not defined $p1) {
926            # No ref in home dir project conf file so use the CMS one.
927            $p2->{$ENV{'PBPROJ'}} = $p2->{'default'} if ((not defined $p2->{$ENV{'PBPROJ'}}) && (defined $p2->{'default'}));
928            $p1 = $p2;
929        } else {
930            # Both are defined - handling the overloading
931            if (not defined $p1->{'default'}) {
932                if (defined $p2->{'default'}) {
933                    $p1->{'default'} = $p2->{'default'};
934                }
935            }
936
937            if (not defined $p1->{$ENV{'PBPROJ'}}) {
938                if (defined $p2->{$ENV{'PBPROJ'}}) {
939                    $p1->{$ENV{'PBPROJ'}} = $p2->{$ENV{'PBPROJ'}} if (defined $p2->{$ENV{'PBPROJ'}});
940                } else {
941                    $p1->{$ENV{'PBPROJ'}} = $p1->{'default'} if (defined $p1->{'default'});
942                }
943            }
944            # Now copy back into p1 all p2 content which doesn't exist in p1
945            # p1 content (local) always has priority over p2 (project)
946            foreach my $k (keys %$p2) {
947                $p1->{$k} = $p2->{$k} if (not defined $p1->{$k});
948            }
949        }
950    }
951    $ptr1[$i] = $p1;
952}
953pb_log(2,"DEBUG: pb_conf_get param ptr1: ".Dumper(@ptr1)."\n");
954return(@ptr1);
955}
956
957# Function which returns a pointer on a hash
958# corresponding to a declaration (arg2) in a conf file (arg1)
959# if that conf file doesn't exist returns undef
960sub pb_conf_read_if {
961
962my $conffile = shift;
963my @param = @_;
964
965open(CONF,$conffile) || return((undef));
966close(CONF);
967return(pb_conf_read($conffile,@param));
968}
969
970# Function which returns a pointer on a hash
971# corresponding to a declaration (arg2) in a conf file (arg1)
972sub pb_conf_read {
973
974my $conffile = shift;
975my @param = @_;
976my $trace;
977my @ptr;
978my %h;
979
980open(CONF,$conffile) || die "Unable to open $conffile";
981while(<CONF>) {
982    if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
983        pb_log(3,"DEBUG: 1:$1 2:$2 3:$3\n");
984        $h{$1}{$2}=$3;
985    }
986}
987close(CONF);
988
989for my $param (@param) {
990    push @ptr,$h{$param};
991}
992return(@ptr);
993}
994
995# Analyze a url passed and return protocol, account, password, server, port, path
996sub pb_get_uri {
997
998my $uri = shift || undef;
999
1000pb_log(2,"DEBUG: uri:$uri\n");
1001# A URL has the format protocol://[ac@]host[:port][path[?query][#fragment]].
1002# Cf man URI
1003my ($scheme, $authority, $path, $query, $fragment) =
1004         $uri =~ m|(?:([^:/?#]+):)?(?://([^/?#]*))?([^?#]*)(?:\?([^#]*))?(?:#(.*))?| if (defined $uri);
1005my ($account,$host,$port) = $authority =~ m|(?:([^\@]+)\@)?([^:]+)(:(?:[0-9]+))?| if (defined $authority);
1006
1007$scheme = "" if (not defined $scheme);
1008$authority = "" if (not defined $authority);
1009$path = "" if (not defined $path);
1010$account = "" if (not defined $account);
1011$host = "" if (not defined $host);
1012$port = "" if (not defined $port);
1013
1014pb_log(2,"DEBUG: scheme:$scheme ac:$account host:$host port:$port path:$path\n");
1015return($scheme, $account, $host, $port, $path);
1016}
1017
1018
1019# Setup environment for CMS system for URL passed
1020sub pb_cms_init {
1021
1022my $pbinit = shift || undef;
1023
1024my ($pburl) = pb_conf_get("pburl");
1025pb_log(2,"DEBUG: Project URL of $ENV{'PBPROJ'}: $pburl->{$ENV{'PBPROJ'}}\n");
1026my ($scheme, $account, $host, $port, $path) = pb_get_uri($pburl->{$ENV{'PBPROJ'}});
1027
1028my ($pbprojdir) = pb_conf_get_if("pbprojdir");
1029
1030if ((defined $pbprojdir) && (defined $pbprojdir->{$ENV{'PBPROJ'}})) {
1031    $ENV{'PBPROJDIR'} = $pbprojdir->{$ENV{'PBPROJ'}};
1032} else {
1033    $ENV{'PBPROJDIR'} = "$ENV{'PBDEFDIR'}/$ENV{'PBPROJ'}";
1034}
1035
1036# Computing the default dir for PBDIR.
1037# what we have is PBPROJDIR so work from that.
1038# Tree identical between PBCONFDIR and PBROOTDIR on one side and
1039# PBPROJDIR and PBDIR on the other side.
1040
1041my $tmp = $ENV{'PBROOTDIR'};
1042$tmp =~ s|^$ENV{'PBCONFDIR'}||;
1043
1044#
1045# Check project cms compliance
1046#
1047pb_cms_compliant(undef,'PBDIR',"$ENV{'PBPROJDIR'}/$tmp",$pburl->{$ENV{'PBPROJ'}},$pbinit);
1048
1049if ($scheme =~ /^svn/) {
1050    # svnversion more precise than svn info
1051    $tmp = `(cd "$ENV{'PBDIR'}" ; svnversion .)`;
1052    chomp($tmp);
1053    $ENV{'PBREVISION'}=$tmp;
1054    $ENV{'PBCMSLOGFILE'}="svn.log";
1055} elsif (($scheme eq "file") || ($scheme eq "ftp") || ($scheme eq "http")) {
1056    $ENV{'PBREVISION'}="flat";
1057    $ENV{'PBCMSLOGFILE'}="flat.log";
1058} elsif ($scheme =~ /^cvs/) {
1059    # Way too slow
1060    #$ENV{'PBREVISION'}=`(cd "$ENV{'PBROOTDIR'}" ; cvs rannotate  -f . 2>&1 | awk '{print \$1}' | grep -E '^[0-9]' | cut -d. -f2 |sort -nu | tail -1)`;
1061    #chomp($ENV{'PBREVISION'});
1062    $ENV{'PBREVISION'}="cvs";
1063    $ENV{'PBCMSLOGFILE'}="cvs.log";
1064    $ENV{'CVS_RSH'} = "ssh" if ($scheme =~ /ssh/);
1065} else {
1066    die "cms $scheme unknown";
1067}
1068
1069return($scheme,$pburl->{$ENV{'PBPROJ'}});
1070}
1071
1072sub pb_get_date {
1073   
1074return(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
1075}
1076
1077sub pb_cms_export {
1078
1079my $uri = shift;
1080my $source = shift;
1081my $destdir = shift;
1082my $tmp;
1083my $tmp1;
1084
1085my @date = pb_get_date();
1086# If it's not flat, then we have a real uri as source
1087my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
1088
1089if ($scheme =~ /^svn/) {
1090    if (-d $source) {
1091        $tmp = $destdir;
1092    } else {
1093        $tmp = "$destdir/".basename($source);
1094    }
1095    pb_system("svn export $source $tmp","Exporting $source from SVN to $tmp");
1096} elsif ($scheme eq "dir") {
1097    pb_system("cp -a $path $destdir","Copying $uri from DIR to $destdir");
1098} elsif (($scheme eq "http") || ($scheme eq "ftp")) {
1099    my $f = basename($path);
1100    unlink "$ENV{'PBTMP'}/$f";
1101    if (-x "/usr/bin/wget") {
1102        pb_system("/usr/bin/wget -nv -O $ENV{'PBTMP'}/$f $uri"," ");
1103    } elsif (-x "/usr/bin/curl") {
1104        pb_system("/usr/bin/curl $uri -o $ENV{'PBTMP'}/$f","Downloading $uri with curl to $ENV{'PBTMP'}/$f\n");
1105    } else {
1106        die "Unable to download $uri.\nNo wget/curl available, please install one of those";
1107    }
1108    pb_cms_export("file://$ENV{'PBTMP'}/$f",$source,$destdir);
1109} elsif ($scheme eq "file") {
1110    use File::MimeInfo;
1111    my $mm = mimetype($path);
1112    pb_log(2,"mimetype: $mm\n");
1113    pb_mkdir_p($destdir);
1114
1115    # Check whether the file is well formed
1116    # (containing already a directory with the project-version name)
1117    my ($pbwf) = pb_conf_get_if("pbwf");
1118    if ((defined $pbwf) && (defined $pbwf->{$ENV{'PBPROJ'}})) {
1119        $destdir = dirname($destdir);
1120    }
1121
1122    if ($mm =~ /\/x-bzip-compressed-tar$/) {
1123        # tar+bzip2
1124        pb_system("cd $destdir ; tar xfj $path","Extracting $path in $destdir");
1125    } elsif ($mm =~ /\/x-lzma-compressed-tar$/) {
1126        # tar+lzma
1127        pb_system("cd $destdir ; tar xfY $path","Extracting $path in $destdir");
1128    } elsif ($mm =~ /\/x-compressed-tar$/) {
1129        # tar+gzip
1130        pb_system("cd $destdir ; tar xfz $path","Extracting $path in $destdir");
1131    } elsif ($mm =~ /\/x-tar$/) {
1132        # tar
1133        pb_system("cd $destdir ; tar xf $path","Extracting $path in $destdir");
1134    } elsif ($mm =~ /\/zip$/) {
1135        # zip
1136        pb_system("cd $destdir ; unzip $path","Extracting $path in $destdir");
1137    }
1138} elsif ($scheme =~ /^cvs/) {
1139    # CVS needs a relative path !
1140    my $dir=dirname($destdir);
1141    my $base=basename($destdir);
1142    # CVS also needs a modules name not a dir
1143    #if (-d $source) {
1144        $tmp1 = basename($source);
1145        #} else {
1146        #$tmp1 = dirname($source);
1147        #$tmp1 = basename($tmp1);
1148        #}
1149    my $optcvs = "";
1150
1151    # If we're working on the CVS itself
1152    my $cvstag = basename($ENV{'PBROOTDIR'});
1153    my $cvsopt = "";
1154    if ($cvstag eq "cvs") {
1155        my $pbdate = strftime("%Y-%m-%d %H:%M:%S", @date);
1156        $cvsopt = "-D \"$pbdate\"";
1157    } else {
1158        # we're working on a tag which should be the last part of PBROOTDIR
1159        $cvsopt = "-r $cvstag";
1160    }
1161    pb_system("cd $dir ; cvs -d $account\@$host:$path export $cvsopt -d $base $tmp1","Exporting $tmp1 from $source under CVS to $destdir");
1162} else {
1163    die "cms $scheme unknown";
1164}
1165}
1166
1167
1168sub pb_create_authors {
1169
1170my $authors=shift;
1171my $dest=shift;
1172my $scheme=shift;
1173
1174return if ($authors eq "/dev/null");
1175open(SAUTH,$authors) || die "Unable to open $authors";
1176# Save a potentially existing AUTHORS file and write instead toi AUTHORS.pb
1177my $ext = "";
1178if (-f "$dest/AUTHORS") {
1179    $ext = ".pb";
1180}
1181open(DAUTH,"> $dest/AUTHORS$ext") || die "Unable to create $dest/AUTHORS$ext";
1182print DAUTH "Authors of the project are:\n";
1183print DAUTH "===========================\n";
1184while (<SAUTH>) {
1185    my ($nick,$gcos) = split(/:/);
1186    chomp($gcos);
1187    print DAUTH "$gcos";
1188    if (defined $scheme) {
1189        # Do not give a scheme for flat types
1190        my $endstr="";
1191        if ("$ENV{'PBREVISION'}" ne "flat") {
1192            $endstr = " under $scheme";
1193        }
1194        print DAUTH " ($nick$endstr)\n";
1195    } else {
1196        print DAUTH "\n";
1197    }
1198}
1199close(DAUTH);
1200close(SAUTH);
1201}
1202
1203sub pb_cms_log {
1204
1205my $scheme = shift;
1206my $pkgdir = shift;
1207my $dest = shift;
1208my $chglog = shift;
1209my $authors = shift;
1210
1211pb_create_authors($authors,$dest,$scheme);
1212
1213if ($scheme =~ /^svn/) {
1214    if (! -f "$dest/ChangeLog") {
1215        if (-x "/usr/bin/svn2cl") {
1216            # In case we have no network, just create an empty one before to allow correct build
1217            open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
1218            close(CL);
1219            pb_system("/usr/bin/svn2cl --group-by-day --authors=$authors -i -o $dest/ChangeLog $pkgdir","Generating ChangeLog from SVN with svn2cl");
1220        } else {
1221            # To be written from pbcl
1222            pb_system("svn log -v $pkgdir > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from SVN");
1223        }
1224    }
1225} elsif (($scheme eq "file") || ($scheme eq "dir") || ($scheme eq "http") || ($scheme eq "ftp")) {
1226    if (! -f "$dest/ChangeLog") {
1227        pb_system("echo ChangeLog for $pkgdir > $dest/ChangeLog","Empty ChangeLog file created");
1228    }
1229} elsif ($scheme =~ /^cvs/) {
1230    my $tmp=basename($pkgdir);
1231    # CVS needs a relative path !
1232    if (! -f "$dest/ChangeLog") {
1233        if (-x "/usr/bin/cvs2cl") {
1234            # In case we have no network, just create an empty one before to allow correct build
1235            open(CL,"> $dest/ChangeLog") || die "Unable to create $dest/ChangeLog";
1236            close(CL);
1237            pb_system("/usr/bin/cvs2cl --group-by-day -U $authors -f $dest/ChangeLog $pkgdir","Generating ChangeLog from CVS with cvs2cl");
1238        } else {
1239            # To be written from pbcl
1240            pb_system("cvs log $tmp > $dest/$ENV{'PBCMSLOGFILE'}","Extracting log info from CVS");
1241        }
1242    }
1243} else {
1244    die "cms $scheme unknown";
1245}
1246}
1247
1248# This function is only called with a real CMS system
1249sub pb_cms_get_uri {
1250
1251my $scheme = shift;
1252my $dir = shift;
1253
1254my $res = "";
1255my $void = "";
1256
1257if ($scheme =~ /^svn/) {
1258    open(PIPE,"LANGUAGE=C svn info $dir |") || return("");
1259    while (<PIPE>) {
1260        ($void,$res) = split(/^URL:/) if (/^URL:/);
1261    }
1262    $res =~ s/^\s*//;
1263    close(PIPE);
1264    chomp($res);
1265} elsif ($scheme =~ /^cvs/) {
1266    # This path is always the root path of CVS, but we may be below
1267    open(FILE,"$dir/CVS/Root") || die "$dir isn't CVS controlled";
1268    $res = <FILE>;
1269    chomp($res);
1270    close(FILE);
1271    # Find where we are in the tree
1272    my $rdir = $dir;
1273    while ((! -d "$rdir/CVSROOT") && ($rdir ne "/")) {
1274        $rdir = dirname($rdir);
1275    }
1276    die "Unable to find a CVSROOT dir in the parents of $dir" if (! -d "$rdir/CVSROOT");
1277    #compute our place under that root dir - should be a relative path
1278    $dir =~ s|^$rdir||;
1279    my $suffix = "";
1280    $suffix = "$dir" if ($dir ne "");
1281
1282    my $prefix = "";
1283    if ($scheme =~ /ssh/) {
1284        $prefix = "cvs+ssh://";
1285    } else {
1286        $prefix = "cvs://";
1287    }
1288    $res = $prefix.$res.$suffix;
1289} else {
1290    die "cms $scheme unknown";
1291}
1292pb_log(2,"Found CMS info: $res\n");
1293return($res);
1294}
1295
1296sub pb_cms_copy {
1297my $scheme = shift;
1298my $oldurl = shift;
1299my $newurl = shift;
1300
1301if ($scheme =~ /^svn/) {
1302    pb_system("svn copy -m \"Creation of $newurl from $oldurl\" $oldurl $newurl","Copying $oldurl to $newurl ");
1303} elsif ($scheme eq "flat") {
1304} elsif ($scheme =~ /^cvs/) {
1305} else {
1306    die "cms $scheme unknown";
1307}
1308}
1309
1310sub pb_cms_checkout {
1311my $scheme = shift;
1312my $url = shift;
1313my $destination = shift;
1314
1315if ($scheme =~ /^svn/) {
1316    pb_system("svn co $url $destination","Checking out $url to $destination ");
1317} elsif (($scheme eq "ftp") || ($scheme eq "http")) {
1318    return;
1319} elsif ($scheme =~ /^cvs/) {
1320    pb_system("cvs co $url $destination","Checking out $url to $destination ");
1321} else {
1322    die "cms $scheme unknown";
1323}
1324}
1325
1326sub pb_cms_checkin {
1327my $scheme = shift;
1328my $dir = shift;
1329
1330my $ver = basename($dir);
1331if ($scheme =~ /^svn/) {
1332    pb_system("svn ci -m \"Updated to $ver\" $dir","Checking in $dir");
1333    pb_system("svn up $dir","Updating $dir");
1334} elsif ($scheme eq "flat") {
1335} elsif ($scheme =~ /^cvs/) {
1336} else {
1337    die "cms $scheme unknown";
1338}
1339}
1340
1341sub pb_cms_isdiff {
1342my $scheme = shift;
1343
1344if ($scheme =~ /^svn/) {
1345    open(PIPE,"svn diff $ENV{'PBROOTDIR'} |") || die "Unable to get svn diff from $ENV{'PBROOTDIR'}";
1346    my $l = 0;
1347    while (<PIPE>) {
1348        $l++;
1349    }
1350    return($l);
1351} elsif ($scheme eq "flat") {
1352} elsif ($scheme =~ /^cvs/) {
1353} else {
1354    die "cms $scheme unknown";
1355}
1356}
1357
1358# Get all filters to apply
1359# They're cumulative from less specific to most specific
1360# suffix is .pbf
1361
1362sub pb_get_filters {
1363
1364my @ffiles;
1365my ($ffile00, $ffile0, $ffile1, $ffile2, $ffile3);
1366my ($mfile00, $mfile0, $mfile1, $mfile2, $mfile3);
1367my $pbpkg = shift || die "No package specified";
1368my $dtype = shift || "";
1369my $dfam = shift || "";
1370my $ddir = shift || "";
1371my $dver = shift || "";
1372my $ptr = undef; # returned value pointer on the hash of filters
1373my %h;
1374
1375# Global filter files first, then package specificities
1376if (-d "$ENV{'PBROOTDIR'}/pbfilter") {
1377    $mfile00 = "$ENV{'PBROOTDIR'}/pbfilter/all.pbf" if (-f "$ENV{'PBROOTDIR'}/pbfilter/all.pbf");
1378    $mfile0 = "$ENV{'PBROOTDIR'}/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOTDIR'}/pbfilter/$dtype.pbf");
1379    $mfile1 = "$ENV{'PBROOTDIR'}/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOTDIR'}/pbfilter/$dfam.pbf");
1380    $mfile2 = "$ENV{'PBROOTDIR'}/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOTDIR'}/pbfilter/$ddir.pbf");
1381    $mfile3 = "$ENV{'PBROOTDIR'}/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOTDIR'}/pbfilter/$ddir-$dver.pbf");
1382
1383    push @ffiles,$mfile00 if (defined $mfile00);
1384    push @ffiles,$mfile0 if (defined $mfile0);
1385    push @ffiles,$mfile1 if (defined $mfile1);
1386    push @ffiles,$mfile2 if (defined $mfile2);
1387    push @ffiles,$mfile3 if (defined $mfile3);
1388}
1389
1390if (-d "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter") {
1391    $ffile00 = "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/all.pbf" if (-f "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/all.pbf");
1392    $ffile0 = "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$dtype.pbf" if (-f "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$dtype.pbf");
1393    $ffile1 = "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$dfam.pbf" if (-f "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$dfam.pbf");
1394    $ffile2 = "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$ddir.pbf" if (-f "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$ddir.pbf");
1395    $ffile3 = "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$ddir-$dver.pbf" if (-f "$ENV{'PBROOTDIR'}/$pbpkg/pbfilter/$ddir-$dver.pbf");
1396
1397    push @ffiles,$ffile00 if (defined $ffile00);
1398    push @ffiles,$ffile0 if (defined $ffile0);
1399    push @ffiles,$ffile1 if (defined $ffile1);
1400    push @ffiles,$ffile2 if (defined $ffile2);
1401    push @ffiles,$ffile3 if (defined $ffile3);
1402}
1403if (@ffiles) {
1404    pb_log(2,"DEBUG ffiles: ".Dumper(\@ffiles)."\n");
1405
1406    foreach my $f (@ffiles) {
1407        open(CONF,$f) || next;
1408        while(<CONF>)  {
1409            if (/^\s*([A-z0-9-_]+)\s+([[A-z0-9-_]+)\s*=\s*(.+)$/) {
1410                $h{$1}{$2}=$3;
1411            }
1412        }
1413        close(CONF);
1414
1415        $ptr = $h{"filter"};
1416        pb_log(2,"DEBUG f:".Dumper($ptr)."\n");
1417    }
1418}
1419return($ptr);
1420}
1421
1422# Function which applies filter on pb build files
1423sub pb_filter_file_pb {
1424
1425my $f=shift;
1426my $ptr=shift;
1427my %filter=%$ptr;
1428my $destfile=shift;
1429my $dtype=shift;
1430my $pbsuf=shift;
1431my $pbproj=shift;
1432my $pbpkg=shift;
1433my $pbver=shift;
1434my $pbtag=shift;
1435my $pbrev=shift;
1436my $pbdate=shift;
1437my $defpkgdir = shift;
1438my $extpkgdir = shift;
1439my $pbpackager = shift;
1440my $chglog = shift || undef;
1441
1442pb_log(2,"DEBUG: From $f to $destfile\n");
1443pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1444open(DEST,"> $destfile") || die "Unable to create $destfile";
1445open(FILE,"$f") || die "Unable to open $f: $!";
1446while (<FILE>) {
1447    my $line = $_;
1448    foreach my $s (keys %filter) {
1449        # Process single variables
1450        pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
1451        my $tmp = $filter{$s};
1452        next if (not defined $tmp);
1453        # Expand variables if any single one found
1454        pb_log(2,"DEBUG tmp: $tmp\n");
1455        if ($tmp =~ /\$/) {
1456            eval { $tmp =~ s/(\$\w+)/$1/eeg };
1457        # special case for ChangeLog only for pb
1458        } elsif (($s =~ /^PBLOG$/) && ($line =~ /^PBLOG$/)) {
1459            my $p = $defpkgdir->{$pbpkg};
1460            $p = $extpkgdir->{$pbpkg} if (not defined $p);
1461            pb_changelog($dtype, $pbpkg, $pbver, $pbtag, $pbsuf, $p, \*DEST, $tmp, $chglog);
1462            $tmp = "";
1463        }
1464        $line =~ s|$s|$tmp|;
1465    }
1466    print DEST $line;
1467}
1468close(FILE);
1469close(DEST);
1470}
1471
1472# Function which applies filter on files (external call)
1473sub pb_filter_file_inplace {
1474
1475my $ptr=shift;
1476my %filter=%$ptr;
1477my $destfile=shift;
1478my $pbproj=shift;
1479my $pbpkg=shift;
1480my $pbver=shift;
1481my $pbtag=shift;
1482my $pbrev=shift;
1483my $pbdate=shift;
1484my $pbpackager=shift;
1485
1486my $cp = "$ENV{'PBTMP'}/".basename($destfile);
1487copy($destfile,$cp) || die "Unable to create $cp";
1488
1489pb_filter_file($cp,$ptr,$destfile,$pbproj,$pbpkg,$pbver,$pbtag,$pbrev,$pbdate,$pbpackager);
1490unlink $cp;
1491}
1492
1493# Function which applies filter on files (external call)
1494sub pb_filter_file {
1495
1496my $f=shift;
1497my $ptr=shift;
1498my %filter=%$ptr;
1499my $destfile=shift;
1500my $pbproj=shift;
1501my $pbpkg=shift;
1502my $pbver=shift;
1503my $pbtag=shift;
1504my $pbrev=shift;
1505my $pbdate=shift;
1506my $pbpackager=shift;
1507
1508pb_log(2,"DEBUG: From $f to $destfile\n");
1509pb_mkdir_p(dirname($destfile)) if (! -d dirname($destfile));
1510open(DEST,"> $destfile") || die "Unable to create $destfile";
1511open(FILE,"$f") || die "Unable to open $f: $!";
1512while (<FILE>) {
1513    my $line = $_;
1514    foreach my $s (keys %filter) {
1515        # Process single variables
1516        pb_log(2,"DEBUG filter{$s}: $filter{$s}\n");
1517        my $tmp = $filter{$s};
1518        next if (not defined $tmp);
1519        # Expand variables if any single one found
1520        if ($tmp =~ /\$/) {
1521            eval { $tmp =~ s/(\$\w+)/$1/eeg };
1522        }
1523        $line =~ s|$s|$tmp|;
1524    }
1525    print DEST $line;
1526}
1527close(FILE);
1528close(DEST);
1529}
1530
1531sub pb_log_init {
1532
1533$debug = shift || 0;
1534$LOG = shift || \*STDOUT;
1535
1536} 
1537
1538sub pb_log {
1539
1540my $dlevel = shift;
1541my $msg = shift;
1542
1543print $LOG "$msg" if ($dlevel <= $debug);
1544}
1545
1546#
1547# Return the list of packages we are working on in a CMS action
1548#
1549sub pb_cms_get_pkg {
1550
1551my @pkgs = ();
1552my $defpkgdir = shift || undef;
1553my $extpkgdir = shift || undef;
1554
1555# Get packages list
1556if (not defined $ARGV[0]) {
1557    @pkgs = keys %$defpkgdir if (defined $defpkgdir);
1558} elsif ($ARGV[0] =~ /^all$/) {
1559    @pkgs = keys %$defpkgdir if (defined $defpkgdir);
1560    push(@pkgs, keys %$extpkgdir) if (defined $extpkgdir);
1561} else {
1562    @pkgs = @ARGV;
1563}
1564pb_log(0,"Packages: ".join(',',@pkgs)."\n");
1565return(\@pkgs);
1566}
1567
1568#
1569# Return the list of packages we are working on in a non CMS action
1570#
1571sub pb_get_pkg {
1572
1573my @pkgs = ();
1574
1575my ($var) = pb_conf_read("$ENV{'PBDESTDIR'}/$ENV{'PBPROJVER'}-$ENV{'PBPROJTAG'}.pb","pbpkg");
1576@pkgs = keys %$var;
1577
1578pb_log(0,"Packages: ".join(',',@pkgs)."\n");
1579return(\@pkgs);
1580}
1581
1582#
1583# Check pbconf/project cms compliance
1584#
1585sub pb_cms_compliant {
1586
1587my $param = shift;
1588my $envar = shift;
1589my $defdir = shift;
1590my $uri = shift;
1591my $pbinit = shift;
1592my %pdir;
1593
1594my ($pdir) = pb_conf_get_if($param) if (defined $param);
1595if (defined $pdir) {
1596    %pdir = %$pdir;
1597}
1598
1599
1600if ((defined $pdir) && (%pdir) && (defined $pdir{$ENV{'PBPROJ'}})) {
1601    # That's always the environment variable that will be used
1602    $ENV{$envar} = $pdir{$ENV{'PBPROJ'}};
1603} else {
1604    if (defined $param) {
1605        pb_log(1,"WARNING: no $param defined, using $defdir\n");
1606        pb_log(1,"         Please create a $param reference for project $ENV{'PBPROJ'} in $ENV{'PBETC'}\n");
1607        pb_log(1,"         if you want to use another directory\n");
1608    }
1609    $ENV{$envar} = "$defdir";
1610}
1611
1612# Expand potential env variable in it
1613eval { $ENV{$envar} =~ s/(\$ENV.+\})/$1/eeg };
1614pb_log(2,"$envar: $ENV{$envar}\n");
1615
1616my ($scheme, $account, $host, $port, $path) = pb_get_uri($uri);
1617
1618if ((! -d "$ENV{$envar}") || (defined $pbinit)) {
1619    if (defined $pbinit) {
1620        pb_mkdir_p("$ENV{$envar}");
1621    } else {
1622        pb_log(1,"Checking out $uri\n");
1623        pb_cms_checkout($scheme,$uri,$ENV{$envar});
1624    }
1625} elsif (($scheme !~ /^cvs/) || ($scheme !~ /^svn/)) {
1626    # Do not compare if it's not a real cms
1627    return;
1628} else {
1629    pb_log(1,"$uri found locally, checking content\n");
1630    my $cmsurl = pb_cms_get_uri($scheme,$ENV{$envar});
1631    my ($scheme2, $account2, $host2, $port2, $path2) = pb_get_uri($cmsurl);
1632    if ($cmsurl ne $uri) {
1633        # The local content doesn't correpond to the repository
1634        pb_log(0,"ERROR: Inconsistency detected:\n");
1635        pb_log(0,"       * $ENV{$envar} refers to $cmsurl but\n");
1636        pb_log(0,"       * $ENV{'PBETC'} refers to $uri\n");
1637        die "Project $ENV{'PBPROJ'} is not Project-Builder compliant.";
1638    } else {
1639        pb_log(1,"Content correct - doing nothing - you may want to update your repository however\n");
1640        # they match - do nothing - there may be local changes
1641    }
1642}
1643}
1644
1645sub pb_changelog {
1646
1647my $dtype = shift;
1648my $pkg = shift;
1649my $pbver = shift;
1650my $pbtag = shift;
1651my $dsuf = shift;
1652my $path = shift;
1653my $OUTPUT = shift;
1654my $doit = shift;
1655my $chglog = shift || undef;
1656
1657my $log = "";
1658
1659# For date handling
1660$ENV{LANG}="C";
1661
1662if ((not (defined $dtype)) || ($dtype eq "") || 
1663        (not (defined $pkg)) || ($pkg eq "") || 
1664        (not (defined $pbver)) || ($pbver eq "") || 
1665        (not (defined $pbtag)) || ($pbtag eq "") || 
1666        (not (defined $dsuf)) || ($dsuf eq "") || 
1667        (not (defined $path)) || ($path eq "") || 
1668        (not (defined $OUTPUT)) || ($OUTPUT eq "") ||
1669        (not (defined $doit)) || ($doit eq "")) {
1670    print $OUTPUT "\n";
1671    return;
1672}
1673
1674if (((not defined $chglog) || (! -f $chglog)) && ($doit eq "yes")) {
1675    #pb_log(2,"No ChangeLog file ($chglog) for $pkg\n";
1676    print $OUTPUT "\n";
1677    return;
1678}
1679
1680my $date;
1681my $ndate;
1682my $n2date;
1683my $ver;
1684my $ver2;
1685my ($pbpackager) = pb_conf_get("pbpackager");
1686
1687if (not defined $pbpackager->{$ENV{'PBPROJ'}}) {
1688    $pbpackager->{$ENV{'PBPROJ'}} = "undefined\@noproject.noorg";
1689}
1690
1691# If we don't need to do it, or don't have it fake something
1692if (((not defined $chglog) || (! -f $chglog)) && ($doit ne "yes")) {
1693    my @date=(localtime->sec(), localtime->min(), localtime->hour(), localtime->mday(), localtime->mon(), localtime->year(), localtime->wday(), localtime->yday(), localtime->isdst());
1694    $date = strftime("%Y-%m-%d", @date);
1695    $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
1696    $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
1697    if (($dtype eq "rpm") || ($dtype eq "fc")) {
1698        $ver2 = "$pbver-$pbtag$dsuf";
1699        print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
1700        print $OUTPUT "- Updated to $pbver\n";
1701        }
1702    if ($dtype eq "deb") {
1703        print $OUTPUT "$pkg ($pbver) unstable; urgency=low\n";
1704        print $OUTPUT "\n";
1705        print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}}  $n2date\n\n\n";
1706        }
1707    return;
1708}
1709
1710open(INPUT,"$chglog") || die "Unable to open $chglog (read)";
1711
1712# Skip first 4 lines
1713my $tmp = <INPUT>;
1714$tmp = <INPUT>;
1715$tmp = <INPUT>;
1716if ($dtype eq "announce") {
1717    print $OUTPUT $tmp;
1718}
1719$tmp = <INPUT>;
1720if ($dtype eq "announce") {
1721    print $OUTPUT $tmp;
1722}
1723
1724my $first=1;
1725
1726# Handle each block separated by newline
1727while (<INPUT>) {
1728    ($ver, $date) = split(/ /);
1729    $ver =~ s/^v//;
1730    chomp($date);
1731    $date =~ s/\(([0-9-]+)\)/$1/;
1732    #pb_log(2,"**$date**\n";
1733    $ndate = UnixDate($date,"%a", "%b", "%d", "%Y");
1734    $n2date = &UnixDate($date,"%a, %d %b %Y %H:%M:%S %z");
1735    #pb_log(2,"**$ndate**\n";
1736
1737    if (($dtype eq "rpm") || ($dtype eq "fc")) {
1738        if ($ver !~ /-/) {
1739            if ($first eq 1) {
1740                $ver2 = "$ver-$pbtag$dsuf";
1741                $first=0;
1742            } else {
1743                $ver2 = "$ver-1$dsuf";
1744            }
1745        } else {
1746            $ver2 = "$ver$dsuf";
1747        }
1748        print $OUTPUT "* $ndate $pbpackager->{$ENV{'PBPROJ'}} $ver2\n";
1749        print $OUTPUT "- Updated to $ver\n";
1750        }
1751    if ($dtype eq "deb") {
1752        print $OUTPUT "$pkg ($ver) unstable; urgency=low\n";
1753        print $OUTPUT "\n";
1754        }
1755
1756    $tmp = <INPUT>; 
1757    while ($tmp !~ /^$/) {
1758        if ($dtype eq "deb") {
1759            $tmp =~ s/^- //;
1760            print $OUTPUT "  * $tmp";
1761        } elsif ($dtype eq "rpm") {
1762            print $OUTPUT "$tmp";
1763        } else {
1764            print $OUTPUT "$tmp";
1765        }
1766        last if (eof(INPUT));
1767        $tmp = <INPUT>;
1768    }
1769    print $OUTPUT "\n";
1770
1771    if ($dtype eq "deb") {
1772        # Cf: http://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog
1773        print $OUTPUT " -- $pbpackager->{$ENV{'PBPROJ'}}  $n2date\n\n\n";
1774        }
1775
1776    last if (eof(INPUT));
1777    last if ($dtype eq "announce");
1778}
1779close(INPUT);
1780}
17811;
Note: See TracBrowser for help on using the repository browser.