guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: avoid wrapper scripts when possible


From: Ricardo Wurmus
Subject: Re: avoid wrapper scripts when possible
Date: Fri, 03 Nov 2017 22:17:19 +0100
User-agent: mu4e 0.9.18; emacs 25.3.1

Christopher Baines <address@hidden> writes:

> However, I think that the file wrapping approach has advantages for
> visibility. Maybe it could be tweaked to keep ensure the wrapper script
> has the same name as the script its wrapping, e.g. when wrapping foo,
> replace foo with a bash script, and move the real script
> to .wrapped-bin/foo.

I agree that having a separate wrapper is certainly nicer than patching
upstream scripts automatically.  The idea of moving original scripts out
of the way sounds intriguing, but I fear that we would have a similar
set of problems.

In the case of conda’s “activate” script there would be an obvious
problem: the script tries to determine the directory that contains it.
If that were a different directory than the one the developers intended,
it would fail in unexpected ways.

I wonder if there’s a way to have a script header that starts out as a
shell script and then calls itself again but skipping over the header,
thus calling the original script.

Take this Python script as an example:

--8<---------------cut here---------------start------------->8---
#!/home/rekado/.guix-profile/bin/python
print("hello from python")
--8<---------------cut here---------------end--------------->8---

We then prepend this header:

--8<---------------cut here---------------start------------->8---
#!/run/current-system/profile/bin/bash
echo "hello from bash"
exec /home/rekado/.guix-profile/bin/python 
<(/run/current-system/profile/bin/tail -n +4 "$0")
--8<---------------cut here---------------end--------------->8---

When we execute the resulting thing it will be a shell script, and do
shell things printing “hello from bash”.  Then it scrubs itself off the
script and removes the original script’s Python shebang using tail (with
“-n +4” where 4 is the number of lines of the shell script header + 1),
and replaces itself with Python calling the original script.

This seems to work just fine and off the top of my head I can’t think of
a situation where this would fail — unless the wrapped script performed
the same kind of trick of reading its contents through $0.  (How likely
is that?)

What do you think?  Is this too weird to consider?  Weirder than
renaming binaries and replacing them with scripts?

One side effect would be that “file” would be rather confused about
these scripts, but maybe that’s acceptable.

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net





reply via email to

[Prev in Thread] Current Thread [Next in Thread]