feat(lib): add require_disk_space helper and enforce pre-flight disk checks
- add `require_disk_space` function to lib/common.sh with dedup logic for shared filesystems - gate cloudpanel, coolify, pterodactyl installs behind a 2–3 GB disk check - gate uptime-kuma, proxmox update, harden, update-server, and server-benchmark behind 300–1024 MB disk checks - fail early with a clear error before apt installs or config writes can leave the system in a partial state
This commit is contained in:
@@ -220,6 +220,7 @@ install_cloudpanel() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
require_disk_space 2048 || return 1
|
||||||
check_requirements || return 1
|
check_requirements || return 1
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ install_coolify() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
require_disk_space 3072 || return 1
|
||||||
check_requirements || return 1
|
check_requirements || return 1
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
|||||||
@@ -245,6 +245,8 @@ update_proxmox() {
|
|||||||
|
|
||||||
check_proxmox || return 1
|
check_proxmox || return 1
|
||||||
|
|
||||||
|
require_disk_space 1024 || return 1
|
||||||
|
|
||||||
# Configure non-interactive mode
|
# Configure non-interactive mode
|
||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
export NEEDRESTART_MODE=a
|
export NEEDRESTART_MODE=a
|
||||||
|
|||||||
@@ -212,6 +212,8 @@ install_pterodactyl() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
require_disk_space 3072 || return 1
|
||||||
|
|
||||||
echo "[1/10] Installing dependencies..."
|
echo "[1/10] Installing dependencies..."
|
||||||
install_dependencies && install_composer
|
install_dependencies && install_composer
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -94,6 +94,8 @@ install_uptime_kuma() {
|
|||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
require_disk_space 1024 || return 1
|
||||||
|
|
||||||
echo "[1/4] Installing dependencies..."
|
echo "[1/4] Installing dependencies..."
|
||||||
install_dependencies
|
install_dependencies
|
||||||
echo ""
|
echo ""
|
||||||
|
|||||||
@@ -171,6 +171,42 @@ require_debian_ubuntu() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Verify enough free disk space before doing apt installs or writing config.
|
||||||
|
# Fails early with a clear message so we don't get half-installed packages or
|
||||||
|
# files truncated mid-write when the disk is full.
|
||||||
|
#
|
||||||
|
# Usage:
|
||||||
|
# require_disk_space # 500MB on /var (apt cache + lists)
|
||||||
|
# require_disk_space 1024 # 1024MB on /var
|
||||||
|
# require_disk_space 1024 /var /opt # 1024MB on each listed path
|
||||||
|
#
|
||||||
|
# Duplicate filesystems (e.g. /var on the same fs as /) are checked once.
|
||||||
|
require_disk_space() {
|
||||||
|
local min_mb=${1:-500}
|
||||||
|
shift 2>/dev/null || true
|
||||||
|
local paths=("$@")
|
||||||
|
[ ${#paths[@]} -eq 0 ] && paths=(/var)
|
||||||
|
|
||||||
|
local path avail fs seen=" " rc=0
|
||||||
|
for path in "${paths[@]}"; do
|
||||||
|
fs=$(df -P "$path" 2>/dev/null | awk 'NR==2 {print $1}')
|
||||||
|
if [ -z "$fs" ]; then
|
||||||
|
err "Cannot read disk usage for ${path}"
|
||||||
|
rc=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
[[ "$seen" == *" $fs "* ]] && continue
|
||||||
|
seen="$seen$fs "
|
||||||
|
|
||||||
|
avail=$(df -Pm "$path" 2>/dev/null | awk 'NR==2 {print $4}')
|
||||||
|
if [ "${avail:-0}" -lt "$min_mb" ]; then
|
||||||
|
err "Not enough disk space on ${path} (${fs}): ${avail}MB free, ${min_mb}MB required."
|
||||||
|
rc=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
return $rc
|
||||||
|
}
|
||||||
|
|
||||||
# Re-exec the current script via sudo if not already root. Preserves env and
|
# Re-exec the current script via sudo if not already root. Preserves env and
|
||||||
# arguments. Call near the top of a sub-script:
|
# arguments. Call near the top of a sub-script:
|
||||||
# require_root "$0" "$@"
|
# require_root "$0" "$@"
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ done
|
|||||||
# ═══════════════════════════════════════════════════════════════════════════
|
# ═══════════════════════════════════════════════════════════════════════════
|
||||||
|
|
||||||
require_debian_ubuntu || exit 1
|
require_debian_ubuntu || exit 1
|
||||||
|
require_disk_space 500 || exit 1
|
||||||
|
|
||||||
# Read the effective Port from sshd_config + any drop-in under sshd_config.d/
|
# Read the effective Port from sshd_config + any drop-in under sshd_config.d/
|
||||||
sshd_effective_port() {
|
sshd_effective_port() {
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ install_dependencies() {
|
|||||||
echo -e "${YELLOW}[!] sysbench not found, installing...${NC}"
|
echo -e "${YELLOW}[!] sysbench not found, installing...${NC}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
|
require_disk_space 300 || return 1
|
||||||
|
|
||||||
if command -v apt-get &> /dev/null; then
|
if command -v apt-get &> /dev/null; then
|
||||||
run_spinner "Updating package list..." "apt-get update -qq"
|
run_spinner "Updating package list..." "apt-get update -qq"
|
||||||
run_spinner "Installing sysbench..." "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq sysbench"
|
run_spinner "Installing sysbench..." "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq sysbench"
|
||||||
|
|||||||
@@ -62,6 +62,8 @@ if ! command -v apt-get >/dev/null 2>&1; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
require_disk_space 1024 || exit 1
|
||||||
|
|
||||||
UPGRADE_CMD="upgrade"
|
UPGRADE_CMD="upgrade"
|
||||||
UPGRADE_LABEL="Upgrade installed packages"
|
UPGRADE_LABEL="Upgrade installed packages"
|
||||||
if [ $DO_FULL_UPGRADE -eq 1 ]; then
|
if [ $DO_FULL_UPGRADE -eq 1 ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user