twpayne / chezmoi

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

hooks.read-source-state.pre cannot find script #3861

Open ashebanow opened 1 week ago

ashebanow commented 1 week ago

Describe the bug

I tried to follow the instructions for adding a hook to install 1password across various OSes. But no matter what form of path I try, it always says that it can't run the file even though it is there. The only difference is that I've got a home subdirectory that is my chezmoi root, and I don't put the script in the home subdirectory. (NOTE: I also tried moving the script to the home directory. It made no difference.)

Here's a screenshot of the error when I use the simplest form of path. Note the commented out forms as well - none work.

❯ pwd
/home/ashebanow/.local/share/chezmoi

❯ head -10 home/.chezmoi.toml.tmpl
# A lot of this is directly from
# https://github.com/twpayne/dotfiles/blob/436e4e9366667d84493d3504123bb16c89583605/home/.chezmoi.toml.tmpl

# setup onepassword
[hooks.read-source-state.pre]
  # command = "{{- .chezmoi.commandDir -}}/.install-1password.sh"
  # command = "/home/ashebanow/.local/share/chezmoi/.install-1password.sh"
  command = ".install-1password.sh"
  # command = ".local/share/chezmoi/.install-1password.sh"

❯ ll .install-1password.sh
.rwxr-xr-x 3.4k ashebanow 6 Jul 14:53 .install-1password.sh

❯ chezmoi init

