1
This was originally posted to stackoverflow (https://stackoverflow.com/questions/47099045/how-do-you-create-a-dpkg-admin-directory) but probably belongs here instead
I have a package that previously only targeted RPM based distros for which I am now building .deb packages for Debian based distros.
The aim is to simulate a test installation from user-space that is isolated from the system you are building on. It may be multi-user and you do not want to require root access just to build the software. Many of our tests simulate the installation directory structure already. This is for the next step up to simulate an actual installation using packages built.
For the RPM packages I was able to create test installations using:
WSDIR=/where/I/want/my/tests/to/run
rpmdb --initdb --dbpath "$WSDIR"/rpmdb
rpm --relocate /opt="$WSDIR"/opt --dbpath $WSDIR/rpmdb -i <package>.rpm
The equivalent in the Debian world is something like:
dpkg --force-not-root --admindir=$WSDIR/dpkg --root=$WSDIR/install --install "$DEB"
However, I am stuck over the equivalent to the rpmdb --initdb
step.
Note that I can just unpack the archive using:
dpkg-deb -x "$DEB" $WSDIR/install
But I would prefer to be closer to how a real package is installed.
Also I don't think this will run preinstall
and postinstall
scripts.
Similar questions have suggested using deboostrap
to create a chroot
environment but this creates a complete new installation. As well as being overkill it is too slow for an automated test. I intend to use this for quick tests of the installation package prior to further testing in actual test environments.
My experiments so far:
(cd $WSDIR/dpkg && mkdir alternatives info parts triggers updates)
cp /var/lib/dpkg/status $WSDIR/dpkg/status
have at best resulted in:
dpkg: error: unable to access dpkg status area: No such file or directory
which does not indicate clear what is wrong.
So how do you create a dpkg admin directory?
Update 24/11/2017
I've tried copying using the dpkg dir from an environment created by cowdancer (which uses deboostrap under the hood) or copying the real one from /var/lib/dpkg but I still get the same error message so perhaps the error (and/or the --admindir option) doesn't mean quite what I think it means.
Note that:
sudo dpkg --force-not-root --root=$WSDIR/install --admindir=/var/lib/dpkg --install "$DEB"
does work. So it is something to do with the admind dir.
I've also retitled the question as "How do you create a dpkg admin directory" is interesting question but the answer is not necessarily the solution to my problem.
Note the original question currently has an open bounty. – Bruce Adams – 2017-11-23T12:57:03.840
Hmm. May be just use
– kostix – 2017-11-24T07:38:49.903debootstrap
orcdebootstrap
to create a chroot with a minimal "real" installation and then install the package there? You could snapshot the contents of the target directory after bootstrapping and then compare it with the results of the trial package installation. There exist a special solution,cowdancer
, which can make this process much faster by "preimaging" the debootstrapped directory.Otherwise you may look at
fakeroot
— the stock tools used to build Debian package use it to "virtualize" a call tomake install
they make — making it think it was called by root and that in installs stuff into a real filesystem directories with restricted access (such as/usr/bin
) while actually redirected into a dedicated directory writable by the normal user running thefakeroot
encantation. – kostix – 2017-11-24T07:40:48.893