When creating a Debian package with dpkg-buildpackage
(and debhelper
), I am using the following entry in debian/rules
for assigning ownership of my-config
to my-user
(instead of root
):
override_dh_fixperms:
dh_fixperms
chown my-user:my-user $(CURDIR)/debian/my-package/etc/my-config
dpkg-buildpackage
runs as part of a build pipeline where the package name may be chosen as either my-package
or my-package-n
(n
is an integer). It currently fails in the case of my-package-n
because of the mismatch to the constant directory name my-package
in the path for chown
.
Is there mechanism in dpkg_buildpackage
(and debhelper
in particular) that gives access to the package name (my-package
or my-package-n
in my case) or the package build directory ($(CURDIR)/debian/my-package
or $(CURDIR)/debian/my-package-n
in my case)?
I've printed "ordinary" environment variables with set
between in dh_fixperms
and chown
: apparently none such holds the desired information.
Approach 1: Introspection
The
debhelper
package includes twodh_*
-programs that parse thedebhelper
command line arguments (e.g.-v
/--verbose
,-B
/--builddir
/--builddirectory
,-N
/--no-package
), environment variables (e.g.DH_VERBOSE
,DH_OPTIONS
), and package metadata to print them for introspection/use by other scripts/tooling:dh_listpackages
lists the binary packagesdebhelper
programs would act on:dh_assistant
provides various sub commands, that print information as JSON:In your particular case,
dh_listpackages
should do the job:Please keep in mind, that
dh_listpackages
will return multiple packages, if your source package produces multiple binary packages.Approach 2: Well-known binary package directory
You appear to have a source package that produces a single binary package (with a varying name) with a compatibility less than
15
. Until compatibility level15
, by defaultdebian/<package-name>
is used for single binary anddebian/tmp
for multiple binary packages.Starting with compatibility
15
,debhelper
will by default always usedebian/tmp
also for single binary packages.Regardless of the compatibility level, you can force a specific package directory with the
-P
/--tmpdir
option: