danboid / ALEZ

Arch Linux Easy ZFS installer
GNU General Public License v3.0
145 stars 25 forks source link

Install kernel from archive if un-sync'd #23

Closed johnramsden closed 5 years ago

johnramsden commented 5 years ago

Summary

When a newer kernel has been released but the zfs packages have not yet been released at the same version, fetch the correct kernel matching the zfs package from the Arch Linux archive.

This should fix failures that occur when the ZFS packages are not yet caught up to the kernel.

Explanation

In order to get the matching kernel, request info on the zfs package used:

pacman -S --info zfs-linux|grep "Depends On"
Depends On      : kmod  spl-linux  zfs-utils=0.7.12  linux=4.20.13.arch1-1

Get the linux version from linux= with:

grep -oP '(?<=\blinux\="')(.*)+(?=\b)' <(pacman -S --info zfs-linux|grep "Depends On")

We then compare the actual linux version, and if it is not the same as the one we found above we download from the archive.

In practice we use a few functions for readability:

pkg_ver() {
    grep -oP "${1}" <(pacman -Ss '^'"${2}"'$' | grep -P "${2}"'\s')
}

depend_ver() {
    grep -oP '(?<=\b'"${1}\="')(.*)+(?=\b)' <(pacman -S --info "${2}" | grep "Depends On")
}

And then get the version using:

zfs_depend_ver="$(depend_ver "linux${kern_suffix}" "zfs-linux${kern_suffix}")"
kernel_version="$(pkg_ver '(?<=\s)[[:digit:]].*?(?=($|\s))' "linux${kern_suffix}")"

Tests Ran

danboid commented 5 years ago

Great stuff! This should make ALEZ much less of a hit and miss affair. Thanks John!