summary refs log tree commit diff
path: root/pkgs/stdenv/generic
diff options
context:
space:
mode:
authorBjørn Forsman <bjorn.forsman@gmail.com>2014-01-03 13:55:41 +0100
committerBjørn Forsman <bjorn.forsman@gmail.com>2014-01-03 14:47:39 +0100
commitf4f0d2ecb96ee731cd1091c052afa50f0353bb94 (patch)
treeb3f30d6dd1c87dbbd6107dba4cc9942b0eaff242 /pkgs/stdenv/generic
parent86802e68ffd1981af92303a7a8a91a2723ca84ca (diff)
downloadnixlib-f4f0d2ecb96ee731cd1091c052afa50f0353bb94.tar
nixlib-f4f0d2ecb96ee731cd1091c052afa50f0353bb94.tar.gz
nixlib-f4f0d2ecb96ee731cd1091c052afa50f0353bb94.tar.bz2
nixlib-f4f0d2ecb96ee731cd1091c052afa50f0353bb94.tar.lz
nixlib-f4f0d2ecb96ee731cd1091c052afa50f0353bb94.tar.xz
nixlib-f4f0d2ecb96ee731cd1091c052afa50f0353bb94.tar.zst
nixlib-f4f0d2ecb96ee731cd1091c052afa50f0353bb94.zip
stdenv/setup.sh: fix breakage when shebang contains '\'
Some programs, e.g. guile-config, has a shebang that ends in '\':

  #!/usr/bin/guile-1.8 \
  -e main -s
  !#
  ;;;; guile-config --- utility for linking programs with Guile
  ;;;; Jim Blandy <jim@red-bean.com> --- September 1997

This currently breaks patchShebangs:

  $ read oldPath arg0 args <<< 'shebang \'; echo $?
  1
  $ echo $oldPath
  shebang
  $ echo $arg0

  $ echo $args

(And setup.sh/patchShebangs is run with 'set -e' so any command that
return non-zero aborts the build.)

Fix by telling 'read' to not interpret backslashes (with the -r flag):

  $ read -r oldPath arg0 args <<< 'shebang \'; echo $?
  0
  $ echo $oldPath
  shebang
  $ echo $arg0
  \
  $ echo $args

Also needed: escape the escape characters so that sed doesn't interpret
them.
Diffstat (limited to 'pkgs/stdenv/generic')
-rw-r--r--pkgs/stdenv/generic/setup.sh6
1 files changed, 4 insertions, 2 deletions
diff --git a/pkgs/stdenv/generic/setup.sh b/pkgs/stdenv/generic/setup.sh
index b7940a069ce7..58647f1508d1 100644
--- a/pkgs/stdenv/generic/setup.sh
+++ b/pkgs/stdenv/generic/setup.sh
@@ -677,7 +677,7 @@ patchShebangs() {
         fi
 
         oldInterpreterLine=$(head -1 "$f" | tail -c +3)
-        read oldPath arg0 args <<< "$oldInterpreterLine"
+        read -r oldPath arg0 args <<< "$oldInterpreterLine"
 
         if $(echo "$oldPath" | grep -q "/bin/env$"); then
             # Check for unsupported 'env' functionality:
@@ -703,7 +703,9 @@ patchShebangs() {
         if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then
             if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then
                 echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\""
-                sed -i -e "1 s|.*|#\!$newInterpreterLine|" "$f"
+                # escape the escape chars so that sed doesn't interpret them
+                escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g')
+                sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f"
             fi
         fi
     done