Skip to content

Commit ac2c30f

Browse files
joschmasahir0y
authored andcommitted
kbuild: deb-pkg: allow hooks also in /usr/share/kernel
By passing an additional directory to run-parts, allow Debian and its derivatives to ship maintainer scripts in /usr while at the same time allowing the local admin to override or disable them by placing hooks of the same name in /etc. This adds support for the mechanism described in the UAPI Configuration Files Specification for kernel hooks. The same idea is also used by udev, systemd or modprobe for their config files. https://uapi-group.org/specifications/specs/configuration_files_specification/ This functionality relies on run-parts 5.21 or later. It is the responsibility of packages installing hooks into /usr/share/kernel to also declare a Depends: debianutils (>= 5.21). KDEB_HOOKDIR can be used to change the list of directories that is searched. By default, /etc/kernel and /usr/share/kernel are hook directories. Since the list of directories in KDEB_HOOKDIR is separated by spaces, the paths must not contain the space character themselves. Signed-off-by: Johannes Schauer Marin Rodrigues <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent d9ecb92 commit ac2c30f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

scripts/package/builddeb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
#
66
# Simple script to generate a deb package for a Linux kernel. All the
77
# complexity of what to do with a kernel after it is installed or removed
8-
# is left to other scripts and packages: they can install scripts in the
9-
# /etc/kernel/{pre,post}{inst,rm}.d/ directories (or an alternative location
10-
# specified in KDEB_HOOKDIR) that will be called on package install and
11-
# removal.
8+
# is left to other scripts and packages. Scripts can be placed into the
9+
# preinst, postinst, prerm and postrm directories in /etc/kernel or
10+
# /usr/share/kernel. A different list of search directories can be given
11+
# via KDEB_HOOKDIR. Scripts in directories earlier in the list will
12+
# override scripts of the same name in later directories. The script will
13+
# be called on package installation and removal.
1214

1315
set -eu
1416

@@ -74,7 +76,7 @@ install_maint_scripts () {
7476
# kernel packages, as well as kernel packages built using make-kpkg.
7577
# make-kpkg sets $INITRD to indicate whether an initramfs is wanted, and
7678
# so do we; recent versions of dracut and initramfs-tools will obey this.
77-
debhookdir=${KDEB_HOOKDIR:-/etc/kernel}
79+
debhookdir=${KDEB_HOOKDIR:-/etc/kernel /usr/share/kernel}
7880
for script in postinst postrm preinst prerm; do
7981
mkdir -p "${pdir}/DEBIAN"
8082
cat <<-EOF > "${pdir}/DEBIAN/${script}"
@@ -88,7 +90,15 @@ install_maint_scripts () {
8890
# Tell initramfs builder whether it's wanted
8991
export INITRD=$(if_enabled_echo CONFIG_BLK_DEV_INITRD Yes No)
9092
91-
test -d ${debhookdir}/${script}.d && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" ${debhookdir}/${script}.d
93+
# run-parts will error out if one of its directory arguments does not
94+
# exist, so filter the list of hook directories accordingly.
95+
hookdirs=
96+
for dir in ${debhookdir}; do
97+
test -d "\$dir/${script}.d" || continue
98+
hookdirs="\$hookdirs \$dir/${script}.d"
99+
done
100+
hookdirs="\${hookdirs# }"
101+
test -n "\$hookdirs" && run-parts --arg="${KERNELRELEASE}" --arg="/${installed_image_path}" \$hookdirs
92102
exit 0
93103
EOF
94104
chmod 755 "${pdir}/DEBIAN/${script}"

0 commit comments

Comments
 (0)