Skip to content

Commit

Permalink
feat: Add flag to disable RAM check (#511)
Browse files Browse the repository at this point in the history
  • Loading branch information
kroese authored May 19, 2024
1 parent 18c8a04 commit 384c2ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
20 changes: 12 additions & 8 deletions src/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,20 @@ fi

# Check available memory as the very last step

RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
AVAIL_GB=$(( (RAM_AVAIL + 1073741823)/1073741824 ))
if [[ "$RAM_CHECK" != [Nn]* ]]; then

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 17
fi
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
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."
fi

if (( (RAM_WANTED + 1450000000) > 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
12 changes: 8 additions & 4 deletions src/reset.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ echo "❯ For support visit $SUPPORT"
: "${ARGUMENTS:=""}" # Extra QEMU parameters
: "${CPU_CORES:="1"}" # Amount of CPU cores
: "${RAM_SIZE:="1G"}" # Maximum RAM amount
: "${RAM_CHECK:="Y"}" # Check available RAM
: "${DISK_SIZE:="16G"}" # Initial data disk size
: "${BOOT_INDEX:="10"}" # Boot index of CD drive

Expand Down Expand Up @@ -59,11 +60,12 @@ if [ ! -d "$STORAGE" ]; then
fi

# Read memory
RAM_SPARE=500000000
RAM_AVAIL=$(free -b | grep -m 1 Mem: | awk '{print $7}')
RAM_TOTAL=$(free -b | grep -m 1 Mem: | awk '{print $2}')
RAM_SIZE=$(echo "${RAM_SIZE^^}" | sed 's/MB/M/g;s/GB/G/g;s/TB/T/g')
RAM_WANTED=$(numfmt --from=iec "$RAM_SIZE")
AVAIL_GB=$(( (RAM_AVAIL + 1073741823)/1073741824 ))
AVAIL_GB=$(( RAM_AVAIL/1073741824 ))
TOTAL_GB=$(( (RAM_TOTAL + 1073741823)/1073741824 ))
WANTED_GB=$(( (RAM_WANTED + 1073741823)/1073741824 ))

Expand All @@ -79,9 +81,11 @@ echo

# Check memory

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 17
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
fi

# Helper functions
Expand Down

0 comments on commit 384c2ed

Please sign in to comment.