Skip to content

Commit 9c4a6e0

Browse files
committed
feat(chezmoi): add debug option for chezmoi init diagnostics
When debug=true, writes /var/log/chezmoi-feature-debug.log before chezmoi init with feature options, resolved command, injected env file contents and full installer environment. Bump minor version to 1.8.0.
1 parent 20978c5 commit 9c4a6e0

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/chezmoi/devcontainer-feature.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "chezmoi",
33
"id": "chezmoi",
4-
"version": "1.7.1",
4+
"version": "1.8.0",
55
"description": "Install chezmoi",
66
"documentationURL": "https://github.com/ckagerer/devcontainer-features/tree/main/src/chezmoi",
77
"options": {
@@ -35,6 +35,11 @@
3535
"default": false,
3636
"description": "Ignore errors during setup and continue execution."
3737
},
38+
"debug": {
39+
"type": "boolean",
40+
"default": false,
41+
"description": "Write diagnostic info (env vars, chezmoi command) to /var/log/chezmoi-feature-debug.log before running chezmoi init."
42+
},
3843
"env_vars": {
3944
"type": "string",
4045
"default": "",

src/chezmoi/install.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,36 @@ if [ -n "${CHEZMOI_BRANCH}" ]; then
114114
CHEZMOI_ARGS="${CHEZMOI_ARGS} --branch '${CHEZMOI_BRANCH}'"
115115
fi
116116
CMD="chezmoi ${CHEZMOI_ARGS} '${DOTFILES_REPO}'"
117+
118+
if [ "${DEBUG:-false}" = "true" ]; then
119+
CHEZMOI_DEBUG_LOG="/var/log/chezmoi-feature-debug.log"
120+
printf '=== chezmoi feature debug log: %s ===\n' "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >"${CHEZMOI_DEBUG_LOG}"
121+
{
122+
printf '\n-- Feature options --\n'
123+
printf 'DOTFILES_REPO=%s\n' "${DOTFILES_REPO}"
124+
printf 'CHEZMOI_BRANCH=%s\n' "${CHEZMOI_BRANCH:-}"
125+
printf 'CHEZMOI_USER=%s\n' "${CHEZMOI_USER}"
126+
printf 'CHEZMOI_USER_HOME=%s\n' "${CHEZMOI_USER_HOME}"
127+
printf 'ENV_VARS=%s\n' "${ENV_VARS:-}"
128+
printf 'KEEP_GOING=%s\n' "${KEEP_GOING:-false}"
129+
printf '\n-- Resolved chezmoi command --\n'
130+
printf '%s\n' "cd '${CHEZMOI_USER_HOME}' && ${CHEZMOI_ENV_SOURCE}REMOTE_CONTAINERS=1 ${CMD}"
131+
} >>"${CHEZMOI_DEBUG_LOG}"
132+
if [ -n "${CHEZMOI_ENV_TMP}" ] && [ -f "${CHEZMOI_ENV_TMP}" ]; then
133+
{
134+
printf '\n-- Injected env file (%s) --\n' "${CHEZMOI_ENV_TMP}"
135+
cat "${CHEZMOI_ENV_TMP}"
136+
} >>"${CHEZMOI_DEBUG_LOG}"
137+
fi
138+
{
139+
printf '\n-- Full environment (installer process) --\n'
140+
env | sort
141+
printf '\n=== end of debug log ===\n'
142+
} >>"${CHEZMOI_DEBUG_LOG}"
143+
chmod 640 "${CHEZMOI_DEBUG_LOG}"
144+
printf 'chezmoi debug log written to %s\n' "${CHEZMOI_DEBUG_LOG}"
145+
fi
146+
117147
sudo --user "${CHEZMOI_USER}" bash -c "cd '${CHEZMOI_USER_HOME}' && ${CHEZMOI_ENV_SOURCE}REMOTE_CONTAINERS=1 ${CMD}"
118148

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

0 commit comments

Comments
 (0)