virt-what.in: warn about missing cpuid-virt helper program
[virt-what.git] / virt-what.in
index fb399be..5ae1ccb 100644 (file)
@@ -1,4 +1,4 @@
-#!/bin/bash -
+#!/bin/sh -
 # @configure_input@
 # Copyright (C) 2008-2011 Red Hat Inc.
 #
@@ -33,12 +33,12 @@ skip_qemu_kvm=false
 
 VERSION="@VERSION@"
 
-function fail {
+fail() {
     echo "virt-what: $1" >&2
     exit 1
 }
 
-function usage {
+usage() {
     echo "virt-what [options]"
     echo "Options:"
     echo "  --help          Display this help"
@@ -74,11 +74,18 @@ exec_prefix=@exec_prefix@
 PATH="${root}@libexecdir@:${root}/sbin:${root}/usr/sbin:${PATH}"
 
 # Check we're running as root.
+EFFUID=$(id -u) || fail "failed to get current user id"
 
-if [ "x$root" = "x" ] && [ "$EUID" -ne 0 ]; then
+if [ "x$root" = "x" ] && [ "$EFFUID" -ne 0 ]; then
     fail "this script must be run as root"
 fi
 
+# Try to locate the CPU-ID helper program
+CPUID_HELPER=$(which virt-what-cpuid-helper 2>/dev/null)
+if [ -z "$CPUID_HELPER" ] ; then
+    fail "virt-what-cpuid-helper program not found in \$PATH"
+fi
+
 # Many fullvirt hypervisors give an indication through CPUID.  Use the
 # helper program to get this information.
 
@@ -248,3 +255,8 @@ if ! "$skip_qemu_kvm"; then
        fi
     fi
 fi
+
+# Check for Docker.
+if [ -f "${root}/.dockerinit" ]; then
+       echo docker
+fi