From 36af9a34839106e6d27cf278f580e7be9496dfbc Mon Sep 17 00:00:00 2001 From: Kroese Date: Fri, 14 Mar 2025 14:42:08 +0100 Subject: [PATCH] feat: Validate configured RAM (#924) --- src/config.sh | 18 ++++++++++++------ src/reset.sh | 13 +++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/config.sh b/src/config.sh index f38bec1..2653675 100644 --- a/src/config.sh +++ b/src/config.sh @@ -20,12 +20,18 @@ if [[ "$RAM_CHECK" != [Nn]* ]]; then AVAIL_GB=$(( RAM_AVAIL/1073741824 )) if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then - error "Your configured RAM_SIZE of $WANTED_GB GB is too high for the $AVAIL_GB GB of memory available, please set a lower value." - exit 17 - fi - - if (( (RAM_WANTED + (RAM_SPARE * 3)) > RAM_AVAIL )); then - warn "your configured RAM_SIZE of $WANTED_GB GB is very close to the $AVAIL_GB GB of memory available, please consider a lower value." + msg="Your configured RAM_SIZE of $WANTED_GB GB is too high for the $AVAIL_GB GB of memory available, please set a lower value." + [[ "${FS,,}" != "zfs" ]] && error "$msg" && exit 17 + info "$msg" + else + if (( (RAM_WANTED + (RAM_SPARE * 3)) > RAM_AVAIL )); then + msg="your configured RAM_SIZE of $WANTED_GB GB is very close to the $AVAIL_GB GB of memory available, please consider a lower value." + if [[ "${FS,,}" != "zfs" ]]; then + warn "$msg" + else + info "$msg" + fi + fi fi fi diff --git a/src/reset.sh b/src/reset.sh index 9113c2b..b6789c3 100644 --- a/src/reset.sh +++ b/src/reset.sh @@ -132,15 +132,12 @@ SPACE_GB=$(( (SPACE + 1073741823)/1073741824 )) echo "❯ CPU: ${CPU} | RAM: $AVAIL_GB/$TOTAL_GB GB | DISK: $SPACE_GB GB (${FS}) | KERNEL: ${SYS}..." echo -# Check memory +# Check available memory -[[ "${FS,,}" == "zfs" ]] && RAM_CHECK="N" - -if [[ "$RAM_CHECK" != [Nn]* ]]; then - if (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then - error "Your configured RAM_SIZE of $WANTED_GB GB is too high for the $AVAIL_GB GB of memory available, please set a lower value." - exit 17 - fi +if [[ "$RAM_CHECK" != [Nn]* ]] && (( (RAM_WANTED + RAM_SPARE) > RAM_AVAIL )); then + msg="Your configured RAM_SIZE of $WANTED_GB GB is too high for the $AVAIL_GB GB of memory available, please set a lower value." + [[ "${FS,,}" != "zfs" ]] && error "$msg" && exit 17 + info "$msg" fi # Cleanup files