Ubuntu – what user/ file owner to use when creating debian packages

debianpackage-management

We are creating a simple binary package for a war file and some scripts using dpkg-deb.

One issue is that say we are doing this as a local user called "goofy", then the files in the package will be owned by goofy.

When we later try to install this package as root, we were surprised that the files it put in /opt/ourpackage were all still owned by goofy.

Now goofy user wont exist on most peoples machines, so what is the best way to handle this?

We assume there are two options:

  1. make all the files be owned by a user we can assume exists on all servers – i.e. root.
  2. create some pre-installation scripts which create the goofy (or appropriate) user first.

What method is recommended?

IF the answer is 2, does anyone have any tried and tested scripts we could add to the package to do this?

We would have chosen option1, but this is hampered by the fact that the "user" who will be creating and building the packages is jenkins, so cant easily create files owned by root.

Best Answer

The solution in the end was to use fakeroot (sudo apt-get install fakeroot).

Then the packager can own the files to be packaged, but when we run:

fakeroot dpkg-deb --build debian

it spoofs the builder to think that all the files are owned by root, and keeps lintian happy and installs the files as root on the target server.