twpayne / chezmoi

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

chezmoi: .chezmoiscripts/linux-install-packages.sh: inconsistent state #3947

Closed MRDGH2821 closed 20 hours ago

MRDGH2821 commented 2 days ago

What exactly are you trying to do?

Making my dotfiles sturdy enough to install all packages I need across Windows, Ubuntu & Fedora (and possibly Arch) My repo - https://github.com/MRDGH2821/dotfiles/

I have made run before scripts to initialise things on ubuntu/debian based systems, but none for fedora or arch. Then there is declarative installation of apps handled by chezmoi. And finally run after script which runs rew commands.

What have you tried so far?

I assumed it would be dashes problem in templates, thus I removed them. But no luck.

Where else have you checked for solutions?

https://www.chezmoi.io/user-guide/frequently-asked-questions/design/#can-chezmoi-support-multiple-sources-or-multiple-source-states

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

$ chezmoi apply --debug --verbose
time=2024-09-16T22:45:13.855+05:30 level=INFO msg=persistentPreRunRootE version.version=2.52.2 version.commit=f91dbfc2256b59c003ecdf28815a265e48eeecc3 version.date=2024-09-10T00:13:37Z version.builtBy=goreleaser args="[chezmoi apply --debug --verbose]" goVersion=go1.23.1
time=2024-09-16T22:45:13.856+05:30 level=INFO msg=Stat component=system name=/home/test/.config/chezmoi/chezmoistate.boltdb
time=2024-09-16T22:45:13.856+05:30 level=INFO msg=Stat component=system name=/home/test/.local/share/chezmoi
time=2024-09-16T22:45:13.856+05:30 level=INFO msg=Stat component=system name=/home/test/.local/share/chezmoi/.git
time=2024-09-16T22:45:13.858+05:30 level=ERROR msg=ReadFile component=system err="open /home/test/.local/share/chezmoi/.chezmoiroot: no such file or directory" name=/home/test/.local/share/chezmoi/.chezmoiroot size=0 data=""
time=2024-09-16T22:45:13.858+05:30 level=INFO msg=ReadDir component=system name=/home/test/.local/share/chezmoi
time=2024-09-16T22:45:13.858+05:30 level=INFO msg=ReadFile component=system name=/home/test/.local/share/chezmoi/.chezmoi.toml.tmpl size=735 data="{{ $email := promptStringOnce . \"email\" \"Email address\" }}\n{{ $e..."
time=2024-09-16T22:45:13.858+05:30 level=ERROR msg=Mkdir component=system err="mkdir /home/test/.config/chezmoi: file exists" name=/home/test/.config/chezmoi perm=511
time=2024-09-16T22:45:13.858+05:30 level=INFO msg=Stat component=system name=/home/test/.config/chezmoi
time=2024-09-16T22:45:13.858+05:30 level=INFO msg=Get component=persistentState bucket=configState key=configState value="{\n  \"configTemplateContentsSHA256\": \"6fbfc88f1dda9bbb87c2504e58c5dec20c58d5d1b724c06ac7e7f74fd323a8a9\"\n}\n"
time=2024-09-16T22:45:13.859+05:30 level=ERROR msg=ReadFile component=system err="open /home/test/.local/share/chezmoi/.chezmoiversion: no such file or directory" name=/home/test/.local/share/chezmoi/.chezmoiversion size=0 data=""
Installing KeepassXC on Fedora...
Last metadata expiration check: 0:41:53 ago on Monday 16 September 2024 10:03:21 PM.
Package keepassxc-2.7.9-1.fc40.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
time=2024-09-16T22:45:14.510+05:30 level=INFO msg=Run cmd=.local/share/chezmoi/.chezmoiscripts/.install-password-manager.sh duration=651.294369ms err=<nil>
time=2024-09-16T22:45:14.510+05:30 level=INFO msg=Stat component=system name=/home/test/.local/share/chezmoi
time=2024-09-16T22:45:14.510+05:30 level=INFO msg=Stat component=system name=/home/test/.local/share/chezmoi
time=2024-09-16T22:45:14.510+05:30 level=INFO msg=ReadDir component=system name=/home/test/.local/share/chezmoi
time=2024-09-16T22:45:14.510+05:30 level=INFO msg=ReadDir component=system name=/home/test/.local/share/chezmoi/.chezmoidata
time=2024-09-16T22:45:14.510+05:30 level=INFO msg=ReadFile component=system name=/home/test/.local/share/chezmoi/.chezmoidata/packages.yaml size=2049 data="packages:\n  windows:\n    winget:\n      - 7zip.7zip\n      - calib..."
time=2024-09-16T22:45:14.510+05:30 level=INFO msg=ReadFile component=system name=/home/test/.local/share/chezmoi/.chezmoiignore size=68 data="./README.md\n.gitignore\n.prettierrc.json\n.trunk\n.vscode\n**/*.src...."
time=2024-09-16T22:45:14.511+05:30 level=INFO msg=ReadDir component=system name=/home/test/.local/share/chezmoi/.chezmoiscripts
chezmoi: .chezmoiscripts/linux-install-packages.sh: inconsistent state (/home/test/.local/share/chezmoi/.chezmoiscripts/run_once_before_linux-install-packages.sh, /home/test/.local/share/chezmoi/.chezmoiscripts/run_onchange_linux-install-packages.sh.tmpl)

Output of chezmoi doctor

Details

```console $ chezmoi doctor RESULT CHECK MESSAGE ok version v2.52.2, commit f91dbfc2256b59c003ecdf28815a265e48eeecc3, built at 2024-09-10T00:13:37Z, built by goreleaser ok latest-version v2.52.2 ok os-arch linux/amd64 (Fedora Linux 40 (KDE Plasma)) ok uname Linux localhost-live.mshome.net 6.10.9-200.fc40.x86_64 #1 SMP PREEMPT_DYNAMIC Sun Sep 8 17:23:55 UTC 2024 x86_64 GNU/Linux ok go-version go1.23.1 (gc) ok executable ~/bin/chezmoi ok upgrade-method replace-executable ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2024-09-16T22:41:06+05:30 warning source-dir ~/.local/share/chezmoi is a git working tree (dirty) ok suspicious-entries no suspicious entries warning working-tree ~/.local/share/chezmoi 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 ~/.local/bin/zed ok edit-args zed --wait ok git-command found /usr/bin/git, version 2.46.0 warning merge-command vimdiff not found in $PATH 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.4.4 info pinentry-command not set info 1password-command op not found in $PATH info bitwarden-command bw not found in $PATH info bitwarden-secrets-command bws not found in $PATH info dashlane-command dcli not found in $PATH info doppler-command doppler not found in $PATH info gopass-command gopass not found in $PATH ok keepassxc-command found /usr/bin/keepassxc-cli, version 2.7.9 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 vlt-command vlt not found in $PATH info secret-command not set ```

Additional context

I did go through this but somehow I'm not able to understand their script.

bradenhilton commented 2 days ago

The error happens because you have two scripts with the same target name (their names after their attributes are removed):

run_once_before_linux-install-packages.sh
run_onchange_linux-install-packages.sh.tmpl

The target name for both of these scripts is linux-install-packages.sh.

If you want to keep their behaviors (run_once_before and run_onchange), you need to give them unique target names.

halostatue commented 2 days ago

I recommend using numbered scripts like one would do with rc scripts. My .chezmoiscripts is:

run_after_fisher-update.sh
run_once_before-01-install-macports.sh
run_once_before-02-install-homebrew.sh
run_once_before-03-install-rust.sh
run_once_before_00-prepare-system.sh
run_onchange_after-01-install-macports-packages.sh.tmpl
run_onchange_after-02-install-homebrew-packages.sh.tmpl
run_onchange_after-03-install-rust-packages.sh.tmpl
run_onchange_after-04-install-gobin.sh.tmpl
run_onchange_after-05-install-code-extensions.sh.tmpl
run_onchange_after-06-update-vim-spell.sh.tmpl
run_onchange_after-07-configure-apps.sh
MRDGH2821 commented 20 hours ago

Thanks for the solution!

I ran various scripts multiple times & it is working consistently