From da1dab956f8796eaa08ae36481d11bc10f12daf5 Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 3 May 2024 11:01:14 +0200 Subject: [PATCH] feat: Check the RAM amount available (#53) --- src/config.sh | 16 ++++++++++++++++ src/reset.sh | 8 ++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/config.sh b/src/config.sh index 91c4529..88e9115 100644 --- a/src/config.sh +++ b/src/config.sh @@ -32,4 +32,20 @@ else fi fi +# Check available memory as the very last step + +RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}') +RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}') +AVAIL_GB=$(( (RAM_AVAIL + 1073741823)/1073741824 )) +TOTAL_GB=$(( (RAM_TOTAL + 1073741823)/1073741824 )) + +if (( (RAM_WANTED + 500000000) > RAM_AVAIL )); then + error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available, please set a lower value." + exit 15 +fi + +if (( (RAM_WANTED + 1950000000) > RAM_AVAIL )); then + warn "your configured RAM_SIZE of $WANTED_GB GB is much too close to the $AVAIL_GB GB of memory available, please set a lower value." +fi + return 0 diff --git a/src/reset.sh b/src/reset.sh index a85d2cd..4368718 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -81,15 +81,11 @@ echo # Check memory -if (( RAM_WANTED > RAM_AVAIL )); then - error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available." +if (( (RAM_WANTED + 500000000) > RAM_AVAIL )); then + error "Your configured RAM_SIZE of $WANTED_GB GB is higher than the $AVAIL_GB GB of memory available, please set a lower value." exit 15 fi -if (( (RAM_WANTED + 1950000000) > RAM_AVAIL )); then - warn "your configured RAM_SIZE of $WANTED_GB GB is much too close to the $AVAIL_GB GB of memory available." -fi - # Helper functions isAlive() {