test/system: Fix reading the os-release(5) VERSION_ID on Ubuntu

The current approach of extracting the VERSION_ID field from
os-release(5) assumes that the value is not quoted.  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"
  ...

This means that "22.04", including the double quotes, is read as the
value of VERSION_ID on Ubuntu, not 22.04.  This is wrong because this
value can't be used as is in image and container names.  There's no
image called quay.io/toolbx/ubuntu-toolbox:"22.04" and double quotes are
not allowed in container names.

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

Fallout from b27795a03e

https://github.com/containers/toolbox/pull/1320
This commit is contained in:
Debarshi Ray 2023-06-23 12:47:05 +02:00
parent 62c31ca8ea
commit 4322824061

View file

@ -510,7 +510,7 @@ function get_system_id() (
# Returns the content of field VERSION_ID in os-release
function get_system_version() {
function get_system_version() (
local os_release
os_release="$(find_os_release)"
@ -520,8 +520,9 @@ function get_system_version() {
return
fi
echo $(awk -F= '/VERSION_ID/ {print $2}' $os_release | head -n 1)
}
. "$os_release"
echo "$VERSION_ID"
)
# Set up the XDG_RUNTIME_DIR variable if not set