Blame 0024-qemu-module-setup.sh-provide-alternative-for-systemd.patch

Harald Hoyer 12f6cc
From f1040fc4702778b38e6cc9eaf5b4c1ff24a7c26c Mon Sep 17 00:00:00 2001
Harald Hoyer 12f6cc
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 12f6cc
Date: Wed, 25 Jul 2012 16:03:49 +0200
Harald Hoyer 12f6cc
Subject: [PATCH] qemu*/module-setup.sh: provide alternative for
Harald Hoyer 12f6cc
 systemd-detect-virt
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
---
Harald Hoyer 12f6cc
 modules.d/90qemu-net/module-setup.sh | 19 +++++++++++++++----
Harald Hoyer 12f6cc
 modules.d/90qemu/module-setup.sh     | 18 ++++++++++++++----
Harald Hoyer 12f6cc
 2 files changed, 29 insertions(+), 8 deletions(-)
Harald Hoyer 12f6cc
Harald Hoyer 12f6cc
diff --git a/modules.d/90qemu-net/module-setup.sh b/modules.d/90qemu-net/module-setup.sh
Harald Hoyer 12f6cc
index 35c8f0f..e617230 100755
Harald Hoyer 12f6cc
--- a/modules.d/90qemu-net/module-setup.sh
Harald Hoyer 12f6cc
+++ b/modules.d/90qemu-net/module-setup.sh
Harald Hoyer 12f6cc
@@ -3,10 +3,21 @@
Harald Hoyer 12f6cc
 # ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
 check() {
Harald Hoyer 12f6cc
-    vm=$(systemd-detect-virt --vm &>/dev/null)
Harald Hoyer 12f6cc
-    (($? != 0)) && return 255
Harald Hoyer 12f6cc
-    [[ $vm = "qemu" ]] && return 0
Harald Hoyer 12f6cc
-    [[ $vm = "kvm" ]] && return 0
Harald Hoyer 12f6cc
+    if type -P systemd-detect-virt &>/dev/null; then
Harald Hoyer 12f6cc
+        vm=$(systemd-detect-virt --vm &>/dev/null)
Harald Hoyer 12f6cc
+        (($? != 0)) && return 255
Harald Hoyer 12f6cc
+        [[ $vm = "qemu" ]] && return 0
Harald Hoyer 12f6cc
+        [[ $vm = "kvm" ]] && return 0
Harald Hoyer 12f6cc
+        [[ $vm = "bochs" ]] && return 0
Harald Hoyer 12f6cc
+    fi
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    for i in /sys/class/dmi/id/*_vendor; do
Harald Hoyer 12f6cc
+        [[ -f $i ]] || continue
Harald Hoyer 12f6cc
+        read vendor < $i
Harald Hoyer 12f6cc
+        [[  "$vendor" == "QEMU" ]] && return 0
Harald Hoyer 12f6cc
+        [[  "$vendor" == "Bochs" ]] && return 0
Harald Hoyer 12f6cc
+    done
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
     return 255
Harald Hoyer 12f6cc
 }
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
diff --git a/modules.d/90qemu/module-setup.sh b/modules.d/90qemu/module-setup.sh
Harald Hoyer 12f6cc
index 3e55f23..fc258ac 100755
Harald Hoyer 12f6cc
--- a/modules.d/90qemu/module-setup.sh
Harald Hoyer 12f6cc
+++ b/modules.d/90qemu/module-setup.sh
Harald Hoyer 12f6cc
@@ -3,10 +3,20 @@
Harald Hoyer 12f6cc
 # ex: ts=8 sw=4 sts=4 et filetype=sh
Harald Hoyer 12f6cc
 
Harald Hoyer 12f6cc
 check() {
Harald Hoyer 12f6cc
-    vm=$(systemd-detect-virt --vm &>/dev/null)
Harald Hoyer 12f6cc
-    (($? != 0)) && return 255
Harald Hoyer 12f6cc
-    [[ $vm = "qemu" ]] && return 0
Harald Hoyer 12f6cc
-    [[ $vm = "kvm" ]] && return 0
Harald Hoyer 12f6cc
+    if type -P systemd-detect-virt &>/dev/null; then
Harald Hoyer 12f6cc
+        vm=$(systemd-detect-virt --vm &>/dev/null)
Harald Hoyer 12f6cc
+        (($? != 0)) && return 255
Harald Hoyer 12f6cc
+        [[ $vm = "qemu" ]] && return 0
Harald Hoyer 12f6cc
+        [[ $vm = "kvm" ]] && return 0
Harald Hoyer 12f6cc
+        [[ $vm = "bochs" ]] && return 0
Harald Hoyer 12f6cc
+    fi
Harald Hoyer 12f6cc
+
Harald Hoyer 12f6cc
+    for i in /sys/class/dmi/id/*_vendor; do
Harald Hoyer 12f6cc
+        [[ -f $i ]] || continue
Harald Hoyer 12f6cc
+        read vendor < $i
Harald Hoyer 12f6cc
+        [[  "$vendor" == "QEMU" ]] && return 0
Harald Hoyer 12f6cc
+        [[  "$vendor" == "Bochs" ]] && return 0
Harald Hoyer 12f6cc
+    done
Harald Hoyer 12f6cc
     return 255
Harald Hoyer 12f6cc
 }
Harald Hoyer 12f6cc