termux / termux-packages

A package build system for Termux.
https://termux.dev
Other
12.97k stars 2.98k forks source link

[Bug]: chezmoi fails to run scripts #12220

Closed VorpalBlade closed 1 year ago

VorpalBlade commented 1 year ago

Problem description

chezmoi installed from the official termux repositories fail to execute scripts. This is specific to the termux environment, and works fine on normal desktop Linux.

Based on a bug report in chezmoi this is a termux bug: https://github.com/twpayne/chezmoi/issues/2345

The issue seems to be that termux uses LD_PRELOAD hacks that don't take effect on programs written in Go. An alternative solution to enable full functionality on Termux is needed (as the upstream developer does not consider this a bug in chezmoi).

Steps to reproduce the behavior.

$ pkg install chezmoi
$ chezmoi init
$ chezmoi cd
$ echo "#!/usr/bin/env bash" > run_test.sh
$ echo "echo Hi" >> run_test.sh
$ chezmoi apply

What is the expected behavior?

The run_ script should execute, and in this case print "Hi"

Instead you will get an output like the following:

chezmoi: fork/exec /data/data/com.termux/files/usr/tmp/1634744225.test.sh: no such file or directory

System information

2096779623 commented 1 year ago

https://github.com/twpayne/chezmoi/issues/2345#issuecomment-1241338143

Grimler91 commented 1 year ago

Is it possible to use templates in scripts? If yes then something like

$ cat run_test.sh.tmpl
{{- if eq .chezmoi.os "android" }}
#!/data/data/com.termux/files/usr/bin/env bash
{{ else }}
#!/usr/bin/env bash
{{ end }}
echo Hi

could work. For it to work without such a workaround we would have to patch our golang and add the same functionality as we have in libtermux-exec.

Tangentially related: we have an open feature request for adding support for golang's "shebangs" (like //usr/bin/go run $0 $@ ; exit) over at https://github.com/termux/termux-exec/issues/22.

VorpalBlade commented 1 year ago

Ah, yes, It is possible to be even more elegant:

#!{{ lookPath "bash" }}
[ ... ]

That solves my immediate problem. However, that is specific to chezmoi. I don't know if there are any other Go programs that need to execute scripts that lack the template functionality. None that I use that I know of.