kbuild: scripts/package: use $(ROOTCMD) to become root
PATCH 1/2 kbuild: scripts/package: use $(ROOTCMD) to become root
Use the value of the ROOTCMD variable as a command to acquire root or fake root privileges for "make tar-pkg" et al.
So now you can do
$ make oldconfig rpm-pkg ROOTCMD="fakeroot -u"
as a shortcut for
$ make oldconfig &&
Quoted 2 lines
make &&
fakeroot -u make rpm-pkg
In the future, ROOTCMD="fakeroot -u" could be set automatically when not running as root and fakeroot is found on the path, so that "make oldconfig deb-pkg" would just work without fuss.
Idea from Ryan Anderson
<http://thread.gmane.org/gmane.comp.version-control.git/14770/focus=14802>.
---
Thoughts?
Thanks,
Jonathan
scripts/package/Makefile | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
scripts/package/Makefile +7 -6
@@ -44,7 +44,8 @@ rpm-pkg rpm: $(objtree)/kernel.spec FORCE set -e; \ mv -f $(objtree)/.tmp_version $(objtree)/.version - $(RPM) $(RPMOPTS) --target $(UTS_MACHINE) -ta ../$(KERNELPATH).tar.gz + $(ROOTCMD) $(RPM) $(RPMOPTS) --target $(UTS_MACHINE) \ + -ta ../$(KERNELPATH).tar.gz rm ../$(KERNELPATH).tar.gz clean-files := $(objtree)/kernel.spec
@@ -61,8 +62,8 @@ binrpm-pkg: $(objtree)/binkernel.spec FORCE set -e; \ mv -f $(objtree)/.tmp_version $(objtree)/.version - $(RPM) $(RPMOPTS) --define "_builddir $(srctree)" --target \ - $(UTS_MACHINE) -bb $< + $(ROOTCMD) $(RPM) $(RPMOPTS) --define "_builddir $(srctree)" \ + --target $(UTS_MACHINE) -bb $< clean-files += $(objtree)/binkernel.spec
@@ -70,7 +71,7 @@ clean-files += $(objtree)/binkernel.spec # --------------------------------------------------------------------------- deb-pkg: FORCE $(MAKE) KBUILD_SRC= - $(CONFIG_SHELL) $(srctree)/scripts/package/builddeb + $(ROOTCMD) $(CONFIG_SHELL) $(srctree)/scripts/package/builddeb clean-dirs += $(objtree)/debian/
@@ -79,7 +80,7 @@ clean-dirs += $(objtree)/debian/ # --------------------------------------------------------------------------- tar%pkg: FORCE $(MAKE) KBUILD_SRC= - $(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@ + $(ROOTCMD) $(CONFIG_SHELL) $(srctree)/scripts/package/buildtar $@ clean-dirs += $(objtree)/tar-install/
@@ -87,10 +88,10 @@ clean-dirs += $(objtree)/tar-install/ # Help text displayed when executing 'make help' # --------------------------------------------------------------------------- help: FORCE + @echo ' Set ROOTCMD={sudo|fakeroot -u|super|...} and make as non-root:' @echo ' rpm-pkg - Build both source and binary RPM kernel packages' @echo ' binrpm-pkg - Build only the binary kernel package' @echo ' deb-pkg - Build the kernel as an deb package' @echo ' tar-pkg - Build the kernel as an uncompressed tarball' @echo ' targz-pkg - Build the kernel as a gzip compressed tarball' @echo ' tarbz2-pkg - Build the kernel as a bzip2 compressed tarball' -
Signature · 1 line
1.6.5.rc1.199.g596ec
PATCH 2/2 kbuild: scripts/package: set ROOTCMD="fakeroot -u" by default
Unless already running as root, use fakeroot to ensure the files in the generated binary packages are owned by root. Without this change, you have to set ROOTCMD or become root yourself to run "make foo-pkg".
With this change, you can run "make oldconfig rpm-pkg" as an ordinary user to build a binary package for an updated kernel tree and it should just work.
fakeroot is a bit too zealous by default in pretending files are owned by root: unless directed otherwise, its wrapped stat() and lstat() set st_uid and st_gid to 0 for all files. If CONFIG_LOCALVERSION_AUTO=y is set, git notices that the owners have changed and has to reread the entire kernel tree to discover that the version string does not need a "-dirty" suffix. But as long as "make install" and "scripts/package/foo" run within the same fakeroot invocation, it is perfectly safe to use the actual owner and group for preexisting files. Make it so by passing fakeroot the -u option.
Note: if fakeroot is missing, all members of the package generated by "make tar-pkg" will be owned and writable by the invoking user, even once the archive is extracted. This is true even without this patch and probably should be addressed separately.
---
Actually, this is all just an excuse to include a reminder about fakeroot -u in the kernel. :) But maybe it could be convenient for others, anyway.
I look forward to your thoughts.
Thanks,
Jonathan
scripts/package/Makefile | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
scripts/package/Makefile +9 -0
@@ -1,6 +1,15 @@ # Makefile for the different targets used to generate full packages of a kernel # It uses the generic clean infrastructure of kbuild +# How to acquire (fake) root privileges +ifndef ROOTCMD +ifneq ($(shell id -u),0) +ifeq ($(shell which fakeroot >/dev/null 2>&1 && echo found),found) +ROOTCMD := fakeroot -u +endif +endif +endif + # RPM target # --------------------------------------------------------------------------- # The rpm target generates two rpm files:
Signature · 1 line
1.6.5.rc1.199.g596ec