diff --git a/apps/cloudpanel.sh b/apps/cloudpanel.sh index b08575c..c439869 100755 --- a/apps/cloudpanel.sh +++ b/apps/cloudpanel.sh @@ -219,7 +219,8 @@ install_cloudpanel() { echo -e "${YELLOW}CloudPanel is already installed!${NC}" return 0 fi - + + require_disk_space 2048 || return 1 check_requirements || return 1 echo "" diff --git a/apps/coolify.sh b/apps/coolify.sh index 21902b0..ef31432 100755 --- a/apps/coolify.sh +++ b/apps/coolify.sh @@ -66,7 +66,8 @@ install_coolify() { echo -e "${YELLOW}Coolify is already installed!${NC}" return 0 fi - + + require_disk_space 3072 || return 1 check_requirements || return 1 echo "" diff --git a/apps/proxmox.sh b/apps/proxmox.sh index 02b8304..6155d1f 100755 --- a/apps/proxmox.sh +++ b/apps/proxmox.sh @@ -242,16 +242,18 @@ clear_cache() { update_proxmox() { echo -e "${WHITE}${BOLD}UPDATE PROXMOX VE${NC}\n" - + check_proxmox || return 1 - + + require_disk_space 1024 || return 1 + # Configure non-interactive mode export DEBIAN_FRONTEND=noninteractive export NEEDRESTART_MODE=a export NEEDRESTART_SUSPEND=1 - + local start_time=$(date +%s) - + run_spinner "Updating package lists..." "apt update" echo "" diff --git a/apps/pterodactyl.sh b/apps/pterodactyl.sh index 0b4367f..c4f8ab2 100755 --- a/apps/pterodactyl.sh +++ b/apps/pterodactyl.sh @@ -211,7 +211,9 @@ install_pterodactyl() { echo -e "${YELLOW}Pterodactyl is already installed!${NC}" return 0 fi - + + require_disk_space 3072 || return 1 + echo "[1/10] Installing dependencies..." install_dependencies && install_composer echo "" diff --git a/apps/uptime-kuma.sh b/apps/uptime-kuma.sh index a6840f8..6f64aab 100755 --- a/apps/uptime-kuma.sh +++ b/apps/uptime-kuma.sh @@ -93,7 +93,9 @@ install_uptime_kuma() { echo -e "${YELLOW}Uptime Kuma is already installed!${NC}" return 0 fi - + + require_disk_space 1024 || return 1 + echo "[1/4] Installing dependencies..." install_dependencies echo "" diff --git a/lib/common.sh b/lib/common.sh index fa8c974..8fa6d9c 100644 --- a/lib/common.sh +++ b/lib/common.sh @@ -171,6 +171,42 @@ require_debian_ubuntu() { 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 # arguments. Call near the top of a sub-script: # require_root "$0" "$@" diff --git a/tools/harden.sh b/tools/harden.sh index fda5d1c..0cbb333 100755 --- a/tools/harden.sh +++ b/tools/harden.sh @@ -56,6 +56,7 @@ done # ═══════════════════════════════════════════════════════════════════════════ 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/ sshd_effective_port() { diff --git a/tools/server-benchmark.sh b/tools/server-benchmark.sh index 00450e3..4932faf 100755 --- a/tools/server-benchmark.sh +++ b/tools/server-benchmark.sh @@ -38,7 +38,9 @@ install_dependencies() { if ! command -v sysbench &> /dev/null; then echo -e "${YELLOW}[!] sysbench not found, installing...${NC}" echo "" - + + require_disk_space 300 || return 1 + if command -v apt-get &> /dev/null; then run_spinner "Updating package list..." "apt-get update -qq" run_spinner "Installing sysbench..." "DEBIAN_FRONTEND=noninteractive apt-get install -y -qq sysbench" diff --git a/tools/update-server.sh b/tools/update-server.sh index 25bf53b..bf105fd 100755 --- a/tools/update-server.sh +++ b/tools/update-server.sh @@ -62,6 +62,8 @@ if ! command -v apt-get >/dev/null 2>&1; then exit 1 fi +require_disk_space 1024 || exit 1 + UPGRADE_CMD="upgrade" UPGRADE_LABEL="Upgrade installed packages" if [ $DO_FULL_UPGRADE -eq 1 ]; then