From 387ea927ac300a65fa4774fd12ae86f5b685ee95 Mon Sep 17 00:00:00 2001 From: Ralph Sennhauser Date: Fri, 28 Mar 2025 20:19:03 +0100 Subject: [PATCH] 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 --- .shellcheckrc | 2 ++ source/tools/utils.sh | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .shellcheckrc create mode 100755 source/tools/utils.sh diff --git a/.shellcheckrc b/.shellcheckrc new file mode 100644 index 0000000000..2cb6717b2f --- /dev/null +++ b/.shellcheckrc @@ -0,0 +1,2 @@ +external-sources=true +source-path=source/tools diff --git a/source/tools/utils.sh b/source/tools/utils.sh new file mode 100755 index 0000000000..5680d82190 --- /dev/null +++ b/source/tools/utils.sh @@ -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 +}