[Libguestfs] [PATCH] p2v: make-disk: rely on os-release for host distro detection

Pino Toscano ptoscano at redhat.com
Tue Nov 6 12:33:11 UTC 2018


Instead of assuming the latest Fedora version if /etc/redhat-release is
available, or the latest Debian with /etc/debian_version, use only
/etc/os-release.  The possible name of the virt-builder template is
created by concatenating $ID and $VERSION_ID, which is generally a
better guess than what previously done, and better matches the host OS.

This affects only the case when os-version is not specified as command
line argument.
---
 p2v/virt-p2v-make-disk.in | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/p2v/virt-p2v-make-disk.in b/p2v/virt-p2v-make-disk.in
index bdf7fd96e..ee65716f2 100644
--- a/p2v/virt-p2v-make-disk.in
+++ b/p2v/virt-p2v-make-disk.in
@@ -122,12 +122,8 @@ if [ $# -eq 1 ]; then
 else
     # If osversion was not set, then we must guess a good value
     # based on the host distro.
-    if test -f /etc/redhat-release; then
-        osversion="$(virt-builder -l | sort |
-                       @AWK@ '/^fedora-[1-9]/ {print $1}' | tail -1)"
-    elif test -f /etc/debian_version; then
-        osversion="$(virt-builder -l | sort |
-                       @AWK@ '/^debian-[1-9]/ {print $1}' | tail -1)"
+    if test -f /etc/os-release; then
+        osversion="`. /etc/os-release && echo ${ID}-${VERSION_ID}`"
     fi
     if [ "x$osversion" = "x" ]; then
         echo "$program: unable to guess a suitable os-version."
-- 
2.17.2




More information about the Libguestfs mailing list