#4 Fall back to /usr/lib/os-release when /etc/os-release is absent
Merged a year ago by ngompa. Opened a year ago by rishi.
rishi/fedora-autofirstboot wip/rishi/os-release-priority  into  main

@@ -38,7 +38,10 @@ 

      if ! rpm --quiet --query "${OPENH264_PACKAGES}"; then

          (

              # Check the OS to ensure we're not RHEL-like

-             source /etc/os-release

+             if ! source /etc/os-release; then

+                 source /usr/lib/os-release

+             fi

+ 

              if [[ "$ID" != "rhel" ]] && [[ "$ID_LIKE" != *"rhel"* ]]; then

                  if [ ! -e "/run/ostree-booted" ] && [ -x "/usr/bin/pkcon" ]; then

                         pkcon --noninteractive install ${OPENH264_PACKAGES}

@@ -17,7 +17,10 @@ 

      if rpm --quiet --query gnome-initial-setup || rpm --quiet --query pico-wizard; then

          (

              # Check the OS to ensure we're not RHEL-like

-             source /etc/os-release

+             if ! source /etc/os-release; then

+                 source /usr/lib/os-release

+             fi

+ 

              if [[ "$ID" != "rhel" ]] && [[ "$ID_LIKE" != *"rhel"* ]]; then

                  if [ ! -e "/run/ostree-booted" ] && [ -x "/usr/bin/pkcon" ]; then

                         pkcon --noninteractive --autoremove remove ${ANACONDA_PACKAGES}

It's not mandatory for /etc/os-release to be present. The os-release(5) manual says [1]:

The file /etc/os-release takes precedence over /usr/lib/os-release.
Applications should check for the former, and exclusively use its data
if it exists, and only fall back to /usr/lib/os-release if it is
missing.

A valid os-release(5) file is not expected to have any commands in it. Hence, there's no chance of a non-zero exit code from the last command inside /etc/os-release getting forwarded as the exit code of the attempt to source it [2], and getting misinterpreted as the file being absent. The /etc/os-release file is owned by root. It's assumed that the root user knows what they are doing and has put in place a sane file.

[1] https://www.freedesktop.org/software/systemd/man/os-release.html

[2] https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html

In what world is /etc/os-release missing?

In what world is /etc/os-release missing?

I am struggling to understand how serious or genuine your question is.

A smart answer could be: a world imagined by the os-release(5) manual.

A more thoughtful answer would point out that for the last several years there has been an general rethink about how Linux operating systems are put together. Silverblue and CoreOS are examples of that. Most relevant to this pull request are the ideas around factory reset and stateless systems that are loosely about an OS relying a lot less on the persistence of /etc, and instead relying mostly on a self-sufficient and possibly read-only /usr.

Anyway, I am not very attached to this pull request. I was fixing os-release(5) handling in a different code base when I saw fedora-autofirstboot fly-by in my email. I took a look to distract myself and ended up finding this. :)

Pull-Request has been merged by ngompa

a year ago

I legitimately didn't know if anything doing it that way. Merged.

Thanks, @ngompa !

I legitimately didn't know if anything doing it that way. Merged.

I recently learned that Endless OS doesn't have /usr/lib/os-release. :O