Merge branch 'evilham-machine_type-explorer-simplify-linux-add-openbsd' into 'master'
[explorer/machine_type] simplify linux add openbsd See merge request ungleich-public/cdist!876
This commit is contained in:
commit
2362d89976
1 changed files with 61 additions and 55 deletions
|
@ -22,6 +22,18 @@
|
||||||
|
|
||||||
os=$("$__explorer/os")
|
os=$("$__explorer/os")
|
||||||
|
|
||||||
|
vendor_string_to_machine_type() {
|
||||||
|
for vendor in vmware bochs kvm qemu virtualbox bhyve; do
|
||||||
|
if echo "${1}" | grep -q -i "${vendor}"; then
|
||||||
|
if [ "${vendor}" = "bochs" ] || [ "${vendor}" = "qemu" ]; then
|
||||||
|
vendor="kvm"
|
||||||
|
fi
|
||||||
|
echo "virtual_by_${vendor}"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
case "$os" in
|
case "$os" in
|
||||||
"freebsd")
|
"freebsd")
|
||||||
# FreeBSD does not have /proc/cpuinfo even when procfs is used.
|
# FreeBSD does not have /proc/cpuinfo even when procfs is used.
|
||||||
|
@ -38,65 +50,59 @@ case "$os" in
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
"openbsd")
|
||||||
|
# OpenBSD can also use the sysctl's: hw.vendor or hw.product.
|
||||||
|
# Note we can be reasonably sure about a machine being virtualised
|
||||||
|
# as long as we can identify the virtualisation technology.
|
||||||
|
# But not so much about it being physical...
|
||||||
|
# Patches are welcome / reach out if you have better ideas.
|
||||||
|
for sysctl in hw.vendor hw.product; do
|
||||||
|
# This exits if we can make a reasonable judgement
|
||||||
|
vendor_string_to_machine_type "$(sysctl -n "${sysctl}")"
|
||||||
|
done
|
||||||
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
# Defaulting to linux for compatibility with previous cdist behaviour
|
# Defaulting to linux for compatibility with previous cdist behaviour
|
||||||
|
|
||||||
if [ -d "/proc/vz" ] && [ ! -d "/proc/bc" ]; then
|
if [ -d "/proc/vz" ] && [ ! -d "/proc/bc" ]; then
|
||||||
echo openvz
|
echo openvz
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -e "/proc/1/environ" ] &&
|
if [ -e "/proc/1/environ" ] &&
|
||||||
tr '\000' '\n' < "/proc/1/environ" | grep -Eiq '^container='; then
|
tr '\000' '\n' < "/proc/1/environ" | grep -Eiq '^container='; then
|
||||||
echo lxc
|
echo lxc
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -r /proc/cpuinfo ]; then
|
if [ -r /proc/cpuinfo ]; then
|
||||||
# this should only exist on virtual guest machines,
|
# this should only exist on virtual guest machines,
|
||||||
# tested on vmware, xen, kvm
|
# tested on vmware, xen, kvm, bhyve
|
||||||
if grep -q "hypervisor" /proc/cpuinfo; then
|
if grep -q "hypervisor" /proc/cpuinfo; then
|
||||||
# this file is aviable in xen guest systems
|
# this file is aviable in xen guest systems
|
||||||
if [ -r /sys/hypervisor/type ]; then
|
if [ -r /sys/hypervisor/type ]; then
|
||||||
if grep -q -i "xen" /sys/hypervisor/type; then
|
if grep -q -i "xen" /sys/hypervisor/type; then
|
||||||
echo virtual_by_xen
|
echo virtual_by_xen
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -r /sys/class/dmi/id/product_name ]; then
|
for vendor_file in /sys/class/dmi/id/product_name \
|
||||||
if grep -q -i 'vmware' /sys/class/dmi/id/product_name; then
|
/sys/class/dmi/id/sys_vendor \
|
||||||
echo "virtual_by_vmware"
|
/sys/class/dmi/id/chasis_vendor; do
|
||||||
exit
|
if [ -r ${vendor_file} ]; then
|
||||||
elif grep -q -i 'bochs' /sys/class/dmi/id/product_name; then
|
# This exits if we can make a reasonable judgement
|
||||||
echo "virtual_by_kvm"
|
vendor_string_to_machine_type "$(cat "${vendor_file}")"
|
||||||
exit
|
fi
|
||||||
elif grep -q -i 'virtualbox' /sys/class/dmi/id/product_name; then
|
done
|
||||||
echo "virtual_by_virtualbox"
|
fi
|
||||||
exit
|
echo "virtual_by_unknown"
|
||||||
fi
|
exit
|
||||||
fi
|
else
|
||||||
|
echo "physical"
|
||||||
if [ -r /sys/class/dmi/id/sys_vendor ]; then
|
exit
|
||||||
if grep -q -i 'qemu' /sys/class/dmi/id/sys_vendor; then
|
fi
|
||||||
echo "virtual_by_kvm"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -r /sys/class/dmi/id/chassis_vendor ]; then
|
|
||||||
if grep -q -i 'qemu' /sys/class/dmi/id/chassis_vendor; then
|
|
||||||
echo "virtual_by_kvm"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
echo "virtual_by_unknown"
|
|
||||||
exit
|
|
||||||
else
|
|
||||||
echo "physical"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue