Fix #1151 check if bc command is available (#1201)

On some systems the `bc` command is not installed, so I added a check if the command can be used.

It is a simply calculation from KB to GB.  If `bc` is missing, then it is displayed in KB.

fix: #1151
This commit is contained in:
Falke Design 2021-09-01 15:13:35 +02:00 committed by GitHub
parent d205f4a433
commit 87a37da243
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -130,9 +130,15 @@ if [[ "$OSTYPE" == "linux-gnu" ]]; then
echo "ERR: Sorry this is working only on x86_64!" echo "ERR: Sorry this is working only on x86_64!"
exit 1 exit 1
fi fi
echo " : --- Memory, CPU info ---- " echo " : --- Memory, CPU info ---- "
mem=$( grep MemTotal /proc/meminfo | awk '{print $2}' | xargs -I {} echo "scale=4; {}/1024^2" | bc ) if [ -n "$(command -v bc)" ]; then
echo "System memory (GB): ${mem}" mem=$( grep MemTotal /proc/meminfo | awk '{print $2}' | xargs -I {} echo "scale=4; {}/1024^2" | bc )
echo "System memory (GB): ${mem}"
else
mem=$( grep MemTotal /proc/meminfo | awk '{print $2}')
echo "System memory (KB): ${mem}"
fi
grep SwapTotal /proc/meminfo grep SwapTotal /proc/meminfo
echo "CPU number: $(grep -c processor /proc/cpuinfo) x $(grep "bogomips" /proc/cpuinfo | head -1)" echo "CPU number: $(grep -c processor /proc/cpuinfo) x $(grep "bogomips" /proc/cpuinfo | head -1)"
grep Free /proc/meminfo grep Free /proc/meminfo