> It would be nice if dpkg-deb could produce .deb archives where all 
> files are owned by root:root, ignoring the ownership attributes from
> the filesystem.

Here is a patch for this, see rootowner.patch in the attachment.
It introduces options --root-owner, to create root-owned archives,
and --same-owner (the default).

The second patch is a usage example, it allows dpkg itself to be built
without (fake)root. It is relatively large as I had to remove all those
"-o root -g root" install arguments (useless anyway). Besides that, the 
patch only deletes the `id -u` test and adds --root-owner to dpkg-deb.

Could you drop me a note on whether the feature is worth considering
for inclusion to dpkg, at some point in the future? (I don't know, 
maybe I'm the only one who finds fakeroot inconvenient.)

Best regards,
Sergei Ivanov
--- dpkg-1.10.26/dpkg-deb/main.c.-rootowner     2005-01-11 19:55:11.000000000 
+0300
+++ dpkg-1.10.26/dpkg-deb/main.c        2005-01-23 03:38:12.000000000 +0300
@@ -76,6 +76,7 @@
 "  --showformat=<format>      use alternative format for --show\n"
 "  -D                         enable debugging output\n"
 "  --old, --new               select archive format\n"
+"  --root-owner, --same-owner set ownership of files in the archive\n"
 "  --nocheck                  suppress control file check (build bad 
package).\n"
 "  -z# to set the compression when building\n"
 "  -Z<type>                   set the compression type to use when building.\n"
@@ -101,6 +102,7 @@
      "Type dpkg --help for help about installing and deinstalling packages.");
 
 int debugflag=0, nocheckflag=0, oldformatflag=BUILDOLDPKGFORMAT;
+int sameownerflag=1;
 const char* compression=NULL;
 enum compression_type compress_type = GZ;
 const struct cmdinfo *cipaction=0;
@@ -145,6 +147,8 @@
   { "show",         'W',  0,  0, 0,               setaction        },
   { "new",           0,   0,  &oldformatflag, 0,  0,            0  },
   { "old",           0,   0,  &oldformatflag, 0,  0,            1  },
+  { "root-owner",    0,   0,  &sameownerflag, 0,  0,            0  },
+  { "same-owner",    0,   0,  &sameownerflag, 0,  0,            1  },
   { "debug",        'D',  0,  &debugflag,     0,  0,            1  },
   { "nocheck",       0,   0,  &nocheckflag,   0,  0,            1  },
   { "compression",  'z',  1,  0,   &compression,  0,            1  },
--- dpkg-1.10.26/dpkg-deb/dpkg-deb.h.-rootowner 2005-01-11 19:55:11.000000000 
+0300
+++ dpkg-1.10.26/dpkg-deb/dpkg-deb.h    2005-01-23 03:38:12.000000000 +0300
@@ -28,6 +28,7 @@
 dofunction do_info, do_field, do_extract, do_vextract, do_fsystarfile;
 
 extern int debugflag, nocheckflag, oldformatflag;
+extern int sameownerflag;
 extern const struct cmdinfo *cipaction;
 extern dofunction *action;
 
--- dpkg-1.10.26/dpkg-deb/build.c.-rootowner    2005-01-11 19:55:11.000000000 
+0300
+++ dpkg-1.10.26/dpkg-deb/build.c       2005-01-23 03:38:12.000000000 +0300
@@ -319,7 +319,11 @@
     m_dup2(p1[1],1); close(p1[0]); close(p1[1]);
     if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
     if (chdir(BUILDCONTROLDIR)) ohshite(_("failed to chdir to .../DEBIAN"));
