Skip to contentSkip to conversation

builddeb: Fix build on non-Debian/Ubuntu distros

PATCH In review Petr Vorel 3 participants 5 messages Oct 30, 2020 – Nov 2, 2020 Kbuild

lore
Share & tools
lore

Petr Vorel

author
#0 lore raw

PATCH 1/1 builddeb: Fix build on non-Debian/Ubuntu distros

This fixes make bindeb-pkg for RPM based distros, which don't have dpkg-dev (and thus not /usr/bin/dpkg-buildpackage), which sets $DEB_RULES_REQUIRES_ROOT.

Fixes 3e8541803624 ("builddeb: Enable rootless builds")

---
Hi,

I admit not many people compile kernel with bindeb-pkg on RPM based distro, but it'd be nice it were working.

openSUSE has most of other required packages, although there are some missing dependencies, thus DPKG_FLAGS="-d" is needed.

Kind regards,
Petr

 scripts/package/builddeb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/package/builddeb +1 -1
index 1b11f8993629..287e4bbd222c 100755
@@ -37,7 +37,7 @@ create_package() {
 		| xargs -r0 md5sum > DEBIAN/md5sums"
 
 	# Fix ownership and permissions
-	if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
+	if [ -z "$DEB_RULES_REQUIRES_ROOT" -o "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
 		dpkg_deb_opts="--root-owner-group"
 	else
 		chown -R root:root "$pdir"
Signature · 1 line
2.27.0.rc0
#1 lore raw
Quoted 5 lines · Petr Vorel

This fixes make bindeb-pkg for RPM based distros, which don't have dpkg-dev (and thus not /usr/bin/dpkg-buildpackage), which sets $DEB_RULES_REQUIRES_ROOT.

Fixes 3e8541803624 ("builddeb: Enable rootless builds")

This doesn't seem to fix a bug, and in fact it would introduce one.

Quoted 1 line

[...]

scripts/package/builddeb create_package() { · line 43

Quoted 11 lines
scripts/package/builddeb +1 -1
@@ -37,7 +37,7 @@ create_package() {
                | xargs -r0 md5sum > DEBIAN/md5sums"
 
        # Fix ownership and permissions
-       if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
+       if [ -z "$DEB_RULES_REQUIRES_ROOT" -o "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
                dpkg_deb_opts="--root-owner-group"
        else
                chown -R root:root "$pdir"

This is the wrong default behaviour; it will cause a regression with older versions of dpkg that don't support this option.

If you invoke this script directly and do not use dpkg-buildpackage (which I don't think is really supported anyway) then you must either do so as root or use fakeroot (as dpkg-buildpackage does by default).

Ben.

Signature · 2 lines
Ben Hutchings
The first rule of tautology club is the first rule of tautology club.
author
#2 lore raw

Hi Ben,

first, thanks for your review.

Quoted 23 lines · Petr Vorel
Quoted 5 lines

This fixes make bindeb-pkg for RPM based distros, which don't have dpkg-dev (and thus not /usr/bin/dpkg-buildpackage), which sets $DEB_RULES_REQUIRES_ROOT.

Fixes 3e8541803624 ("builddeb: Enable rootless builds")

This doesn't seem to fix a bug, and in fact it would introduce one.

Quoted 1 line

[...]

scripts/package/builddeb create_package() { · line 43

Quoted 11 lines
scripts/package/builddeb +1 -1
@@ -37,7 +37,7 @@ create_package() {
                | xargs -r0 md5sum > DEBIAN/md5sums"
 
        # Fix ownership and permissions
-       if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
+       if [ -z "$DEB_RULES_REQUIRES_ROOT" -o "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
                dpkg_deb_opts="--root-owner-group"
        else
                chown -R root:root "$pdir"
Quoted 2 lines

This is the wrong default behaviour; it will cause a regression with older versions of dpkg that don't support this option.

Sorry for wrong report. I tested it on Debian, but only on unstable.

Quoted 3 lines

If you invoke this script directly and do not use dpkg-buildpackage (which I don't think is really supported anyway) then you must either do so as root or use fakeroot (as dpkg-buildpackage does by default).

Well, both bindeb-pkg and deb-pkg use dpkg-buildpackage. Thus fakeroot is used by default.

/bin/sh -c dpkg-buildpackage -r"fakeroot -u" -a$(cat debian/arch) -d -b -nc -uc

The root cause is that while calling chown -R root:root "$pdir" is ok on Debian, it's refused for fakeroot in openSUSE. I can run it with DEB_RULES_REQUIRES_ROOT=no, that should fix that, but I'd prefer it were working by default (although I admit not many people need it).
I reported it because the default setup worked before 3e8541803624. I'll have a look what configuration (permission) is missing on openSUSE to allow chown -R root:root for non-root user.

Quoted 1 line

Ben.

Kind regards,
Petr

#3 lore raw
Quoted 48 lines · Petr Vorel

Hi Ben,

first, thanks for your review.

Quoted 23 lines · Petr Vorel
Quoted 5 lines

This fixes make bindeb-pkg for RPM based distros, which don't have dpkg-dev (and thus not /usr/bin/dpkg-buildpackage), which sets $DEB_RULES_REQUIRES_ROOT.

Fixes 3e8541803624 ("builddeb: Enable rootless builds")

This doesn't seem to fix a bug, and in fact it would introduce one.

Quoted 1 line

[...]

scripts/package/builddeb create_package() { · line 43

Quoted 11 lines
scripts/package/builddeb +1 -1
@@ -37,7 +37,7 @@ create_package() {
                | xargs -r0 md5sum > DEBIAN/md5sums"
 
        # Fix ownership and permissions
-       if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
+       if [ -z "$DEB_RULES_REQUIRES_ROOT" -o "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
                dpkg_deb_opts="--root-owner-group"
        else
                chown -R root:root "$pdir"
Quoted 2 lines

This is the wrong default behaviour; it will cause a regression with older versions of dpkg that don't support this option.

Sorry for wrong report. I tested it on Debian, but only on unstable.

Quoted 3 lines

If you invoke this script directly and do not use dpkg-buildpackage (which I don't think is really supported anyway) then you must either do so as root or use fakeroot (as dpkg-buildpackage does by default).

Well, both bindeb-pkg and deb-pkg use dpkg-buildpackage. Thus fakeroot is used by default.

/bin/sh -c dpkg-buildpackage -r"fakeroot -u" -a$(cat debian/arch) -d -b -nc -uc

The root cause is that while calling chown -R root:root "$pdir" is ok on Debian, it's refused for fakeroot in openSUSE. I can run it with DEB_RULES_REQUIRES_ROOT=no, that should fix that, but I'd prefer it were working by default (although I admit not many people need it).
I reported it because the default setup worked before 3e8541803624. I'll have a look what configuration (permission) is missing on openSUSE to allow chown -R root:root for non-root user.

Quoted 4 lines
Quoted 1 line

Ben.

Kind regards,
Petr

I do not know what is different on openSUSE, but
my understanding is like follows:

For old dpkg tools (which does not know "Rules-Requires-Root: no"), $DEB_RULES_REQUIRES_ROOT is empty.
-> We run chown -R root:root like before.

For new dpkg tools (which knows "Rules-Requires-Root: no"), $DEB_RULES_REQUIRES_ROOT is "no".
-> We pass --root-owner-group to dpkg-deb.

--
Best Regards
Masahiro Yamada

author
#4 lore raw
Quoted 61 lines · Petr Vorel
Quoted 48 lines

Hi Ben,

first, thanks for your review.

Quoted 23 lines · Petr Vorel
Quoted 5 lines

This fixes make bindeb-pkg for RPM based distros, which don't have dpkg-dev (and thus not /usr/bin/dpkg-buildpackage), which sets $DEB_RULES_REQUIRES_ROOT.

Fixes 3e8541803624 ("builddeb: Enable rootless builds")

This doesn't seem to fix a bug, and in fact it would introduce one.

Quoted 1 line

[...]

scripts/package/builddeb create_package() { · line 43

Quoted 11 lines
scripts/package/builddeb +1 -1
@@ -37,7 +37,7 @@ create_package() {
                | xargs -r0 md5sum > DEBIAN/md5sums"
 
        # Fix ownership and permissions
-       if [ "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
+       if [ -z "$DEB_RULES_REQUIRES_ROOT" -o "$DEB_RULES_REQUIRES_ROOT" = "no" ]; then
                dpkg_deb_opts="--root-owner-group"
        else
                chown -R root:root "$pdir"
Quoted 2 lines

This is the wrong default behaviour; it will cause a regression with older versions of dpkg that don't support this option.

Sorry for wrong report. I tested it on Debian, but only on unstable.

Quoted 3 lines

If you invoke this script directly and do not use dpkg-buildpackage (which I don't think is really supported anyway) then you must either do so as root or use fakeroot (as dpkg-buildpackage does by default).

Well, both bindeb-pkg and deb-pkg use dpkg-buildpackage. Thus fakeroot is used by default.

/bin/sh -c dpkg-buildpackage -r"fakeroot -u" -a$(cat debian/arch) -d -b -nc -uc

The root cause is that while calling chown -R root:root "$pdir" is ok on Debian, it's refused for fakeroot in openSUSE. I can run it with DEB_RULES_REQUIRES_ROOT=no, that should fix that, but I'd prefer it were working by default (although I admit not many people need it).
I reported it because the default setup worked before 3e8541803624. I'll have a look what configuration (permission) is missing on openSUSE to allow chown -R root:root for non-root user.

Quoted 4 lines
Quoted 1 line

Ben.

Kind regards,
Petr

I do not know what is different on openSUSE, but
my understanding is like follows:

Quoted 8 lines

For old dpkg tools (which does not know "Rules-Requires-Root: no"), $DEB_RULES_REQUIRES_ROOT is empty.
-> We run chown -R root:root like before.

For new dpkg tools (which knows "Rules-Requires-Root: no"), $DEB_RULES_REQUIRES_ROOT is "no".
-> We pass --root-owner-group to dpkg-deb.

Yes. I'm using dpkg 1.19.0.4, which knows "Rules-Requires-Root: no", but does not know --rules-requires-root (added in 1.19.1). export DEB_RULES_REQUIRES_ROOT=no fixes the problem for my version (but that does not break the build). I just wanted to save time for the others, but 1) there are probably not many people using OBS to build Debian packages and 2) maybe it's just me who does not know it.

It looks to me debhelper is not used for kernel Debian packaing, right? At least building works even I don't have it.

As a result of this I'll also update openSUSE dpkg package to latest release.

Thanks all for explanation.

Kind regards,
Petr