❯ chezmoi apply
chezmoi: .install-1password.sh: exec: ".install-1password.sh": cannot run executable found relative to current directory
snip ![image](https://github.com/twpayne/chezmoi/assets/11263/6948c180-cfe3-4e15-900e-ae9a17a02976)

If I comment out the simple relative path and use the path relative to $HOME, I get this error:

chezmoi: .local/share/chezmoi/.install-1password.sh: fork/exec .local/share/chezmoi/.install-1password.sh: no such file or directory

If I use a full path, as in the first two lines, I get this error:

chezmoi: /home/ashebanow/.local/share/chezmoi/.install-1password.sh: fork/exec /home/ashebanow/.local/share/chezmoi/.install-1password.sh: no such file or directory

As shown in the screenshot, the file does exist, is executable, and starts with a hashbang.

To reproduce

Expected behavior

I expected the chezmoi apply to succeed while running the script.

Output of command with the --verbose flag

$ chezmoi --verbose apply
chezmoi: .local/share/chezmoi/home/.install-1password.sh: fork/exec .local/share/chezmoi/home/.install-1password.sh: no such file or directory

Output of chezmoi doctor

```console $ chezmoi doctor RESULT CHECK MESSAGE warning version v2.50.0, built at 2024-07-02T21:33:31Z ok latest-version v2.50.0 ok os-arch linux/amd64 (EndeavourOS) ok uname Linux limon 6.9.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 28 Jun 2024 04:32:50 +0000 x86_64 GNU/Linux ok go-version go1.22.4 (gc) ok executable /usr/bin/chezmoi ok config-file ~/.config/chezmoi/chezmoi.toml, last modified 2024-07-06T15:08:33-07:00 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 /usr/bin/zsh ok cd-args /usr/bin/zsh info diff-command not set ok edit-command found ~/.local/bin/lvim ok edit-args ~/.local/bin/lvim ok git-command found /usr/bin/git, version 2.45.2 ok merge-command found /usr/bin/vimdiff ok shell-command found /usr/bin/zsh ok shell-args /usr/bin/zsh ok age-command found /usr/bin/age, version 1.2.0 ok gpg-command found /usr/bin/gpg, version 2.4.5 info pinentry-command not set ok 1password-command found /usr/bin/op, version 2.29.0 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 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 vlt-command vlt not found in $PATH info secret-command not set ```

Additional context

Add any other context about the problem here.

ashebanow commented 1 week ago

Sorry, the chezmoi doctor output didn't format correctly somehow. Here it is again:


RESULT    CHECK                       MESSAGE
warning   version                     v2.50.0, built at 2024-07-02T21:33:31Z
ok        latest-version              v2.50.0
ok        os-arch                     linux/amd64 (EndeavourOS)
ok        uname                       Linux limon 6.9.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 28 Jun 2024 04:32:50 +0000 x86_64 GNU/Linux
ok        go-version                  go1.22.4 (gc)
ok        executable                  /usr/bin/chezmoi
ok        config-file                 ~/.config/chezmoi/chezmoi.toml, last modified 2024-07-06T15:08:33-07:00
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 /usr/bin/zsh
ok        cd-args                     /usr/bin/zsh
info      diff-command                not set
ok        edit-command                found ~/.local/bin/lvim
ok        edit-args                   ~/.local/bin/lvim
ok        git-command                 found /usr/bin/git, version 2.45.2
ok        merge-command               found /usr/bin/vimdiff
ok        shell-command               found /usr/bin/zsh
ok        shell-args                  /usr/bin/zsh
ok        age-command                 found /usr/bin/age, version 1.2.0
ok        gpg-command                 found /usr/bin/gpg, version 2.4.5
info      pinentry-command            not set
ok        1password-command           found /usr/bin/op, version 2.29.0
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
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      vlt-command                 vlt not found in $PATH
info      secret-command              not set
halostatue commented 1 week ago

Have you considered running this as a before script instead of trying to run it as a hook? It gives an example name run_once_before_install-password-manager.sh that suggests exactly what you’re trying to do.

There may or may not be a bug in pre-hooks, but I can't say as I don't use them.

ashebanow commented 1 week ago

I probably will do that. But this is the documented method, even though @twpayne doesn’t use it in his own dotfiles. So I figured filling a bug was the right thing to do,

On Sat, Jul 6, 2024 at 6:57 PM Austin Ziegler @.***> wrote:

Have you considered running this as a before script https://www.chezmoi.io/user-guide/use-scripts-to-perform-actions/ instead of trying to run it as a hook? It gives an example name run_once_before_install-password-manager.sh that suggests exactly what you’re trying to do.

There may or may not be a bug in pre-hooks, but I can't say as I don't use them.

— Reply to this email directly, view it on GitHub https://github.com/twpayne/chezmoi/issues/3861#issuecomment-2212250534, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACX72E7UAN37DNYMQZWKTZLCOAPAVCNFSM6AAAAABKOYUI5KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMJSGI2TANJTGQ . You are receiving this because you modified the open/close state.Message ID: @.***>

bradenhilton commented 1 week ago

@ashebanow FYI, your chezmoi doctor output wasn't formatted properly because you need to surround a code block with empty lines inside details, e.g.:

<details><summary>Details</summary>

```console
❯ pwd



I've updated the issue and hidden your comment.
twpayne commented 1 week ago

The error is coming from your .install-1password.sh script, not chezmoi. chezmoi is running the script correctly.

What are the exact contents of your .install-1password.sh script?

twpayne commented 5 days ago

For info, I wondered if the problem was the relative path to the hook with a test in 4cac69813ef2b01e5d9f956cb9447a5bf9902533, but this seems to work as intended.

ashebanow commented 4 days ago

Sorry I took so long to respond, had a busy couple of days.

I'm pretty certain that the problem is not in my script, since it runs fine on my mac here standalone (it correctly detects that homebrew & 1password are already installed and exits). I haven't fully debugged the steps on either linux or mac, because I'm trying to get past this problem first.

In any event, the script doesn't call itself recursively, so it can't be the one generating the message.

The script itself is attached (renamed from the original '.install-1password.sh' since github won't allow me to attach hidden files or shell scripts here. As mentioned earlier, the script is in .local/share/chezmoi, not in the home subdir which is my dotfiles root. I've tried four different path combos (shown above) including relative paths and full paths. None are working for me, I wonder if the issue is the split between the two directories.

install-1password.txt