I have already seen Easily unpack DEB, edit postinst, and repack DEB - however, that one doesn't explain how to properly change the .deb version number if I want to do some changes the original .deb file.
I'm on Ubuntu 14.04, and let's take hostapd
for an example:
$ mkdir /tmp/debtest
$ cd /tmp/debtest/
$ apt-get download hostapd
Get:1 http://dk.archive.ubuntu.com/ubuntu/ trusty-updates/universe hostapd amd64 1:2.1-0ubuntu1.4 [423 kB]
Fetched 423 kB in 1s (361 kB/s)
$ ls -la hostapd_1%3a2.1-0ubuntu1.4_amd64.deb
-rw-rw-r-- 1 myuser myuser 422846 Nov 10 2015 hostapd_1%3a2.1-0ubuntu1.4_amd64.deb
Now we can unpack as in the cited link above:
$ mkdir unpack-hostapd
$ dpkg-deb -R hostapd_1%3a2.1-0ubuntu1.4_amd64.deb unpack-hostapd
$ ls -la unpack-hostapd/
total 20
drwxr-xr-x 5 myuser myuser 4096 Jan 26 11:31 .
drwxrwxr-x 3 myuser myuser 4096 Jan 26 11:31 ..
drwxr-xr-x 2 myuser myuser 4096 Nov 9 2015 DEBIAN
drwxr-xr-x 6 myuser myuser 4096 Nov 9 2015 etc
drwxr-xr-x 4 myuser myuser 4096 Nov 9 2015 usr
Let's say I want to make a trival change, say appending a line of text to README.Debian:
echo "Just a test line" >> unpack-hostapd/usr/share/doc/hostapd/README.Debian
... and now I want to repack this as a new .deb.
First question - is there a way to retrieve the current (old) version of the package from the unpacked state? Because I don't trust filenames, I'd usually do:
$ apt-cache policy hostapd
hostapd:
Installed: (none)
Candidate: 1:2.1-0ubuntu1.4
...
... and this tells me I've downloaded version 1:2.1-0ubuntu1.4 of the package when I used apt-get download...
- but not necessarily what is the version inside the unpack-hostapd
directory. Is there a command that will tell me the package version of the originating .deb that was unpacked into the unpack-hostapd
directory?
Now, I've used debchange
as dch -i
before to auto-increment a version number (although in other source projects), but when I try it here:
$ cd unpack-hostapd
$ pwd
/tmp/debtest/unpack-hostapd
$ dch -e
dch: fatal error at line 580:
Cannot find debian/changelog anywhere!
Are you in the source code tree?
(You could use --create if you wish to create this file.)
$ find . -name 'changelog*'
./usr/share/doc/hostapd/changelog.Debian.gz
$ dpkg -c ../hostapd_1%3a2.1-0ubuntu1.4_amd64.deb | grep changelog
-rw-r--r-- root/root 2126 2015-11-09 14:56 ./usr/share/doc/hostapd/changelog.Debian.gz
... but, I cannot change any of that here.
So, my second question is: is there an easy way (like dch -i
is for source packages) to change the .deb package version number, and possibly add a changelog, to an unpacked .deb package like this?
Of course, ultimately I'd like to re-pack this new version as a .deb package, for which the link above suggests something like dpkg-deb -b unpack-hostapd hostapd_1%3a2.1-0ubuntu1.4_amd64.deb
; although, say here I'd rather use version 1:2.2
, so I'd finally use a filename like dpkg-deb -b unpack-hostapd hostapd_1%3a2.2_amd64.deb
- however, that version should also match what is recorded inside the .deb, and I don't know how to do that...
hostapd
sources are available. And presumably rebuilding them is not an issue. Oh, I believe the Debian metadata is in the DEBIAN directory, though I'm not 100% sure about that.