Skip to content

Commit

Permalink
test/system: Fix reading the os-release(5) ID on Ubuntu
Browse files Browse the repository at this point in the history
The current approach of selecting all the os-release(5) fields that have
'ID' in their name (eg., ID, VERSION_ID, PLATFORM_ID, VARIANT_ID, etc.)
and then picking the first one, assumes that the ID field will always be
placed above the others in os-release(5).  There's no guarantee that
this will be the case.  It only happens to be so on Fedora by chance,
and is different on Ubuntu:
  $ cat /etc/os-release
  ...
  VERSION_ID="22.04"
  ...
  ID=ubuntu
  ID_LIKE=debian
  ...

This means that "22.04" is read as the value of ID on Ubuntu, which is
clearly wrong.

Instead, use the same approach as profile.d/toolbox.sh and the old POSIX
shell implementation that doesn't rely on the order of the os-release(5)
fields.

Fallout from 54a2ca1

containers#1320
  • Loading branch information
debarshiray committed Jun 23, 2023
1 parent b57dfd8 commit 62c31ca
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/system/libs/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ function find_os_release() {


# Returns the content of field ID in os-release
function get_system_id() {
function get_system_id() (
local os_release

os_release="$(find_os_release)"
Expand All @@ -504,8 +504,9 @@ function get_system_id() {
return
fi

echo $(awk -F= '/ID/ {print $2}' $os_release | head -n 1)
}
. "$os_release"
echo "$ID"
)


# Returns the content of field VERSION_ID in os-release
Expand Down

0 comments on commit 62c31ca

Please sign in to comment.