Customize Debian Rules
Now that we have a power-on package up and running, it's time to expand the packaging process to meet your desire needs. Reading back the guide, we do have a custom debian/rules
section for us to work on.
Golden Rules
Now there are some golden rules when it comes to customize the build process:
- NEVER blocks the default process. Works on top of it.
- ALWAYS build and test the package when the changes are minor.
- UNDERSTAND the build sequence. It's clearly stated in the guide under the Default Rules File sub-section.
- OVERRIDE only the necessary process.
Append The Override Keywords
Remember that debian/rules
is a Makefile, you should only append the "override_" keyword after the main debhelper commands. Example:
#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
%:
dh $@
override_dh_auto_build:
mv fennec.sh fennec
Here, I'm only overriding the dh_auto_build process because I need to rename a script into a program. You can override the correct sequences to run your own process.
Overriding dh_auto_build
It is very common to override build process since many software usually has its own build process. If you wish to override it, use override_dh_auto_build:
Makefile tag.
Then under it, execute your own build process. Example:
override_dh_auto_build:
mv fennec.sh fennec
make -j8
Overriding dh_installinit, dh_systemd_start, etc.
This is another common override for custom kick-starting a daemon-like software after installation.
You need to ensure that you install the service file inside the necessary daemon service provider, like systemd. Otherwise, it will fails. To install the service file, you should create the appropriate file inside your Debian directory:
debian/package.init
, which will install into/etc/init.d
.debian/package.default
, which will install into/etc/default/package
.
dh_installinit
will run the installation automatically. If you do not wish to start the service after the service installation, you'll need to override dh_installinit
stage:
override_dh_installinit:
dh_installinit --no-start --restart-on-upgrade
Read the man page for more arguments and flags.
If, for some reason, you need to execute a custom start for your daemon with a particular service provider, override the necessary process. Example, for systemd:
override_dh_systemd_start:
dh_systemd_start --restart-on-upgrade
If you wish to install multiple scripts, override_dh_installint
and dh_systemd_start
entirely and perform the installation and installation yourself. Here is an example from Ubuntu lxd:
override_dh_installinit:
# We handle starting and restarting things ourselves
dh_systemd_enable -plxd --name=lxd-bridge lxd-bridge.service
dh_systemd_enable -plxd --name=lxd-containers lxd-containers.service
dh_installinit -plxd --no-start
dh_installinit -plxd --name=lxd-bridge --no-start --noscripts
dh_installinit -plxd --name=lxd-containers --no-start --noscripts
dh_systemd_start -plxd lxd-containers.service --no-restart-on-upgrade
# Update arch-specific paths
sed -i "s#@LIBEXECDIR@#/usr/lib/${DEB_HOST_MULTIARCH}#g" debian/lxd/lib/systemd/system/lxd.service
sed -i "s#@LIBEXECDIR@#/usr/lib/${DEB_HOST_MULTIARCH}#g" debian/lxd/etc/init/lxd.conf
sed -i "s#@LIBEXECDIR@#/usr/lib/${DEB_HOST_MULTIARCH}#g" debian/lxd/etc/init.d/lxd
override_dh_systemd_start:
true
Here are some advanced examples:
Some Intended Overrides
Overriding for running custom commands
override_<process-block>:
dh_<process-block-before>
execute line 1
execute line 2
dh_<process-block-after>
...
Overriding for not running a process
override_<process-block>:
true
That's all about it. You should be able to build your full package easily with these custom rules. Keep in mind that with these customization, you will rarely need to use the maintainer scripts (pre/post install/rm). Hence, it simplifies your package testing.