aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2021-07-22 01:06:51 +0200
committerJakub Jirutka <jakub@jirutka.cz>2021-07-22 01:07:14 +0200
commit9851593f2ee11fe630ceb998f8853991a827d6aa (patch)
tree4b45b0633471824432f7349347ba40508249ee3d
parent8104da5316c92d16588c0f6b45e79ace07ea0ad0 (diff)
downloadaports-9851593f2ee11fe630ceb998f8853991a827d6aa.tar.gz
aports-9851593f2ee11fe630ceb998f8853991a827d6aa.tar.bz2
aports-9851593f2ee11fe630ceb998f8853991a827d6aa.tar.xz
testing/kernel-hooks: new aport
-rw-r--r--testing/kernel-hooks/APKBUILD20
-rw-r--r--testing/kernel-hooks/README13
-rw-r--r--testing/kernel-hooks/kernel-hooks.trigger51
3 files changed, 84 insertions, 0 deletions
diff --git a/testing/kernel-hooks/APKBUILD b/testing/kernel-hooks/APKBUILD
new file mode 100644
index 0000000000..2ff6c3a24a
--- /dev/null
+++ b/testing/kernel-hooks/APKBUILD
@@ -0,0 +1,20 @@
+# Contributor: Jakub Jirutka <jakub@jirutka.cz>
+# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
+pkgname=kernel-hooks
+pkgver=0.1
+pkgrel=0
+pkgdesc="Run user-provided hooks when /lib/modules/* is updated"
+url="https://gitlab.alpinelinux.org/alpine/aports/"
+arch="noarch"
+license="MIT"
+triggers="$pkgname.trigger=/lib/modules/*"
+source="README"
+options="!check" # no tests
+
+package() {
+ install -D -m644 "$srcdir"/README "$pkgdir"/etc/kernel-hooks.d/README
+}
+
+sha512sums="
+757a49dc238ce69210219ad7db9a6ebcd14d696d29d1e52dd57d8ce891aac5218aedbb95d1c73bb60f782d586c837ac100cd347b01c64116c41aa873ac7ff67d README
+"
diff --git a/testing/kernel-hooks/README b/testing/kernel-hooks/README
new file mode 100644
index 0000000000..4c908dbdde
--- /dev/null
+++ b/testing/kernel-hooks/README
@@ -0,0 +1,13 @@
+Executable scripts found in this directory are executed by the kernel-hooks
+package trigger after any kernel package or package providing kernel modules
+is (re)installed, upgraded or removed.
+
+Scripts are executed sequentially in alphabetic order with the following
+arguments: <kernel-flavor> <new-version> [<old-version>].
+
+<*-version> is a version of kernel package in the same format as in 'uname -r',
+without the flavor (e.g. 5.10.51-0).
+
+<new-version> is empty string if the kernel is removed.
+<old-version> is empty string if the kernel is (re)installed or any package
+providing modules for this kernel is installed, upgraded or removed.
diff --git a/testing/kernel-hooks/kernel-hooks.trigger b/testing/kernel-hooks/kernel-hooks.trigger
new file mode 100644
index 0000000000..d0ad1d11ef
--- /dev/null
+++ b/testing/kernel-hooks/kernel-hooks.trigger
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+PROGNAME='kernel-hooks'
+HOOKS_DIR='/etc/kernel-hooks.d'
+
+[ -d $HOOKS_DIR ] || exit 0
+
+flavors_vers=
+for path in "$@"; do
+ name="${path##*/}"
+
+ case "$name" in
+ [0-9]*-[0-9]*-*) ;; # go on
+ *) echo "$PROGNAME: ERROR: invalid kernel version: $name!" >&2; exit 1;;
+ esac
+
+ flavor=${name#*-}; flavor=${flavor#*-}
+ ver=${name%-$flavor}
+ flavors_vers="$flavors_vers $flavor:$ver"
+done
+
+ret=0
+for flavor in $(printf '%s\n' $flavors_vers | sort | cut -d: -f1 | uniq); do
+ relfile=/usr/share/kernel/$flavor/kernel.release
+
+ new_ver=
+ old_ver=
+ for fv in $flavors_vers; do
+ [ "${fv%:*}" = "$flavor" ] || continue
+ ver=${fv#*:}
+
+ [ "$(cat "$relfile" 2>/dev/null)" = "$ver-$flavor" ] \
+ && new_ver=$ver \
+ || old_ver=$ver
+ done
+
+ for hook in $HOOKS_DIR/*; do
+ [ -x "$hook" ] || continue
+ name=${hook##*/}
+
+ echo "$PROGNAME: executing hook $name ($flavor, $new_ver, $old_ver)" >&2
+
+ $hook "$flavor" "$new_ver" "$old_ver" && continue
+
+ echo "$PROGNAME: ERROR: hook $name failed, skipping hooks for linux-$flavor" >&2
+ ret=1
+ break
+ done
+done
+
+exit $ret