chezmoi scriptTempDir related fixes

This commit is contained in:
Lockszmith (@kateryna) 2025-04-15 13:44:39 -04:00
parent 03a2310480
commit d3ef7b6bcd
2 changed files with 25 additions and 3 deletions

View File

@ -1,7 +1,6 @@
# This .chezmoi.toml file is used once only # This .chezmoi.toml file is used once only
# It collects information about the system in order to determine # It collects information about the system in order to determine
# which of the _home.* dirs will be set as the .chezmoiroot # which of the _home.* dirs will be set as the .chezmoiroot
#
{{- $githubToken := promptStringOnce . "githubToken" "Public GITHUB token (mostly for rate limits - !insecure!)" (or ( {{- $githubToken := promptStringOnce . "githubToken" "Public GITHUB token (mostly for rate limits - !insecure!)" (or (
env "CZ_GITHUB_ACCESS_TOKEN" env "CZ_GITHUB_ACCESS_TOKEN"
@ -9,7 +8,7 @@
) ( env "GITHUB_ACCESS_TOKEN" ) ( env "GITHUB_ACCESS_TOKEN"
) ( env "GITHUB_TOKEN" ) ( env "GITHUB_TOKEN"
)) -}} )) -}}
{{- $scriptTempDir := "~/.cache/chezmoi/tmp" }} {{- $scriptTempDir := or (env "CZ_SCRIPT_TEMPDIR") "~/.cache/chezmoi/tmp" }}
{{- $chassisType := "desktop" }} {{- $chassisType := "desktop" }}
{{- $sysType := "posix" }} {{- $sysType := "posix" }}
@ -32,8 +31,9 @@
{{- $sysType = "windows" }} {{- $sysType = "windows" }}
{{- $sysVendor = "pc" }} {{- $sysVendor = "pc" }}
{{- $chassisType = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "if ((Get-CimInstance -Class Win32_Battery | Measure-Object).Count -gt 0) { Write-Output 'laptop' } else { Write-Output 'desktop' }") | trim }} {{- $chassisType = (output "powershell.exe" "-NoProfile" "-NonInteractive" "-Command" "if ((Get-CimInstance -Class Win32_Battery | Measure-Object).Count -gt 0) { Write-Output 'laptop' } else { Write-Output 'desktop' }") | trim }}
{{- end }} {{- end -}}
#
scriptTempDir={{- $scriptTempDir | quote }} scriptTempDir={{- $scriptTempDir | quote }}
[scriptEnv] [scriptEnv]

View File

@ -34,6 +34,28 @@ done
set -e set -e
${SET_X:-:} -x ${SET_X:-:} -x
# Make sure temporary directory exists
CZ_SCRIPT_TEMPDIR="${CZ_SCRIPT_TEMPDIR:-~/.cache/chezmoi/tmp}"
mkdir -p "${CZ_SCRIPT_TEMPDIR}"
# (in debug x2 mode) Show the existing configuration before destroying it
[[ -z "${CZ_DEBUG}" ]] || chezmoi cat-config
# Destroy existing chezmoi state
rm -fR ~/.config/chezmoi ~/.local/share/chezmoi/.chezmoiroot rm -fR ~/.config/chezmoi ~/.local/share/chezmoi/.chezmoiroot
# Create a temporary chezmoi configuration bypass /tmp noexec situation
mkdir -p ~/.config/chezmoi
cat - > ~/.config/chezmoi/chezmoi.toml <<TOML
scriptTempDir="${CZ_SCRIPT_TEMPDIR}"
TOML
# Show the initial configuration in debug x2 mode
[[ -z "${CZ_DEBUG}" ]] || chezmoi cat-config
# "It's show time!" - Re-initialize
chezmoi init ${CZ_DEBUG} --apply chezmoi init ${CZ_DEBUG} --apply
unset SET_X unset SET_X
# Show the final configuration in debug x2 mode
[[ -z "${CZ_DEBUG}" ]] || chezmoi cat-config