From 178fcea0f31b8bbf96b7bf3a637186c78f25f993 Mon Sep 17 00:00:00 2001 From: Debarshi Ray Date: Nov 23 2022 23:26:54 +0000 Subject: Fall back to /usr/lib/os-release when /etc/os-release is absent 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 https://pagure.io/fedora-autofirstboot/pull-request/4 --- diff --git a/libexec/fedora-autofirstboot/scripts.d/install-openh264.sh b/libexec/fedora-autofirstboot/scripts.d/install-openh264.sh index 00d8843..7ff166a 100644 --- a/libexec/fedora-autofirstboot/scripts.d/install-openh264.sh +++ b/libexec/fedora-autofirstboot/scripts.d/install-openh264.sh @@ -38,7 +38,10 @@ if [ -z "$NO_INSTALL_OPENH264" ] && [ -x "/usr/bin/rpm" ]; then 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} diff --git a/libexec/fedora-autofirstboot/scripts.d/remove-anaconda.sh b/libexec/fedora-autofirstboot/scripts.d/remove-anaconda.sh index c4abe0a..7eb119f 100644 --- a/libexec/fedora-autofirstboot/scripts.d/remove-anaconda.sh +++ b/libexec/fedora-autofirstboot/scripts.d/remove-anaconda.sh @@ -17,7 +17,10 @@ if [ -z "$NO_REMOVE_ANACONDA" ] && [ -x "/usr/bin/rpm" ]; then 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}