From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: avoid wrapper scripts when possible Date: Fri, 03 Nov 2017 22:17:19 +0100 Message-ID: <8760argizk.fsf@elephly.net> References: <87mv44gyfv.fsf@elephly.net> <20171103185416.0ffc4065@cbaines.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55162) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBGv2-00005Z-ER for guix-devel@gnu.org; Sun, 05 Nov 2017 04:08:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBGv0-0002lZ-1V for guix-devel@gnu.org; Sun, 05 Nov 2017 04:08:40 -0500 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21085) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBGuz-0002lS-Qv for guix-devel@gnu.org; Sun, 05 Nov 2017 04:08:37 -0500 In-reply-to: <20171103185416.0ffc4065@cbaines.net> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: Christopher Baines Cc: guix-devel@gnu.org Christopher Baines 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=E2=80=99s =E2=80=9Cactivate=E2=80=9D script there woul= d 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=E2=80=99s a way to have a script header that starts out a= s 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/bi= n/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 =E2=80=9Chello from bash=E2=80=9D. Then it scrubs it= self off the script and removes the original script=E2=80=99s Python shebang using tail = (with =E2=80=9C-n +4=E2=80=9D 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=E2=80=99t thi= nk of a situation where this would fail =E2=80=94 unless the wrapped script perfo= rmed 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 =E2=80=9Cfile=E2=80=9D would be rather confus= ed about these scripts, but maybe that=E2=80=99s acceptable. -- Ricardo GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC https://elephly.net