Skip to content

Commit a29ed78

Browse files
MickLeskhavardthom
andauthored
Add Option "check_storage" and "check_container_ressources" (#249)
* Add Option "check_storage" and "check_container_ressources" * Update misc/build.func Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update misc/build.func Co-authored-by: Håvard Gjøby Thom <[email protected]> * Update misc/build.func Co-authored-by: Håvard Gjøby Thom <[email protected]> * Final Version - remove locals - use var_variables - show storage in percent - harmonize some texts - optimize Prompt (Continue anyway) --------- Co-authored-by: Håvard Gjøby Thom <[email protected]>
1 parent f8d302c commit a29ed78

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

misc/build.func

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ variables() {
77
# This function sets various color variables using ANSI escape codes for formatting text in the terminal.
88
color() {
99
YW=$(echo "\033[33m")
10+
YWB=$(echo "\033[93m")
1011
BL=$(echo "\033[36m")
1112
RD=$(echo "\033[01;31m")
1213
BGN=$(echo "\033[4;92m")
@@ -501,6 +502,38 @@ install_script() {
501502
fi
502503
}
503504

505+
check_container_resources() {
506+
# Check actual RAM & Cores
507+
current_ram=$(free -m | awk '/^Mem:/{print $2}')
508+
current_cpu=$(nproc)
509+
510+
# Check whether the current RAM is less than the required RAM or the CPU cores are less than required
511+
if [[ "$current_ram" -lt "$var_ram" ]] || [[ "$current_cpu" -lt "$var_cpu" ]]; then
512+
echo -e "\n⚠️${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}"
513+
echo -e "${YWB}Please ensure that the ${APP} LXC is configured with at least ${var_cpu} vCPU and ${var_ram} MB RAM for the build process.${CL}\n"
514+
exit 1
515+
else
516+
echo -e ""
517+
fi
518+
}
519+
520+
check_container_storage() {
521+
# Check if the /boot partition is more than 80% full
522+
total_size=$(df /boot --output=size | tail -n 1)
523+
local used_size=$(df /boot --output=used | tail -n 1)
524+
usage=$(( 100 * used_size / total_size ))
525+
if (( usage > 80 )); then
526+
# Prompt the user for confirmation to continue
527+
echo -e "⚠️${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}"
528+
read -r -p "Continue anyway? <y/N> " prompt
529+
# Check if the input is 'y' or 'yes', otherwise exit with status 1
530+
if [[ ! ${prompt,,} =~ ^(y|yes)$ ]]; then
531+
echo -e "❌${HOLD} ${YWB}Exiting based on user input.${CL}"
532+
exit 1
533+
fi
534+
fi
535+
}
536+
504537
start() {
505538
if command -v pveversion >/dev/null 2>&1; then
506539
if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then

0 commit comments

Comments
 (0)