fix(chezmoi): Skip system packages tasks without sudo rights

mise bootstrap installs apt packages through sudo: for an account without
sudo (devenv sandbox agent), it failed and stopped chezmoi apply, thus the
image build. The bootstrap and the APT section of update are now skipped
unless the account is root, has passwordless sudo, or belongs to a sudo
group with a terminal to type the password.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xavierandClaude Opus 5.5 committed 2026-11-11 21:37:42 +01:00
1 parent ee405c937a
commit e7d9189de4
3 files changed
+58 -23

No files matched your search

+27 -17
View File
@@ -5,6 +5,7 @@ set -u
FAILED=0
STATUS_APT="not_detected"
APT=()
STATUS_BREW="not_detected"
STATUS_CHEZMOI="not_detected"
STATUS_MISE="not_detected"
@@ -73,30 +74,38 @@ if [[ -f /etc/os-release ]]; then
. /etc/os-release
if [[ "$ID" == "debian" || "$ID" == "ubuntu" ]]; then
STATUS_APT="success"
# root, sudo sans mot de passe, ou membre d'un groupe sudo avec un terminal
# pour saisir le mot de passe ; sinon (par exemple compte sans sudo d'un
# bac à sable) la section est ignorée
if ((EUID == 0)); then
APT=(apt)
else
elif sudo -n true 2>/dev/null ||
{ [[ -t 0 ]] && id -nG | grep -qwE 'sudo|admin|wheel'; }; then
APT=(sudo apt)
else
STATUS_APT="skipped"
fi
echo_info "APT"
run APT "Mise à jour des paquets" \
"${APT[@]}" update || true
run APT "Mise à niveau des paquets" \
"${APT[@]}" upgrade -y || true
run APT "Suppression des paquets inutiles" \
"${APT[@]}" autoremove -y || true
run APT "Nettoyage du cache" \
"${APT[@]}" autoclean || true
fi
fi
if ((${#APT[@]})); then
STATUS_APT="success"
echo_info "APT"
run APT "Mise à jour des paquets" \
"${APT[@]}" update || true
run APT "Mise à niveau des paquets" \
"${APT[@]}" upgrade -y || true
run APT "Suppression des paquets inutiles" \
"${APT[@]}" autoremove -y || true
run APT "Nettoyage du cache" \
"${APT[@]}" autoclean || true
fi
# ----------------------------------------------------------------------
# Homebrew
# ----------------------------------------------------------------------
@@ -174,6 +183,7 @@ case "$STATUS_APT" in
success) echo_success "APT : réussi" ;;
failed) echo_failed "APT : échoué" ;;
not_detected) echo_skipped "APT : non détecté" ;;
skipped) echo_skipped "APT : ignoré (pas de droits sudo)" ;;
esac
echo -n " ► "