Add util.sh shell library

A shell utilities function library starting with a first utility
function for getting the number of online CPUs.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2025-03-28 20:19:03 +01:00
parent 2d206708cd
commit 387ea927ac
No known key found for this signature in database
2 changed files with 15 additions and 0 deletions

2
.shellcheckrc Normal file
View file

@ -0,0 +1,2 @@
external-sources=true
source-path=source/tools

13
source/tools/utils.sh Executable file
View file

@ -0,0 +1,13 @@
#!/bin/sh
# Collection of sh utilities
# Return number of online cpu or 1 if it can't be determined.
utils_num_online_cpu()
{
getconf _NPROCESSORS_ONLN 2>/dev/null && return
getconf NPROCESSORS_ONLN 2>/dev/null && return
nproc 2>/dev/null && return
sysctl -m hw.nproc 2>/dev/null && return
echo 1
}