[Libguestfs] [PATCH libguestfs] build: When parsing distro from /etc/os-release, try $ID_LIKE first

Richard W.M. Jones rjones at redhat.com
Sun May 22 17:41:14 UTC 2022


The current code for working out the distro uses the ID entry from
/etc/os-release, and then we map those strings into a smaller set of
values (basically, what package manager to use).  However it was
suggested that we should try ID_LIKE first so that distros which act
like other distros would work.  On an Arch Linux 32 system:

ID=arch32
ID_LIKE=arch

See-also: https://github.com/libguestfs/libguestfs/issues/81
Thanks: S D Rausty
---
 m4/guestfs-appliance.m4 | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/m4/guestfs-appliance.m4 b/m4/guestfs-appliance.m4
index 9e443f151d..4e63ef4356 100644
--- a/m4/guestfs-appliance.m4
+++ b/m4/guestfs-appliance.m4
@@ -102,8 +102,16 @@ AC_ARG_WITH([distro],
         AC_MSG_RESULT([$DISTRO (manually specified)])
     ],[
         if test -f /etc/os-release; then
-            ( . /etc/os-release && echo $ID | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@' ) >&AS_MESSAGE_LOG_FD
-            DISTRO="`. /etc/os-release && echo $ID | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@'`"
+            echo "/etc/os-release:" >&AS_MESSAGE_LOG_FD
+            cat /etc/os-release >&AS_MESSAGE_LOG_FD
+            DISTRO="$(
+                . /etc/os-release
+                if test -n "$ID_LIKE"; then
+                    echo $ID_LIKE | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@'
+                else
+                    echo $ID      | tr '@<:@:lower:@:>@' '@<:@:upper:@:>@'
+                fi
+            )"
             AS_CASE([$DISTRO],
                     [FEDORA | RHEL | CENTOS | ALMALINUX | CLOUDLINUX | ROCKY],
                         [DISTRO=REDHAT],
@@ -116,6 +124,7 @@ AC_ARG_WITH([distro],
         fi
     ]
 )
+AC_SUBST([DISTRO])
 AM_CONDITIONAL([HAVE_RPM],
     [AS_CASE([$DISTRO], [REDHAT | SUSE | OPENMANDRIVA | MAGEIA ], [true],
                         [*], [false])])
@@ -125,7 +134,6 @@ AM_CONDITIONAL([HAVE_DPKG],
 AM_CONDITIONAL([HAVE_PACMAN],
     [AS_CASE([$DISTRO], [ARCHLINUX | FRUGALWARE | ARTIX], [true],
                         [*], [false])])
-AC_SUBST([DISTRO])
 
 dnl Add extra packages to the appliance.
 AC_ARG_WITH([extra-packages],
-- 
2.35.1



More information about the Libguestfs mailing list