From e7d9189de4880d689a4b9afd5e4501477225f9da Mon Sep 17 00:00:00 2001 From: Xavier Logerais Date: Wed, 11 Nov 2026 21:37:42 +0100 Subject: [PATCH] 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 --- private_dot_local/bin/executable_update | 44 +++++++++++++++---------- run_once_after_00-install-mise.sh.tmpl | 17 ++++++++-- run_onchange_after_mise-install.sh.tmpl | 20 +++++++++-- 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/private_dot_local/bin/executable_update b/private_dot_local/bin/executable_update index c961aee..eb2acca 100644 --- a/private_dot_local/bin/executable_update +++ b/private_dot_local/bin/executable_update @@ -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 " ► " diff --git a/run_once_after_00-install-mise.sh.tmpl b/run_once_after_00-install-mise.sh.tmpl index ccc8ead..d8ebab7 100644 --- a/run_once_after_00-install-mise.sh.tmpl +++ b/run_once_after_00-install-mise.sh.tmpl @@ -1,5 +1,12 @@ #!/usr/bin/env bash +# Droits d'administration : root, sudo sans mot de passe, ou membre d'un +# groupe sudo avec un terminal pour saisir le mot de passe +can_sudo() { + (( EUID == 0 )) || sudo -n true 2>/dev/null \ + || { [ -t 0 ] && id -nG | grep -qwE 'sudo|admin|wheel'; } +} + # 1. Installer Mise s'il n'est pas présent if ! command -v mise &>/dev/null; then echo "📦 Installation de Mise..." @@ -9,10 +16,14 @@ if ! command -v mise &>/dev/null; then export PATH="${HOME}/.local/bin:$PATH" fi -# 2. Lancer le bootstrap +# 2. Lancer le bootstrap (paquets système : droits sudo requis) if command -v mise &>/dev/null; then - echo "🚀 Mise bootstrap..." - mise bootstrap --yes + if can_sudo; then + echo "🚀 Mise bootstrap..." + mise bootstrap --yes + else + echo "⚠️ Pas de droits sudo : mise bootstrap ignoré (paquets système non installés)." + fi fi # 3. Installer tous les outils déclarés dans ~/.config/mise/config.toml et ~/.config/mise/conf.d/*.toml diff --git a/run_onchange_after_mise-install.sh.tmpl b/run_onchange_after_mise-install.sh.tmpl index 93a0899..f05e95d 100644 --- a/run_onchange_after_mise-install.sh.tmpl +++ b/run_onchange_after_mise-install.sh.tmpl @@ -8,6 +8,13 @@ set -euo pipefail +# Droits d'administration : root, sudo sans mot de passe, ou membre d'un +# groupe sudo avec un terminal pour saisir le mot de passe +can_sudo() { + (( EUID == 0 )) || sudo -n true 2>/dev/null \ + || { [ -t 0 ] && id -nG | grep -qwE 'sudo|admin|wheel'; } +} + export PATH="${HOME}/.local/bin:$PATH" MISE_CONF_D="${HOME}/.config/mise/conf.d" mkdir -p "$MISE_CONF_D" @@ -54,9 +61,16 @@ MISE_TOOLBOX_EOF {{- end }} if command -v mise &>/dev/null; then - echo - echo "🚀 Mise bootstrap..." - mise bootstrap --yes + # Paquets système (apt) du bootstrap : droits sudo requis + # (sinon, par exemple compte sans sudo d'un bac à sable, on les ignore) + if can_sudo; then + echo + echo "🚀 Mise bootstrap..." + mise bootstrap --yes + else + echo + echo "⚠️ Pas de droits sudo : mise bootstrap ignoré (paquets système non installés)." + fi echo echo "⚡ Mise install..."