[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to unpack an repack a deb package?



On 08/26/2016 02:03 PM, Hans wrote:
> I need to unpack and repack a debian package. Reason: I want to change the 
> dependencies in that package. 
> 
> How can I do that? I imagine, to unpack the *.deb, then edit my control file, 
> after that pack it again. 

Well, the easiest way to do so, if you have Debian's packaging tools
(notably dpkg-deb and fakeroot) installed:

($DIR/ shouldn't exist prior to this and could be the package name)
dpkg-deb -x package.deb $DIR/
dpkg-deb -e package.deb $DIR/DEBIAN
$EDITOR $DIR/DEBIAN/control
fakeroot dpkg-deb -b $DIR package_repacked.deb
rm -r $DIR

Example:

apt-get download sed
dpkg-deb -x sed_4.2.2-7.1_amd64.deb sed
dpkg-deb -e sed_4.2.2-7.1_amd64.deb sed/DEBIAN
$EDITOR sed/DEBIAN/control
   (I added Recommends: gawk to the control file and incremented
   the version by adding +local0 at the end)
fakeroot dpkg-deb -b sed sed_4.2.2-7.1+local0_amd64.deb
rm -r sed

If you don't have dpkg-deb installed, you can manually use ar/tar:

ar x sed_4.2.2-7.1_amd64.deb
mkdir sed sed/DEBIAN
tar -C sed -xJf data.tar.xz
tar -C sed/DEBIAN -xzf control.tar.gz
$EDITOR sed/DEBIAN/control
tar -C sed --exclude=DEBIAN --owner=root --group=root -cJf data.tar.xz .
tar -C sed/DEBIAN --owner=root --group=root -czf control.tar.gz .
ar cr sed_4.2.2-7.1+local0_amd64.deb debian-binary control.tar.gz data.tar.xz
    (debian-binary should be a file created by the unpacking
    with ar x, should contain a single line "2.0")

(Please change the compression algorithms for tar where appropriate,
depending on whether gzip, xz and/or bzip2 are used. My example shows
both gzip and xz for different files.)

There are corner cases when either method won't work properly out of
the box unless you are root or at the very least run the entire shell
you're in under fakeroot. (Notably when files have setuid permissions.)

> Is it that easy? I googled, but ar -x paket.deb /tmp/paket did not work.

ar x, not ar -x (ar is funny that way)

Big Warning: if you do not ALSO change the version of the package
slightly (e.g. by adding +local0 at the end), then this can have all
sorts of unpredictable results if you have package sources with _both_
Debian's version of the package and your modified version. The same
version of a package should _not_ be used twice in Debian for different
packages.

Regards,
Christian


Reply to: