core: 改善 vm 检测

This commit is contained in:
bin456789 2023-07-08 17:10:30 +08:00
parent 9dfc148295
commit 69f2bd2e58
No known key found for this signature in database
GPG Key ID: EE301B386DE6C11B

View File

@ -102,12 +102,16 @@ is_virt() {
done done
wmic /namespace:'\\root\cimv2' PATH Win32_Fan | head -1 | grep -q -v Name wmic /namespace:'\\root\cimv2' PATH Win32_Fan | head -1 | grep -q -v Name
else else
if command -v systemd-detect-virt; then # aws t4g debian 11 systemd-detect-virt 为 none即使装了dmidecode
systemd-detect-virt # virt-what: 未装 deidecode时结果为空装了deidecode后结果为aws
else # 所以综合两个命令的结果来判断
install_pkg virt-what if command -v systemd-detect-virt && systemd-detect-virt; then
virt-what return 0
fi fi
# debian 安装 virt-what 不会自动安装 dmidecode因此结果有误
install_pkg dmidecode virt-what
# virt-what 返回值始终是0所以用是否有输出作为判断
[ -n "$(virt-what)" ]
fi fi
} }