]> code.delx.au - monosys/blob - clean-dkms
Fixed clean-dkms to do module versions properly
[monosys] / clean-dkms
1 #!/bin/bash
2
3 architecture="x86_64"
4 linux_packages="linux linux-lts"
5
6 echo "# Running: $(uname -r)"
7 for linux in $linux_packages; do
8 echo "# Installed: $(pacman -Q "$linux")"
9 done
10
11 echo
12 find /var/lib/dkms/ -maxdepth 2 -type l -name 'kernel-*' | while read line; do
13 module_name="$(echo "$line" | cut -d/ -f5)"
14 package_name="${module_name}-dkms"
15 module_version="$(pacman -Q "${package_name}" | cut -d' ' -f2 | cut -d'-' -f1)"
16 long_kernel_version="$(echo "$line" | cut -d/ -f6)"
17 kernel_version="$(echo "$long_kernel_version" | sed -e 's/^kernel-//' -e "s/-${architecture}\$//")"
18 if [ "$kernel_version" = "$(uname -r)" ]; then
19 continue
20 fi
21 echo dkms remove -m "$module_name" -v "$module_version" -k "$kernel_version"
22 done
23
24 echo
25 find /lib/modules/ -maxdepth 1 -type d -name '[0-9]*' | while read line; do
26 if pacman -Qo "$line" &> /dev/null; then
27 continue
28 fi
29 echo rm -rf "$line"
30 done
31