Skip to content

Fix Linux distribution identification through /etc/os-release#179

Merged
scaronni merged 1 commit intodkms-project:masterfrom
fishilico:fix-os-release-parsing
Nov 17, 2021
Merged

Fix Linux distribution identification through /etc/os-release#179
scaronni merged 1 commit intodkms-project:masterfrom
fishilico:fix-os-release-parsing

Conversation

@fishilico
Copy link
Contributor

On Linux distributions such as Arch Linux, /etc/os-release contains:

NAME="Arch Linux"
PRETTY_NAME="Arch Linux"
ID=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL="https://archlinux.org/"
DOCUMENTATION_URL="https://wiki.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"
LOGO=archlinux-logo

There is no ID_LIKE property, so ${#ID_LIKE[@]} is zero:

$ . /etc/os-release
$ echo ${#ID_LIKE[@]}
0

As 0 is not empty, [[ ${#ID_LIKE[@]} ]] is true:

$ [[ ${#ID_LIKE[@]} ]] ; echo $?
0

So in dkms, the function distro_version returns an empty string in

[[ ${#ID_LIKE[@]} ]] && echo ${ID_LIKE[0]} || echo $ID

Fix this by replacing [[ ${#ID_LIKE[@]} ]] with [[ ${#ID_LIKE[@]} != 0]].

Fixes: f0b11ce ("dkms: rework distribution detection")

On Linux distributions such as Arch Linux, /etc/os-release contains:

    NAME="Arch Linux"
    PRETTY_NAME="Arch Linux"
    ID=arch
    BUILD_ID=rolling
    ANSI_COLOR="38;2;23;147;209"
    HOME_URL="https://archlinux.org/"
    DOCUMENTATION_URL="https://wiki.archlinux.org/"
    SUPPORT_URL="https://bbs.archlinux.org/"
    BUG_REPORT_URL="https://bugs.archlinux.org/"
    LOGO=archlinux-logo

There is no `ID_LIKE` property, so `${#ID_LIKE[@]}` is zero:

    $ . /etc/os-release
    $ echo ${#ID_LIKE[@]}
    0

As `0` is not empty, `[[ ${#ID_LIKE[@]} ]]` is true:

    $ [[ ${#ID_LIKE[@]} ]] ; echo $?
    0

So in `dkms`, the function `distro_version` returns an empty string in

    [[ ${#ID_LIKE[@]} ]] && echo ${ID_LIKE[0]} || echo $ID

Fix this by replacing `[[ ${#ID_LIKE[@]} ]]` with `[[ ${#ID_LIKE[@]} != 0]]`.

Fixes: f0b11ce ("dkms: rework distribution detection")
@scaronni scaronni merged commit 280da46 into dkms-project:master Nov 17, 2021
@fishilico fishilico deleted the fix-os-release-parsing branch November 17, 2021 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants