twpayne / chezmoi

Manage your dotfiles across multiple diverse machines, securely.
https://www.chezmoi.io/
MIT License
12.9k stars 478 forks source link

Minimal `.chezmoiscripts` template file generating fork/exec error #2925

Closed balaji-dutt closed 1 year ago

balaji-dutt commented 1 year ago

What exactly are you trying to do?

I'm trying to debug an extremely strange issue where a previously working .chezmoiscripts template file is now abruptly generating a fork/exec /tmp/3067120083.XXXX.sh: no such file or directory error.

What have you tried so far?

I am creating a simple script template with the following lines:

.chezmoiscripts/run_once_before_emacs_spellcheck.sh.tmpl:

{{- if and (eq .chezmoi.os "linux") (.chezmoi.kernel.osrelease | lower | contains "microsoft") -}}
#!/bin/sh
mkdir -p $HOME/src && cd $HOME/src
{{ end -}}

However, when I try to run chezmoi apply it fails with the fork/exec error.

Where else have you checked for solutions?

Output of any commands you've tried with --verbose flag

$ chezmoi apply -v
diff --git a/.chezmoiscripts/emacs_spellcheck.sh b/.chezmoiscripts/emacs_spellcheck.sh
new file mode 100755
index 0000000000000000000000000000000000000000..4bd3629c958ca0b739e1a983f9b80b6088297d8a
--- /dev/null
+++ b/.chezmoiscripts/emacs_spellcheck.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+mkdir -p $HOME/src && cd $HOME/src
chezmoi: fork/exec /tmp/4264534368.emacs_spellcheck.sh: no such file or directory

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.33.0, commit ced12b81b493670520b177dcc62de2c67172858d, built at 2023-03-24T01:29:01Z, built by goreleaser warning latest-version v2.33.1 ok os-arch linux/amd64 (Ubuntu 22.04.2 LTS (Jammy Jellyfish)) ok uname Linux BIG-RIG 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux ok go-version go1.20.2 (gc) ok executable ~/.local/bin/chezmoi ok upgrade-method replace-executable ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2023-04-08T14:47:02+08:00 warning source-dir ~/development/dotfiles is a git working tree (dirty) ok suspicious-entries no suspicious entries warning working-tree ~/development/dotfiles is a git working tree (dirty) ok dest-dir ~ is a directory ok umask 022 ok cd-command found /bin/bash ok cd-args /bin/bash info diff-command not set ok edit-command found ~/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/bin/remote-cli/code ok edit-args ~/.vscode-server/bin/704ed70d4fd1c6bd6342c436f1ede30d1cff4710/bin/remote-cli/code --wait ok git-command found /usr/bin/git, version 2.34.1 ok merge-command found /usr/bin/vimdiff ok shell-command found /bin/bash ok shell-args /bin/bash info age-command age not found in $PATH ok gpg-command found /usr/bin/gpg, version 2.2.27 info pinentry-command not set ok 1password-command found /usr/bin/op, version 2.16.1 info bitwarden-command bw not found in $PATH info dashlane-command dcli not found in $PATH info gopass-command gopass not found in $PATH info keepassxc-command keepassxc-cli not found in $PATH info keepassxc-db not set info keeper-command keeper not found in $PATH info lastpass-command lpass not found in $PATH info pass-command pass not found in $PATH info passhole-command ph not found in $PATH info rbw-command rbw not found in $PATH info vault-command vault not found in $PATH info secret-command not set ```

Additional context

chezmoi execute-template does not throw any error with this file:

$ chezmoi execute-template < .chezmoiscripts/run_once_before_emacs_spellcheck.sh.tmpl 
#!/bin/sh
mkdir -p $HOME/src && cd $HOME/src

Running chezmoi state delete --bucket=entryState --key="/home/balaji/.chezmoiscripts/emacs_spellcheck.sh" and then chezmoi apply did not make any change.

This is the original complete script that was working two days ago.

twpayne commented 1 year ago

What is the output of:

$ chezmoi execute-template < .chezmoiscripts/run_once_before_emacs_spellcheck.sh.tmpl > a.sh
$ chmod a.sh
$ ./a.sh

If this gives the same "file not found" error then it is likely that /bin/sh is missing in your installation.

balaji-dutt commented 1 year ago
$ ./a.sh 
bash: ./a.sh: /bin/sh^M: bad interpreter: No such file or directory

Gah! Mixed line-ending woes. Not entirely sure why VSCode decided to switch the line-endings in the file to CRLF but switching back to LF fixed it.

Thank you for the helpful suggestion and for sharing a different way to debug templates!