Commit 9851593f authored by Jakub Jirutka's avatar Jakub Jirutka
Browse files

testing/kernel-hooks: new aport

parent 8104da53
# 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
"
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.
#!/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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment