Просмотр исходного кода

dpkg-vendor: new script to query various vendor information

This tool is meant to be used in debian/rules files to have common source
packages across multiple distributions and yet still have slightly
different binary packages.

To automatically conserve customizations across derivatives of a given
distribution, one can use “dpkg-vendor --derives-from vendor” so that all
derivatives keep the same customizations when they rebuild the source
package even if the current vendor is no more the same.
Raphael Hertzog лет назад: 17
Родитель
Сommit
349aeaa4f2
7 измененных файлов с 180 добавлено и 0 удалено
  1. 4 0
      debian/changelog
  2. 2 0
      debian/dpkg-dev.install
  3. 1 0
      man/Makefile.am
  4. 53 0
      man/dpkg-vendor.1
  5. 5 0
      man/po/po4a.cfg
  6. 2 0
      scripts/Makefile.am
  7. 113 0
      scripts/dpkg-vendor.pl

+ 4 - 0
debian/changelog

@@ -66,6 +66,10 @@ dpkg (1.15.1) UNRELEASED; urgency=low
   * Fix update-alternatives to not remove real files installed in place of
     an alternative link when the corresponding alternative is fully removed.
     Closes: #526538
+  * Add a new dpkg-vendor tool to query vendor information stored in
+    /etc/dpkg/origins. It can be used in debian/rules to enable different
+    behaviour depending on the current vendor at the time of the build.
+    Closes: #498380
 
   [ Guillem Jover ]
   * Fix typo in dpkg output (‘unexecpted’ → ‘unexpected’). Closes: #519082

+ 2 - 0
debian/dpkg-dev.install

@@ -15,6 +15,7 @@ usr/bin/dpkg-scanpackages
 usr/bin/dpkg-scansources
 usr/bin/dpkg-shlibdeps
 usr/bin/dpkg-source
+usr/bin/dpkg-vendor
 usr/lib/dpkg/parsechangelog
 usr/share/locale/*/LC_MESSAGES/dpkg-dev.mo
 usr/share/man/{*/*,*}/822-date.1
@@ -40,4 +41,5 @@ usr/share/man/{*/*,*}/dpkg-scanpackages.1
 usr/share/man/{*/*,*}/dpkg-scansources.1
 usr/share/man/{*/*,*}/dpkg-shlibdeps.1
 usr/share/man/{*/*,*}/dpkg-source.1
