Make check_container_storage() POSIX compliant

This commit is contained in:
justin 2026-01-27 19:31:02 -05:00 committed by Michel Roegl-Brunner
parent a5096a5b62
commit 8c4f1ce531

View File

@ -3086,21 +3086,32 @@ check_container_resources() {
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# check_container_storage() # check_container_storage()
# #
# - Checks /boot partition usage # - Checks root (/) partition usage
# - Warns if usage >80% and asks user confirmation before proceeding # - Warns if usage >80% and asks user confirmation before proceeding
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
check_container_storage() { check_container_storage() {
total_size=$(df /boot --output=size | tail -n 1) usage=$(df / -P | awk 'NR==2 {print $5}' | tr -d '%')
local used_size=$(df /boot --output=used | tail -n 1)
usage=$((100 * used_size / total_size)) # shellcheck disable=SC2181
if ((usage > 80)); then if [ $? -ne 0 ]; then
echo -e "${INFO}${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}" echo "Error: Failed to check disk usage."
echo -ne "Continue anyway? <y/N> "
read -r prompt
if [[ ! ${prompt,,} =~ ^(y|yes)$ ]]; then
echo -e "${CROSS}${HOLD}${YWB}Exiting based on user input.${CL}"
exit 1 exit 1
fi fi
if [ "$usage" -gt 80 ]; then
echo -e "${INFO}${HOLD} ${YWB}Warning: Storage is dangerously low (${usage}%).${CL}"
printf "Continue anyway? <y/N> "
read -r prompt
case "$prompt" in
[yY][eE][sS] | [yY])
# User input is "yes" or "y"; continue
;;
*)
echo -e "${CROSS}${HOLD}${YWB}Exiting based on user input.${CL}"
exit 1
;;
esac
fi fi
} }