Skip to content

Instantly share code, notes, and snippets.

@simonbru
Created February 23, 2016 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simonbru/f1bfddeedc3429a04e62 to your computer and use it in GitHub Desktop.
Save simonbru/f1bfddeedc3429a04e62 to your computer and use it in GitHub Desktop.
ALPM (pacman) hook compiling dkms modules when necessary
#!/bin/bash
list_installed_kernels() {
for i in /usr/lib/modules/*/build/Kconfig; do
sed -rn 's#/usr/lib/modules/(.*)/build/Kconfig#\1#p' <<< "$i"
done
}
build_all_modules() {
while read kernel; do
dkms autoinstall -k "$kernel"
done
}
# Building missing modules for all installed kernels
list_installed_kernels | build_all_modules
[Unit]
Description=Load DKMS modules
[Service]
Type=oneshot
RemainAfterExit=yes
#ExecStart=/bin/sh -c 'for i in $(find /var/lib/dkms -iname "*.ko" | grep $(uname -r)); do m="$(basename "$i")"; modprobe -b "${m%.*}"; done'
ExecStart=/bin/sh -c 'for i in $$(find /var/lib/dkms -iname "*.ko" | grep $$(uname -r)); do m="$$(basename "$i")"; modprobe -b "$${m%.*}"; done'
ExecStop=/usr/lib/systemd/scripts/dkms stop
[Install]
WantedBy=multi-user.target
[Trigger]
Operation = Install
Operation = Upgrade
Type = File
Target = usr/src/*
Target = usr/lib/modules/*
[Action]
Description = Building missing modules for all installed kernels
When = PostTransaction
Exec = /etc/pacman.d/hooks.bin/dkms
Depends = dkms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment