Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option "check_storage" and "check_container_ressources" #249

Merged
merged 5 commits into from
Nov 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions misc/build.func
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ variables() {
# This function sets various color variables using ANSI escape codes for formatting text in the terminal.
color() {
YW=$(echo "\033[33m")
YWB=$(echo "\033[93m")
BL=$(echo "\033[36m")
RD=$(echo "\033[01;31m")
BGN=$(echo "\033[4;92m")
Expand Down Expand Up @@ -501,6 +502,41 @@ install_script() {
fi
}

check_container_ressources() {
MickLesk marked this conversation as resolved.
Show resolved Hide resolved
local required_ram="$var_ram" # Expected RAM in MB
local required_cpu="$var_cpu" # Expected number of Cores
local app_name="${APP}" # Name of App

# Check actual RAM & Cores
local current_ram
current_ram=$(free -m | awk '/^Mem:/{print $2}')
current_cpu=$(nproc)

# Check whether the current RAM is less than the required RAM or the CPU cores are less than required
if [[ "$current_ram" -lt "$required_ram" ]] || [[ "$current_cpu" -lt "$required_cpu" ]]; then
echo -e "\n⚠️${HOLD} ${GN}Required: ${required_cpu} CPU, ${required_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}"
echo -e "${YWB}Please ensure that the ${app_name} LXC is configured with at least ${var_cpu} vCPU and ${var_ram} MB RAM for the build process.${CL}\n"
havardthom marked this conversation as resolved.
Show resolved Hide resolved
MickLesk marked this conversation as resolved.
Show resolved Hide resolved
exit 1
else
echo -e ""
fi
}

check_storage() {
MickLesk marked this conversation as resolved.
Show resolved Hide resolved
# Check if the /boot partition is more than 80% full
if (( $(df /boot | awk 'NR==2{gsub("%","",$5); print $5}') > 80 )); then
# Prompt the user for confirmation to continue
echo -e "⚠️${HOLD} ${YWB}Warning: Storage is dangerously low.${CL}"
echo -e "Continue anyway? <y/N>${CL}"
read -r -p "" prompt
MickLesk marked this conversation as resolved.
Show resolved Hide resolved
# Check if the input is 'y' or 'yes', otherwise exit with status 1
if [[ ! ${prompt,,} =~ ^(y|yes)$ ]]; then
echo -e "❌${HOLD} ${YWB}Exiting based on incorrect user input.${CL}"
MickLesk marked this conversation as resolved.
Show resolved Hide resolved
exit 1
fi
fi
}

start() {
if command -v pveversion >/dev/null 2>&1; then
if ! (whiptail --backtitle "Proxmox VE Helper Scripts" --title "${APP} LXC" --yesno "This will create a New ${APP} LXC. Proceed?" 10 58); then
Expand Down