+usr/share/man/{*/*,*}/dpkg-vendor.1
 usr/share/perl5/Dpkg

+ 1 - 0
man/Makefile.am

@@ -100,6 +100,7 @@ dist_man_MANS = \
 	dpkg-split.1 \
 	dpkg-statoverride.8 \
 	dpkg-trigger.1 \
+	dpkg-vendor.1 \
 	dpkg.1 \
 	dpkg.cfg.5 \
 	install-info.8 \

+ 53 - 0
man/dpkg-vendor.1

@@ -0,0 +1,53 @@
+.TH dpkg\-vendor 1 "2009-05-10" "Debian Project" "dpkg suite"
+.SH NAME
+dpkg\-vendor \- queries information about distribution vendors
+.
+.SH SYNOPSIS
+.B dpkg\-vendor
+.RI [ option "...] " command
+.
+.SH DESCRIPTION
+\fBdpkg\-vendor\fP is a tool to query information about vendors listed in
+\fB/etc/dpkg/origins\fP. \fB/etc/dpkg/origins/default\fP contains
+information about the current vendor.
+.
+.SH COMMANDS
+.TP
+.BI \-\-is " vendor"
+Exits with 0 if the current vendor is \fIvendor\fP. Otherwise exits
+with non-zero.
+.TP
+.BI \-\-derives\-from " vendor"
+Exits with 0 if the current vendor distribution is a derivative of
+\fIvendor\fP, otherwise exits with non-zero. It uses the "Parent" field
+to browse all ancestors of the current vendor.
+.TP
+.BI \-\-query " field"
+Print on standard output the value of the vendor-specific \fIfield\fP for
+the current vendor.
+.TP
+.B \-\-help
+Show the usage message and exit.
+.TP
+.B \-\-version
+Show the version and exit.
+.
+.SH OPTIONS
+.TP
+.BI \-\-vendor " vendor"
+Assumes the current vendor is \fIvendor\fP instead of discovering it
+with the DEB_VENDOR environment variable or
+\fB/etc/dpkg/origins/default\fP.
+.
+.SH ENVIRONMENT
+.TP
+\fBDEB_VENDOR\fP
+This setting defines the current vendor. If not set, il will discover the
+current vendor by reading \fB/etc/dpkg/origins/default\fP.
+.
+.SH AUTHOR
+Copyright \(co 2009 Rapha\[:e]l Hertzog
+.sp
+This is free software; see the GNU General Public Licence version 2 or
+later for copying conditions. There is NO WARRANTY.
+

+ 5 - 0
man/po/po4a.cfg

@@ -163,6 +163,11 @@
            add_$lang:$(srcdir)/po/$lang.add
 
 
+[type:man] $(srcdir)/dpkg-vendor.1              \
+           $lang:$lang/dpkg-vendor.1            \
+           add_$lang:$(srcdir)/po/$lang.add
+
+
 [type:man] $(srcdir)/dselect.1                  \
            $lang:$lang/dselect.1    \
            add_$lang:$(srcdir)/po/$lang.add

+ 2 - 0
scripts/Makefile.am

@@ -19,6 +19,7 @@ bin_SCRIPTS = \
 	dpkg-shlibdeps \
 	dpkg-statoverride \
 	dpkg-source \
+	dpkg-vendor \
 	update-alternatives
 
 changelogdir = $(pkglibdir)/parsechangelog
@@ -43,6 +44,7 @@ EXTRA_DIST = \
 	dpkg-source.pl \
 	dpkg-divert.pl \
 	dpkg-statoverride.pl \
+	dpkg-vendor.pl \
 	install-info.pl \
 	update-alternatives.pl \
 	changelog/debian.pl \

+ 113 - 0
scripts/dpkg-vendor.pl

@@ -0,0 +1,113 @@
+#!/usr/bin/perl
+#
+# dpkg-vendor
+#
+# Copyright © 2009 Raphaël Hertzog <hertzog@debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+use strict;
+use warnings;
+
+use Dpkg;
+use Dpkg::Gettext;
+use Dpkg::ErrorHandling;
+use Dpkg::Vendor qw(get_vendor_info get_current_vendor);
+
+textdomain("dpkg-dev");
+
+sub version {
+    printf _g("Debian %s version %s.\n"), $progname, $version;
+
+    printf _g("
+Copyright (C) 2009 Raphael Hertzog <hertzog\@debian.org>.");
+
+    printf _g("
+This is free software; see the GNU General Public Licence version 2 or
+later for copying conditions. There is NO warranty.
+");
+}
+
+sub usage {
+    printf _g(
+"Usage: %s [<option> ...] [<action>]
+
+Options:
+  --vendor <vendor>       assume <vendor> is the current vendor
+
+Actions:
+  --is <vendor>           returns true if current vendor is <vendor>.
+  --derives-from <vendor> returns true if current vendor derives from <vendor>.
+  --query <field>         print the content of the vendor-specific field.
+  --help                  show this help message.
+  --version               show the version.
+"), $progname;
+}
+
+my ($vendor, $param, $action);
+
+while (@ARGV) {
+    $_ = shift(@ARGV);
+    if (m/^--vendor$/) {
+        $vendor = shift(@ARGV);
+    } elsif (m/^--(is|derives-from|query)$/) {
+        badusage(_g("two commands specified: --%s and --%s"), $1, $action)
+            if defined($action);
+        $action = $1;
+        $param = shift(@ARGV);
+    } elsif (m/^-(h|-help)$/) {
+        usage();
+        exit 0;
+    } elsif (m/^--version$/) {
+        version();
+        exit 0;
+    } else {
+	usageerr(_g("unknown option \`%s'"), $_);
+    }
+}
+
+# Uses $ENV{DEB_VENDOR} if set
+$vendor = get_current_vendor() unless defined($vendor);
+
+my $info = get_vendor_info($vendor);
+unless (defined($info)) {
+    error(_g("vendor %s doesn't exist in /etc/dpkg/origins/"),
+          $vendor || "default");
+}
+
+if ($action eq 'is') {
+
+    exit(0) if lc($param) eq lc($info->{'Vendor'});
+    exit(1);
+
+} elsif ($action eq 'derives-from') {
+
+    exit(0) if lc($param) eq lc($info->{'Vendor'});
+    while (defined($info) && exists $info->{'Parent'}) {
+        $info = get_vendor_info($info->{'Parent'});
+        exit(0) if lc($param) eq lc($info->{'Vendor'});
+    }
+    exit(1);
+
+} elsif ($action eq 'query') {
+
+    if (exists $info->{$param}) {
+        print $info->{$param} . "\n";
+        exit(0);
+    } else {
+        exit(1);
+    }
+
+}