From 830f9fabd4a564bfbc3fbfc33a62b02010c0a7a5 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Thu, 27 Sep 2018 17:40:16 -0500 Subject: [PATCH 1/3] patch-shebangs: use isScript to safely check for shebang start Fixes commonly encountered errors about broken pipes or null-bytes in command-substitution. --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index d5586fccae6..0ac81102658 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -19,9 +19,8 @@ patchShebangs() { local newInterpreterLine find "$dir" -type f -perm -0100 | while read f; do - if [ "$(head -1 "$f" | head -c+2)" != '#!' ]; then - # missing shebang => not a script - continue + if ! isScript "$f"; then + continue fi oldInterpreterLine=$(head -1 "$f" | tail -c+3) From 286381f0727a5aee3413c24989ad5fb609653c49 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Fri, 28 Sep 2018 11:17:33 -0500 Subject: [PATCH 2/3] patch-shebangs: simplify a bit per reviewer suggestion --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 0ac81102658..18eb011b0c7 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -19,9 +19,7 @@ patchShebangs() { local newInterpreterLine find "$dir" -type f -perm -0100 | while read f; do - if ! isScript "$f"; then - continue - fi + isScript "$f" || continue oldInterpreterLine=$(head -1 "$f" | tail -c+3) read -r oldPath arg0 args <<< "$oldInterpreterLine" From f7db287960241736213c0f262ad655ce40cfc624 Mon Sep 17 00:00:00 2001 From: Will Dietz Date: Fri, 28 Sep 2018 11:21:51 -0500 Subject: [PATCH 3/3] patch-shebangs.sh: use more robust 'for each file' loop, check for dir The latter is to avoid warnings printed by find if it doesn't exist. --- pkgs/build-support/setup-hooks/patch-shebangs.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/setup-hooks/patch-shebangs.sh b/pkgs/build-support/setup-hooks/patch-shebangs.sh index 18eb011b0c7..d26bf735d30 100644 --- a/pkgs/build-support/setup-hooks/patch-shebangs.sh +++ b/pkgs/build-support/setup-hooks/patch-shebangs.sh @@ -18,7 +18,10 @@ patchShebangs() { local oldInterpreterLine local newInterpreterLine - find "$dir" -type f -perm -0100 | while read f; do + [ -e "$dir" ] || return 0 + + local f + while IFS= read -r -d $'\0' f; do isScript "$f" || continue oldInterpreterLine=$(head -1 "$f" | tail -c+3) @@ -58,7 +61,7 @@ patchShebangs() { rm "$f.timestamp" fi fi - done + done < <(find "$dir" -type f -perm -0100 -print0) stopNest }