Skip to content

Commit 565ee65

Browse files
committed
debug(chezmoi): enhance debug log with version, verbose init, post-init state
When debug=true: - chezmoi version logged before init - --verbose added to chezmoi init command - Post-init: chezmoi status, chezmoi managed, ls $HOME appended to log
1 parent 02d98ff commit 565ee65

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/chezmoi/install.sh

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,17 @@ fi
116116
if [ "${DEFER_SCRIPTS:-false}" = "true" ]; then
117117
CHEZMOI_ARGS="${CHEZMOI_ARGS} --exclude=scripts"
118118
fi
119+
if [ "${DEBUG:-false}" = "true" ]; then
120+
CHEZMOI_ARGS="${CHEZMOI_ARGS} --verbose"
121+
fi
119122
CMD="chezmoi ${CHEZMOI_ARGS} '${DOTFILES_REPO}'"
120123

121124
if [ "${DEBUG:-false}" = "true" ]; then
122125
CHEZMOI_DEBUG_LOG="/var/log/chezmoi-feature-debug.log"
123126
printf '=== chezmoi feature debug log: %s ===\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >"${CHEZMOI_DEBUG_LOG}"
124127
{
128+
printf '\n-- chezmoi version --\n'
129+
chezmoi --version 2>&1 || true
125130
printf '\n-- Feature options --\n'
126131
printf 'DOTFILES_REPO=%s\n' "${DOTFILES_REPO}"
127132
printf 'CHEZMOI_BRANCH=%s\n' "${CHEZMOI_BRANCH:-}"
@@ -141,7 +146,6 @@ if [ "${DEBUG:-false}" = "true" ]; then
141146
{
142147
printf '\n-- Full environment (installer process) --\n'
143148
env | sort
144-
printf '\n=== end of debug log ===\n'
145149
} >>"${CHEZMOI_DEBUG_LOG}"
146150
chmod 640 "${CHEZMOI_DEBUG_LOG}"
147151
printf 'chezmoi debug log written to %s\n' "${CHEZMOI_DEBUG_LOG}"
@@ -151,6 +155,18 @@ sudo --user "${CHEZMOI_USER}" bash -c "cd '${CHEZMOI_USER_HOME}' && ${CHEZMOI_EN
151155

152156
[ -n "${CHEZMOI_ENV_TMP}" ] && rm -f "${CHEZMOI_ENV_TMP}"
153157

158+
if [ "${DEBUG:-false}" = "true" ]; then
159+
{
160+
printf '\n-- Post-init: chezmoi status --\n'
161+
sudo --user "${CHEZMOI_USER}" bash -c "cd '${CHEZMOI_USER_HOME}' && REMOTE_CONTAINERS=1 chezmoi status 2>&1" || true
162+
printf '\n-- Post-init: chezmoi managed --\n'
163+
sudo --user "${CHEZMOI_USER}" bash -c "cd '${CHEZMOI_USER_HOME}' && REMOTE_CONTAINERS=1 chezmoi managed 2>&1" || true
164+
printf '\n-- Post-init: home directory --\n'
165+
ls -la "${CHEZMOI_USER_HOME}" 2>&1 || true
166+
printf '\n=== end of debug log ===\n'
167+
} >>"${CHEZMOI_DEBUG_LOG}"
168+
fi
169+
154170
# --- Generate a script to be executed by the 'postCreateCommand' lifecycle hook.
155171
# Runs deferred chezmoi scripts (when defer_scripts=true) and optional Atuin login/sync.
156172
POST_CREATE_SCRIPT_PATH="/usr/local/share/chezmoi-post-create.sh"

0 commit comments

Comments
 (0)