diff --git a/local/bin/updateall.sh b/local/bin/updateall.sh index 4a200e3..8d230d9 100755 --- a/local/bin/updateall.sh +++ b/local/bin/updateall.sh @@ -32,14 +32,42 @@ run_scp() { # Fonction pour mettre à jour avec apt update_with_apt() { - echo -e " - Mise à jour avec apt sur $1 \n" - run_ssh "$1" ' - sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q clean && - sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q update && - sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q full-upgrade && - sudo DEBIAN_FRONTEND=noninteractive apt-get -y -q autoremove - ' - echo -e "\n" + local machine="$1" + local tmpfile="/tmp/update_${machine}_$(date +%s).log" + + echo -e " - Mise à jour avec apt-get sur $machine \n" + + # Exécution distante avec apt-get uniquement, log récupéré localement + run_ssh "$machine" ' + set -e + export DEBIAN_FRONTEND=noninteractive + LOGFILE=$(mktemp) + + sudo apt-get -y -q clean + sudo apt-get -y -q update + sudo apt-get -y -q --with-new-pkgs full-upgrade >> "$LOGFILE" 2>&1 + sudo apt-get -y -q autoremove >> "$LOGFILE" 2>&1 + + cat "$LOGFILE" + rm -f "$LOGFILE" + ' > "$tmpfile" + + # Analyse locale du log pour extraire les lignes intéressantes + updates=$(grep "^Les paquets suivants seront mis à jour" "$tmpfile" | wc -w) + installs=$(grep "^Les NOUVEAUX paquets suivants seront installés" "$tmpfile" | wc -w) + removes=$(grep "^Les paquets suivants seront ENLEVÉS" "$tmpfile" | wc -w) + + # Retirer le nombre de mots fixes d’en-tête pour chaque ligne + updates=$(( updates > 6 ? updates - 6 : 0 )) + installs=$(( installs > 8 ? installs - 8 : 0 )) + removes=$(( removes > 6 ? removes - 6 : 0 )) + + if [ "$updates" -gt 0 ] || [ "$installs" -gt 0 ] || [ "$removes" -gt 0 ]; then + echo -e "📦 ${GREEN}$machine${NC} : $updates mis à jour, $installs installés, $removes supprimés" + fi + + rm -f "$tmpfile" + echo } # Fonction pour mettre à jour avec dnf