What is the correct way to create your own packages for local installation?
Solution 1:
I would download the source and the build dependencies for the Ubuntu version first:
apt-get install dpkg-dev
apt-get build-dep <package>
apt-get source <package>
The unmodified, upstream source the Ubuntu version is based on will be in a file called <pkg>_<ver>.orig.tar.gz (compression scheme may vary) - I would decompress this to one directory (let's call it "dir A"), then download the source to the bug-fixed version into another directory ("dir B"), and then generate a patch for what's changed:
diff -Nur <dirA> <dirB> >/tmp/upgrade.patch
Then change to the directory where apt-get source decompressed the modified Ubuntu version, and apply the patch
patch -p1 </tmp/upgrade.patch
Assuming there weren't many changes between the two upstream versions, and they didn't conflict with any of the Ubuntu packager's changes, this should work. Then edit debian/changelog in the Ubuntu package to give it a new version number, and dpkg-buildpackage should build you a custom version..
Solution 2:
Just to toot my own horn, I have creating a solution for this exact circumstance. You can have a Debian package downloaded, unpacked, built, and reinstalled in 2 or 3 commands.
It is a shell script debtool and is available on GitHub via the aforementioned link.
Building Debian packages from source can be cumbersome, especially on a daily driver that you don't necessarily want to muddle up with numerous build dependencies and the like.
Assuming libvirt is available via sources, run the following command:
debtool --download --unpack libvirt
The above command just downloaded the libvirt_0.9.8_all.deb file and unpacked it into the directory libvirt_0.9.8_all.
Alternatively, you can unpack the version of libvirt that is currently installed on your system:
debtool --unpack libvirt
At this point you should make all of your changes to the files in the directory. You will also likely want to bump up the package's version number (i.e. 0.9.8-custom1) located in ./libvirt_0.9.8_all/DEBIAN/control.
Now build the package by running the following command:
debtool --build ./libvirt_0.9.8_all
Your finished package is now in the current directory as libvirt_0.9.8-custom1_all.deb.
You can quickly reinstall this package by running debtool --reinst ./libvirt_0.9.8-custom1_all.deb
or alternatively debtool --build --reinst ./libvirt_0.9.8_all
to build and reinstall in one fell swoop.
Etcetera
You can do a couple of other related tasks with debtool as well.
Show Available Versions
If there are several versions of a package available in the repositories, you can list them as follows:
debtool --show zsh
The above command will return the following:
zsh 5.0.5-4ubuntu1~ubuntu14.04.1 amd64
zsh 5.0.2-3ubuntu6 amd64
If you'd like to download the packages manually then you can use the --show-format
option.
debtool --show --show-format zsh
Will return the following:
apt-get download zsh=5.0.5-4ubuntu1~ubuntu14.04.1 -a=amd64
apt-get download zsh=5.0.2-3ubuntu6 -a=amd64
Download Debian Archives
You can download the most recent version of a package as follows:
debtool --download zsh
You can download a specific version as follows:
debtool --download zsh=5.0.2-3ubuntu6
Unpacking Packages
You can unpack a package on your hard drive:
debtool --unpack package.deb
You can also unpack a package that is currently installed on your system:
debtool --unpack package
If you have made changes to any of the installed files, they will be incorporated as well. This is perfect if you want to work with a package that is no longer available from sources or if you want to incorporate pre-existing fixes into a 'patched' deb.