mirror of
https://github.com/community-scripts/ProxmoxVE
synced 2025-01-10 19:05:09 +00:00
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 <34199185+havardthom@users.noreply.github.com> * Update misc/build.func Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> * Update misc/build.func Co-authored-by: Håvard Gjøby Thom <34199185+havardthom@users.noreply.github.com> * 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 <34199185+havardthom@users.noreply.github.com>
This commit is contained in:
parent
f8d302c096
commit
a29ed78ae3
@ -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")
|
||||
@ -501,6 +502,38 @@ install_script() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_container_resources() {
|
||||
# Check actual RAM & Cores
|
||||
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 "$var_ram" ]] || [[ "$current_cpu" -lt "$var_cpu" ]]; then
|
||||
echo -e "\n⚠️${HOLD} ${GN}Required: ${var_cpu} CPU, ${var_ram}MB RAM ${CL}| ${RD}Current: ${current_cpu} CPU, ${current_ram}MB RAM${CL}"
|
||||
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"
|
||||
exit 1
|
||||
else
|
||||
echo -e ""
|
||||
fi
|
||||
}
|
||||
|
||||
check_container_storage() {
|
||||
# Check if the /boot partition is more than 80% full
|
||||
total_size=$(df /boot --output=size | tail -n 1)
|
||||
local used_size=$(df /boot --output=used | tail -n 1)
|
||||
usage=$(( 100 * used_size / total_size ))
|
||||
if (( usage > 80 )); then
|
||||
# Prompt the user for confirmation to continue
|
||||
echo -e "⚠️${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}"
|
||||
read -r -p "Continue anyway? <y/N> " prompt
|
||||
# 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 user input.${CL}"
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user