aboutsummaryrefslogtreecommitdiffstats
path: root/brp-mangle-shebangs
diff options
context:
space:
mode:
Diffstat (limited to 'brp-mangle-shebangs')
-rwxr-xr-xbrp-mangle-shebangs21
1 files changed, 14 insertions, 7 deletions
diff --git a/brp-mangle-shebangs b/brp-mangle-shebangs
index 4964c09..f27ad73 100755
--- a/brp-mangle-shebangs
+++ b/brp-mangle-shebangs
@@ -1,4 +1,4 @@
-#!/bin/bash -eu
+#!/usr/bin/bash -eu
# If using normal root, avoid changing anything.
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
@@ -76,7 +76,7 @@ cd "$RPM_BUILD_ROOT"
# (Take care to exclude filenames which would mangle "file" output).
find -executable -type f ! -path '*:*' ! -path $'*\n*' \
| file -N --mime-type -f - \
-| grep -P ".+(?=: text/)" \
+| grep -P ".+(?=: (text/|application/javascript))" \
| {
fail=0
while IFS= read -r line; do
@@ -93,7 +93,14 @@ while IFS= read -r line; do
fi
- read shebang_line < "$f" ||:
+ if ! read shebang_line < "$f"; then
+ echo >&2 "*** WARNING: Cannot read the first line from $f, removing executable bit"
+ ts=$(stat -c %y "$f")
+ chmod -x "$f"
+ touch -d "$ts" "$f"
+ continue
+ fi
+
orig_shebang="${shebang_line#\#!}"
if [ "$orig_shebang" = "$shebang_line" ]; then
echo >&2 "*** WARNING: $f is executable but has no shebang, removing executable bit"
@@ -130,10 +137,10 @@ while IFS= read -r line; do
fi
# Replace "special" env shebang:
- # /whatsoever/env /whatever/foo → /whatever/foo
- shebang=$(echo "$shebang" | sed -r -e 's@^(.+)/env /(.+)$@/\2@')
- # /whatsoever/env foo → /whatsoever/foo
- shebang=$(echo "$shebang" | sed -r -e 's@^(.+/)env (.+)$@\1\2@')
+ # /whatsoever/env -whatever /whatever/foo → /whatever/foo
+ shebang=$(echo "$shebang" | sed -r -e 's@^(.+)/env( -[^ ]+)* /(.+)$@/\3@')
+ # /whatsoever/env -whatever foo → /whatsoever/foo
+ shebang=$(echo "$shebang" | sed -r -e 's@^(.+/)env( -[^ ]+)* (.+)$@\1\3@')
# If the shebang now starts with /bin, change it to /usr/bin
# https://bugzilla.redhat.com/show_bug.cgi?id=1581757