1
  #   Aˆl–Ým_J*n-jm@†ãO\JbÑ¿Ê„€yŸÀÍ >Ó    A#!/usr/bin/sh -
# virt-what.  Generated from virt-what.in by configure.
# Copyright (C) 2008-2024 Red Hat Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

# 'virt-what' tries to detect the type of virtualization being
# used (or none at all if we're running on bare-metal).  It prints
# out one or more lines each being a 'fact' about the virtualization.
#
# Please see also the manual page virt-what(1).
# This script should be run as root.
#
# The following resources were useful in writing this script:
# . http://dmo.ca/blog/detecting-virtualization-on-linux/

# Do not allow unset variables, and set defaults.
set -u
root=''
skip_qemu_kvm=false
skip_lkvm=false

VERSION="1.27"

have_cpuinfo () {
    test -e "${root}/proc/cpuinfo"
}

use_sysctl() {
    # Lacking /proc, on some systems sysctl can be used instead.
    OS=$(uname) || fail "failed to get operating system name"

    [ "$OS" = "OpenBSD" ]
}

fail () {
    echo "virt-what: $1" >&2
    exit 1
}

usage () {
    echo "virt-what [options]"
    echo "Options:"
    echo "  --help          Display this help"
    echo "  --version       Display version and exit"
    exit 0
}

# Handle the command line arguments, if any.
while test $# -gt 0; do
    case "$1" in
        --help) usage ;;
        --test-root=*)
            # Deliberately undocumented: used for 'make check'.
            root=$(echo "$1" | sed 's/.*=//')
            shift 1
            test -z "$root" && fail "--test-root option requires a value"
            ;;
        -v|--version) echo "$VERSION"; exit 0 ;;
        --) shift; break ;;
        *) fail "unrecognized option '$1'";;
    esac
done
test $# -gt 0 && fail "extra operand '$1'"

# Add /sbin and /usr/sbin to the path so we can find system
# binaries like dmidecode.
# Add /usr/libexec to the path so we can find the helper binary.
prefix=/usr
exec_prefix=/usr
PATH="${root}/usr/libexec:${root}/sbin:${root}/usr/sbin:${PATH}"
export PATH

# Check we're running as root.
EFFUID=$(id -u) || fail "failed to get current user id"

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.

cpuid=$(virt-what-cpuid-helper)

# Check for various products in the BIOS information.
# Note that dmidecode doesn't exist on all architectures.  On the ones
# it does not, then this will return an error, which is ignored (error
# message redirected into the $dmi variable).

dmi=$(LANG=C dmidecode 2>&1)

# Architecture.
# Note for the purpose of testing, we only call uname with -m option
# (except WSL2 which is weird).

arch=$(uname -m | sed -e 's/i.86/i386/' | sed -e 's/arm.*/arm/')

# Check for Alibaba Cloud
if echo "$dmi" | grep -q 'Manufacturer: Alibaba'; then
    if $(timeout --version >/dev/null 2>&1); then
        timeout_cmd_prefix="timeout 1s"
        timeout_cmp="-eq"
        timeout_return_value=124
    else
        timeout_cmd_prefix=""
        timeout_cmp="-ne"
        timeout_return_value=0
    fi

    # Check for Alibaba Cloud ECS Bare Metal (EBM) Instance
    metadata=$($timeout_cmd_prefix sh -c '( { echo -e "GET /latest/meta-datainstanc