-    execlp(TAR,"tar","-cf","-",".",(char*)0); ohshite(_("failed to exec tar 
-cf"));
+    if (sameownerflag)
+      execlp(TAR,"tar","-cf","-",".",(char*)0);
+    else
+      execlp(TAR,"tar","-cf","-","--owner=root","--group=root",".",(char*)0);
+    ohshite(_("failed to exec tar -cf"));
   }
   close(p1[1]);
   /* Create a temporary file to store the control data in. Immediately unlink
@@ -391,7 +395,10 @@
     m_dup2(p1[0],0); close(p1[0]); close(p1[1]);
     m_dup2(p2[1],1); close(p2[0]); close(p2[1]);
     if (chdir(directory)) ohshite(_("failed to chdir to `%.255s'"),directory);
-    execlp(TAR,"tar","-cf", "-", "-T", "-", "--null", "--no-recursion", 
(char*)0);
+    if (sameownerflag)
+      execlp(TAR,"tar","-cf", "-", "-T", "-", "--null", "--no-recursion", 
(char*)0);
+    else
+      execlp(TAR,"tar","-cf", "-", "-T", "-", "--null", "--no-recursion", 
"--owner=root", "--group=root", (char*)0);
     ohshite(_("failed to exec tar -cf"));
   }
   close(p1[0]);
--- dpkg-1.10.26/dpkg-deb/dpkg-deb.1.-rootowner 2005-01-11 19:55:11.000000000 
+0300
+++ dpkg-1.10.26/dpkg-deb/dpkg-deb.1    2005-01-23 20:59:26.000000000 +0300
@@ -209,6 +209,12 @@
 when building packages to be parsed by versions of dpkg older than
 0.93.76 (September 1995), which was released as i386 a.out only.
 .TP
+.BR \-\-root\-owner
+Set user and group ownership of all files in the archive to "root".
+.TP
+.BR \-\-same\-owner
+Take ownership data from the filesystem. This is the default.
+.TP
 .BR \-\-nocheck
 Inhibits
 .BR "dpkg\-deb \-\-build" 's
--- dpkg-1.10.26/debian/rules.-orig     2005-01-11 19:55:11.000000000 +0300
+++ dpkg-1.10.26/debian/rules   2005-01-23 22:09:13.000000000 +0300
@@ -86,7 +86,6 @@
 stamp-binary-static: stamp-binary
 stamp-binary: stamp-build
        $(checkdir)
-       test "`id -u`" -eq 0
        rm -rf $(TMP)
        $(MAKE) $(MFLAGS) -C $(BUILD)$* \
                DESTDIR=$(INSTALL_TMP) \
@@ -101,13 +100,13 @@
 
 binary-dpkg-most binary-dpkg-static-most: binary-dpkg%-most: stamp-binary%
        rm -rf $(TMP_DPKG)
-       install -d -m 755 -o root -g root $(TMP_DPKG)
+       install -d -m 755 $(TMP_DPKG)
        chmod g-s $(TMP_DPKG)
-       install -d -m 755 -o root -g root 
$(TMP_DPKG)/usr/share/doc/dpkg$(static)
-       install -d -m 755 -o root -g root $(TMP_DPKG)/usr/lib/dpkg
-       install -d -m 755 -o root -g root $(TMP_DPKG)/usr/bin
-       install -d -m 755 -o root -g root $(TMP_DPKG)/sbin
-       install -d -m 755 -o root -g root $(TMP_DPKG)/var/lib/dpkg
+       install -d -m 755 $(TMP_DPKG)/usr/share/doc/dpkg$(static)
+       install -d -m 755 $(TMP_DPKG)/usr/lib/dpkg
+       install -d -m 755 $(TMP_DPKG)/usr/bin
+       install -d -m 755 $(TMP_DPKG)/sbin
+       install -d -m 755 $(TMP_DPKG)/var/lib/dpkg
        -test -d $(INSTALL_TMP)/etc && cp -a $(INSTALL_TMP)/etc $(TMP_DPKG)/
        set -e ; for i in info alternatives parts updates ; do \
                cp -a $(INSTALL_TMP)/var/lib/dpkg/$$i $(TMP_DPKG)/var/lib/dpkg/ 
; \
@@ -129,19 +128,19 @@
        done
        cp -a debian/pseudo-tags $(TMP_DPKG)/usr/share/doc/dpkg$(static)/
        set -e ; for i in "" $(MANDIRS) ; do \
-               install -d -m 755 -o root -g root 
$(TMP_DPKG)/usr/share/man/$$i/man1 ; \
+               install -d -m 755 $(TMP_DPKG)/usr/share/man/$$i/man1 ; \
                for m in md5sum.1 dpkg-deb.1 ; do \
                        if [ -f $(INSTALL_TMP)/usr/share/man/$$i/man1/$$m ] ; 
then \
                                cp -a $(INSTALL_TMP)/usr/share/man/$$i/man1/$$m 
$(TMP_DPKG)/usr/share/man/$$i/man1/$$m ; \
                        fi ; \
                done ; \
-               install -d -m 755 -o root -g root 
$(TMP_DPKG)/usr/share/man/$$i/man5 ; \
+               install -d -m 755 $(TMP_DPKG)/usr/share/man/$$i/man5 ; \
                for m in dpkg.cfg.5 ; do \
                        if [ -f $(INSTALL_TMP)/usr/share/man/$$i/man5/$$m ] ; 
then \
                                cp -a $(INSTALL_TMP)/usr/share/man/$$i/man5/$$m 
$(TMP_DPKG)/usr/share/man/$$i/man5/$$m ; \
                        fi ; \
                done ; \
-               install -d -m 755 -o root -g root 
$(TMP_DPKG)/usr/share/man/$$i/man8 ; \
+               install -d -m 755 $(TMP_DPKG)/usr/share/man/$$i/man8 ; \
                for m in dpkg.8 dpkg-query.8 dpkg-split.8 start-stop-daemon.8 \
                        cleanup-info.8 dpkg-divert.8 dpkg-statoverride.8 \
                        install-info.8 update-alternatives.8 ; do \
@@ -160,22 +159,22 @@
        mv $(TMP_DPKG)/usr/share/doc/dpkg$(static)/ChangeLog \
                $(TMP_DPKG)/usr/share/doc/dpkg$(static)/changelog
 
-       install -p -m 644 -o root -g root debian/changelog \
+       install -p -m 644 debian/changelog \
                $(TMP_DPKG)/usr/share/doc/dpkg$(static)/changelog.Debian
        rm -f $(TMP_DPKG)/usr/share/doc/dpkg$(static)/copyright
        gzip -9 $(TMP_DPKG)/usr/share/doc/dpkg$(static)/*
-       install -p -m 644 -o root -g root debian/dpkg.cfg \
+       install -p -m 644 debian/dpkg.cfg \
                $(TMP_DPKG)/usr/share/doc/dpkg$(static)/
-       install -p -m 644 -o root -g root debian/copyright \
+       install -p -m 644 debian/copyright \
                $(TMP_DPKG)/usr/share/doc/dpkg$(static)/
 
 # Final package creation
-       install -d -m 755 -o root -g root $(TMP_DPKG)/DEBIAN
-       install -p -m 644 -o root -g root debian/dpkg.conffiles 
$(TMP_DPKG)/DEBIAN/conffiles
-       install -p -m 755 -o root -g root debian/dpkg.preinst 
$(TMP_DPKG)/DEBIAN/preinst
-       install -p -m 755 -o root -g root debian/dpkg.prerm 
$(TMP_DPKG)/DEBIAN/prerm
-       install -p -m 755 -o root -g root debian/dpkg.postinst 
$(TMP_DPKG)/DEBIAN/postinst
-       install -p -m 755 -o root -g root debian/dpkg.postrm 
$(TMP_DPKG)/DEBIAN/postrm
+       install -d -m 755 $(TMP_DPKG)/DEBIAN
+       install -p -m 644 debian/dpkg.conffiles $(TMP_DPKG)/DEBIAN/conffiles
+       install -p -m 755 debian/dpkg.preinst $(TMP_DPKG)/DEBIAN/preinst
+       install -p -m 755 debian/dpkg.prerm $(TMP_DPKG)/DEBIAN/prerm
+       install -p -m 755 debian/dpkg.postinst $(TMP_DPKG)/DEBIAN/postinst
+       install -p -m 755 debian/dpkg.postrm $(TMP_DPKG)/DEBIAN/postrm
 
        $(SHLIBDEPS) -dPre-Depends -Tdebian/dpkg$(static).substvars \
                $(TMP_DPKG)/sbin/start-stop-daemon \
@@ -183,20 +182,20 @@
 
 binary-dpkg binary-dpkg-static: %: %-most
        $(GENCONTROL) -Tdebian/dpkg$(static).substvars -pdpkg$(static) 
-P$(TMP_DPKG)
-       dpkg --build $(TMP_DPKG) ..
+       dpkg-deb --build --root-owner $(TMP_DPKG) ..
 
 binary-dpkg-dev: stamp-binary
        rm -rf $(TMP_DPKG_DEV)
-       install -d -m 755 -o root -g root $(TMP_DPKG_DEV)
+       install -d -m 755 $(TMP_DPKG_DEV)
        chmod g-s $(TMP_DPKG_DEV)
-       install -d -m 755 -o root -g root $(TMP_DPKG_DEV)/etc/dpkg
-       install -p -m 644 -o root -g root debian/shlibs.default \
+       install -d -m 755 $(TMP_DPKG_DEV)/etc/dpkg
+       install -p -m 644 debian/shlibs.default \
                $(TMP_DPKG_DEV)/etc/dpkg/
-       install -p -m 644 -o root -g root debian/shlibs.override \
+       install -p -m 644 debian/shlibs.override \
                $(TMP_DPKG_DEV)/etc/dpkg/
-       install -d -m 755 -o root -g root $(TMP_DPKG_DEV)/usr/lib/dpkg
-       install -d -m 755 -o root -g root $(TMP_DPKG_DEV)/usr/share
-       install -d -m 755 -o root -g root $(TMP_DPKG_DEV)/usr/bin
+       install -d -m 755 $(TMP_DPKG_DEV)/usr/lib/dpkg
+       install -d -m 755 $(TMP_DPKG_DEV)/usr/share
+       install -d -m 755 $(TMP_DPKG_DEV)/usr/bin
        mv $(INSTALL_TMP)/usr/lib/dpkg/parsechangelog 
$(TMP_DPKG_DEV)/usr/lib/dpkg/
        mv $(INSTALL_TMP)/usr/lib/dpkg/controllib.pl 
$(TMP_DPKG_DEV)/usr/lib/dpkg/
        set -e ; for i in dpkg-name dpkg-source dpkg-genchanges dpkg-gencontrol 
\
@@ -206,7 +205,7 @@
                mv $(INSTALL_TMP)/usr/bin/$$i $(TMP_DPKG_DEV)/usr/bin/ ; \
        done
        set -e ; for i in "" $(MANDIRS) ; do \
-               install -d -m 755 -o root -g root 
$(TMP_DPKG_DEV)/usr/share/man/$$i/man1 ; \
+               install -d -m 755 $(TMP_DPKG_DEV)/usr/share/man/$$i/man1 ; \
                for m in dpkg-name.1 dpkg-source.1 822-date.1 
dpkg-architecture.1 \
                        dpkg-buildpackage.1 dpkg-distaddfile.1 
dpkg-genchanges.1 \
                        dpkg-gencontrol.1 dpkg-parsechangelog.1 
dpkg-shlibdeps.1 \
@@ -215,7 +214,7 @@
                                mv $(INSTALL_TMP)/usr/share/man/$$i/man1/$$m 
$(TMP_DPKG_DEV)/usr/share/man/$$i/man1/$$m ; \
                        fi ; \
                done ; \
-               install -d -m 755 -o root -g root 
$(TMP_DPKG_DEV)/usr/share/man/$$i/man5 ; \
+               install -d -m 755 $(TMP_DPKG_DEV)/usr/share/man/$$i/man5 ; \
                for m in deb.5 deb-control.5 deb-old.5 ; do \
                        if [ -e $(INSTALL_TMP)/usr/share/man/$$i/man5/$$m ] ; 
then \
                                mv $(INSTALL_TMP)/usr/share/man/$$i/man5/$$m 
$(TMP_DPKG_DEV)/usr/share/man/$$i/man5/$$m ; \
@@ -225,38 +224,38 @@
 # Now that dpkg-dev has been installed, Debianize it
 # Policy stuff
        find $(TMP_DPKG_DEV)/usr/share/man -type f | xargs gzip -9f
-       install -d -m 755 -o root -g root $(TMP_DPKG_DEV)/usr/share/doc
+       install -d -m 755 $(TMP_DPKG_DEV)/usr/share/doc
        ln -s dpkg $(TMP_DPKG_DEV)/usr/share/doc/dpkg-dev
 
 # Final package creation
-       install -d -m 755 -o root -g root $(TMP_DPKG_DEV)/DEBIAN
-       install -p -m 644 -o root -g root debian/dpkg-dev.conffiles 
$(TMP_DPKG_DEV)/DEBIAN/conffiles
+       install -d -m 755 $(TMP_DPKG_DEV)/DEBIAN
+       install -p -m 644 debian/dpkg-dev.conffiles 
$(TMP_DPKG_DEV)/DEBIAN/conffiles
 
        $(GENCONTROL) -Tdebian/dpkg-dev.substvars -pdpkg-dev -P$(TMP_DPKG_DEV)
-       dpkg --build $(TMP_DPKG_DEV) ..
+       dpkg-deb --build --root-owner $(TMP_DPKG_DEV) ..
 
 binary-dselect: stamp-binary
        rm -rf $(TMP_DSELECT)
-       install -d -m 755 -o root -g root $(TMP_DSELECT)
+       install -d -m 755 $(TMP_DSELECT)
        chmod g-s $(TMP_DSELECT)
 
-       install -d -m 755 -o root -g root $(TMP_DSELECT)/usr/bin
+       install -d -m 755 $(TMP_DSELECT)/usr/bin
        mv $(INSTALL_TMP)/usr/bin/dselect $(TMP_DSELECT)/usr/bin/
 
-       install -d -m 755 -o root -g root $(TMP_DSELECT)/usr/lib/dpkg
+       install -d -m 755 $(TMP_DSELECT)/usr/lib/dpkg
        mv $(INSTALL_TMP)/usr/lib/dpkg/methods $(TMP_DSELECT)/usr/lib/dpkg/
 
-       install -d -m 755 -o root -g root $(TMP_DSELECT)/var/lib/dpkg
+       install -d -m 755 $(TMP_DSELECT)/var/lib/dpkg
        mv $(INSTALL_TMP)/var/lib/dpkg/methods $(TMP_DSELECT)/var/lib/dpkg/
 
        set -e ; for i in "" $(MANDIRS) ; do \
-               install -d -m 755 -o root -g root 
$(TMP_DSELECT)/usr/share/man/$$i/man5 ; \
+               install -d -m 755 $(TMP_DSELECT)/usr/share/man/$$i/man5 ; \
                for m in dselect.cfg.5 ; do \
                        if [ -f $(INSTALL_TMP)/usr/share/man/$$i/man5/$$m ] ; 
then \
                                cp -a $(INSTALL_TMP)/usr/share/man/$$i/man5/$$m 
$(TMP_DSELECT)/usr/share/man/$$i/man5/$$m ; \
                        fi ; \
                done ; \
-               install -d -m 755 -o root -g root 
$(TMP_DSELECT)/usr/share/man/$$i/man8 ; \
+               install -d -m 755 $(TMP_DSELECT)/usr/share/man/$$i/man8 ; \
                for m in dselect.8 ; do \
                        if [ -f $(INSTALL_TMP)/usr/share/man/$$i/man8/$$m ] ; 
then \
                                cp -a $(INSTALL_TMP)/usr/share/man/$$i/man8/$$m 
$(TMP_DSELECT)/usr/share/man/$$i/man8/$$m ; \
@@ -264,31 +263,31 @@
                done ; \
        done
 
-       install -d -m 755 -o root -g root $(TMP_DSELECT)/etc/dpkg
-       install -p -m 644 -o root -g root debian/dselect.cfg \
+       install -d -m 755 $(TMP_DSELECT)/etc/dpkg
+       install -p -m 644 debian/dselect.cfg \
                $(TMP_DSELECT)/etc/dpkg/
 
 # Now do the usual Debian stuff
        find $(TMP_DSELECT)/usr/share/man -type f | xargs gzip -9f
-       install -d -m 755 -o root -g root $(TMP_DSELECT)/usr/share/doc
+       install -d -m 755 $(TMP_DSELECT)/usr/share/doc
        ln -s dpkg $(TMP_DSELECT)/usr/share/doc/dselect
        strip --remove-section=.comment --remove-section=.note \
                --strip-unneeded $(TMP_DSELECT)/usr/bin/* 
 
 # Final package creation
-       install -d -m 755 -o root -g root $(TMP_DSELECT)/DEBIAN
-       install -p -m 644 -o root -g root debian/dselect.conffiles 
$(TMP_DSELECT)/DEBIAN/conffiles
+       install -d -m 755 $(TMP_DSELECT)/DEBIAN
+       install -p -m 644 debian/dselect.conffiles 
$(TMP_DSELECT)/DEBIAN/conffiles
 
        $(SHLIBDEPS) -Tdebian/dselect.substvars \
                $(TMP_DSELECT)/usr/bin/dselect 
        $(GENCONTROL) -Tdebian/dselect.substvars -pdselect -P$(TMP_DSELECT)
-       dpkg --build $(TMP_DSELECT) ..
+       dpkg-deb --build --root-owner $(TMP_DSELECT) ..
 
 binary-dpkg-doc: stamp-binary
        rm -rf $(TMP_DPKG_DOC)
-       install -d -m 755 -o root -g root $(TMP_DPKG_DOC)
+       install -d -m 755 $(TMP_DPKG_DOC)
        chmod g-s $(TMP_DPKG_DOC)
-       install -d -m 755 -o root -g root $(TMP_DPKG_DOC)/usr/share/doc/dpkg
+       install -d -m 755 $(TMP_DPKG_DOC)/usr/share/doc/dpkg
        mv $(INSTALL_TMP)/usr/share/doc/dpkg/internals 
$(TMP_DPKG_DOC)/usr/share/doc/dpkg/
        mv $(INSTALL_TMP)/usr/share/doc/dpkg/ChangeLog.manuals \
                $(TMP_DPKG_DOC)/usr/share/doc/dpkg/changelog.manuals
@@ -299,17 +298,17 @@
        ln -s dpkg $(TMP_DPKG_DOC)/usr/share/doc/dpkg-doc
 
 # Register documentation with doc-base
-       install -d -m 755 -o root -g root $(TMP_DPKG_DOC)/usr/share/doc-base
-       install -p -m 644 -o root -g root debian/dpkg-doc.doc-base \
+       install -d -m 755 $(TMP_DPKG_DOC)/usr/share/doc-base
+       install -p -m 644 debian/dpkg-doc.doc-base \
                $(TMP_DPKG_DOC)/usr/share/doc-base/dpkg-doc
        
 # Final package creation
-       install -d -m 755 -o root -g root $(TMP_DPKG_DOC)/DEBIAN
-       install -p -m 755 -o root -g root debian/dpkg-doc.prerm 
$(TMP_DPKG_DOC)/DEBIAN/prerm
-       install -p -m 755 -o root -g root debian/dpkg-doc.postinst 
$(TMP_DPKG_DOC)/DEBIAN/postinst
+       install -d -m 755 $(TMP_DPKG_DOC)/DEBIAN
+       install -p -m 755 debian/dpkg-doc.prerm $(TMP_DPKG_DOC)/DEBIAN/prerm
+       install -p -m 755 debian/dpkg-doc.postinst 
$(TMP_DPKG_DOC)/DEBIAN/postinst
 
        $(GENCONTROL) -Tdebian/dpkg-doc.substvars -pdpkg-doc -P$(TMP_DPKG_DOC)
-       dpkg --build $(TMP_DPKG_DOC) ..
+       dpkg-deb --build --root-owner $(TMP_DPKG_DOC) ..
 
 binary-arch-static: binary-dpkg-static
 binary-arch: binary-dpkg binary-dpkg-static-most binary-dselect

Reply via email to