feat(darwin): add get_nproc() to support Linux and Darwin

This commit is contained in:
Martin Wimpress 2024-05-14 14:52:36 +01:00 committed by Martin Wimpress
parent 37c89a62f6
commit 5515a9e7d7
1 changed files with 13 additions and 1 deletions

View File

@ -205,6 +205,18 @@ function configure_usb() {
fi
}
# get the number of processing units
function get_nproc() {
if command -v nproc &>/dev/null; then
nproc
elif command -v sysctl &>/dev/null; then
sysctl -n hw.ncpu
else
echo "ERROR! Unable to determine the number of processing units."
exit 1
fi
}
# macOS and Linux compatible get_cpu_info function
function get_cpu_info() {
local INFO_NAME="${1}"
@ -255,7 +267,7 @@ function efi_vars() {
}
function configure_cpu() {
HOST_CPU_CORES=$(nproc)
HOST_CPU_CORES=$(get_nproc)
HOST_CPU_MODEL=$(get_cpu_info '^Model name:')
HOST_CPU_SOCKETS=$(get_cpu_info 'Socket')
HOST_CPU_VENDOR=$(get_cpu_info 'Vendor')