config/etc/profile.d/disk-usage-warning.sh
Bastien Chanot c0fddc6f94 feat(install): system-wide low-disk login warning via /etc/profile.d
Add etc/profile.d/disk-usage-warning.sh (POSIX sh) that warns in bold
red at login when / or /home cross 85% usage. Deployed system-wide via
install_disk_warning() (sudo install -D -m 0644), gated inside the
apt-get block since df --output=pcent and /etc/profile.d are GNU/Debian
conventions absent on macOS. Idempotent and re-runnable.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CN1KSmsuLG6TxSeN5m8xvM
2026-06-24 18:00:17 +02:00

20 lines
615 B
Bash

#!/bin/sh
# disk-usage-warning.sh — login-time low-disk warning.
# Deployed to /etc/profile.d/ by install.sh, so every login shell sources it.
# Warns in bold red when / or /home crosses THRESHOLD% usage.
THRESHOLD=85
check_disk() {
mount_point="$1"
usage=$(df "$mount_point" --output=pcent 2>/dev/null | tail -1 | tr -dc '0-9')
[ -z "$usage" ] && return
if [ "$usage" -ge "$THRESHOLD" ]; then
printf '\033[1;31m' # rouge gras
printf '⚠ WARNING: %s à %s%% (seuil %s%%)\n' "$mount_point" "$usage" "$THRESHOLD"
printf '\033[0m'
fi
}
check_disk /home
check_disk /