From 63b7c6c1f82486604abd6e3b6a6e14643d1f6621 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sun, 14 Apr 2013 17:17:19 +0200 Subject: [PATCH] gnu: automake: Restore shebangs on files that end up in user tarballs. * gnu/packages/autotools.scm (automake): Add `unpatch-shebangs' phase. --- gnu/packages/autotools.scm | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/gnu/packages/autotools.scm b/gnu/packages/autotools.scm index bc4dddc01f..51aadbf0ec 100644 --- a/gnu/packages/autotools.scm +++ b/gnu/packages/autotools.scm @@ -151,6 +151,11 @@ exec ~a --no-auto-compile \"$0\" \"$@\" ,(search-patch "automake-skip-amhello-tests.patch")))) (arguments '(#:patches (list (assoc-ref %build-inputs "patch/skip-amhello")) + #:modules ((guix build gnu-build-system) + (guix build utils) + (srfi srfi-1) + (srfi srfi-26) + (rnrs io ports)) #:phases (alist-cons-before 'patch-source-shebangs 'patch-tests-shebangs (lambda _ @@ -163,7 +168,35 @@ exec ~a --no-auto-compile \"$0\" \"$@\" ;; that occur during the test suite. (setenv "SHELL" sh) (setenv "CONFIG_SHELL" sh))) - %standard-phases))) + + ;; Files like `install-sh', `mdate.sh', etc. must use + ;; #!/bin/sh, otherwise users could leak erroneous shebangs + ;; in the wild. See for an + ;; example. + (alist-cons-after + 'install 'unpatch-shebangs + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out")) + (dir (string-append out "/share"))) + (define (starts-with-shebang? file) + (equal? (call-with-input-file file + (lambda (p) + (list (get-u8 p) (get-u8 p)))) + (map char->integer '(#\# #\!)))) + + (for-each (lambda (file) + (when (and (starts-with-shebang? file) + (executable-file? file)) + (format #t "restoring shebang on `~a'~%" + file) + (substitute* file + (("^#!.*/bin/sh") + "#!/bin/sh") + (("^#!.*/bin/env(.*)$" _ args) + (string-append "#!/usr/bin/env" + args))))) + (find-files dir ".*")))) + %standard-phases)))) (home-page "http://www.gnu.org/software/automake/") (synopsis "GNU Automake, a GNU standard-compliant makefile generator")