diff --git a/brp-mangle-shebangs b/brp-mangle-shebangs index 9869003..53038a5 100755 --- a/brp-mangle-shebangs +++ b/brp-mangle-shebangs @@ -5,6 +5,9 @@ if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then exit 0 fi +exclude_files="${1:-}" +exclude_shebangs="${2:-}" + cd "$RPM_BUILD_ROOT" trim() { @@ -14,10 +17,21 @@ trim() { fail=0 for f in $(find -executable -type f | xargs --no-run-if-empty file -N --mime-type | grep -Po "^\K.+(?=: text/)"); do + # Remove the dot + path="${f#.}" + + if [ -n "$exclude_files" ]; then + echo "$path" | grep -q -E "$exclude_files" && continue + fi + ts=$(stat -c %y "$f") read orig_shebang < "$f" || : shebang=$(trim $(echo "$orig_shebang" | grep -Po "#!\K.*" || echo)) + if [ -n "$exclude_shebangs" ]; then + echo "$shebang" | grep -q -E "$exclude_shebangs" && continue + fi + if [ -z "$shebang" ]; then echo >&2 "*** WARNING: $f is executable but has empty or no shebang, removing executable bit" chmod -x "$f" @@ -44,10 +58,10 @@ for f in $(find -executable -type f | xargs --no-run-if-empty file -N --mime-typ if [ "$shebang" != "$py_shebang" ]; then sed -i -e "1c #!$py_shebang" "$f" - echo >&2 "*** WARNING: mangling shebang in $f from $orig_shebang to #!$py_shebang. This will become an ERROR, fix it manually!" + echo >&2 "*** WARNING: mangling shebang in $path from $orig_shebang to #!$py_shebang. This will become an ERROR, fix it manually!" elif [ "#!$shebang" != "$orig_shebang" ]; then sed -i -e "1c #!$shebang" "$f" - echo "mangling shebang in $f from $orig_shebang to #!$shebang" + echo "mangling shebang in $path from $orig_shebang to #!$shebang" fi touch -d "$ts" "$f" diff --git a/macros b/macros index 04828f3..1e42466 100644 --- a/macros +++ b/macros @@ -143,7 +143,7 @@ %__brp_strip_static_archive /usr/lib/rpm/brp-strip-static-archive %{__strip} %__brp_python_bytecompile /usr/lib/rpm/brp-python-bytecompile %{__python} %{?_python_bytecompile_errors_terminate_build} %__brp_python_hardlink /usr/lib/rpm/brp-python-hardlink -%__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs +%__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs "%{?__brp_mangle_shebangs_exclude_from}" "%{?__brp_mangle_shebangs_exclude}" %__os_install_post \ %{?__brp_ldconfig} \ diff --git a/redhat-rpm-config.spec b/redhat-rpm-config.spec index 0f4a4e0..ef9161c 100644 --- a/redhat-rpm-config.spec +++ b/redhat-rpm-config.spec @@ -6,7 +6,7 @@ Summary: Red Hat specific rpm configuration files Name: redhat-rpm-config -Version: 96 +Version: 97 Release: 1%{?dist} # No version specified. License: GPL+ @@ -183,6 +183,9 @@ install -p -m 755 -t %{buildroot}%{_rpmconfigdir} kmod.prov %{_rpmconfigdir}/macros.d/macros.kmp %changelog +* Wed Feb 14 2018 Miro HronĨok - 97-1 +- Allow to opt-out from shebang mangling for specific paths/shebangs + * Thu Feb 08 2018 Igor Gnatenko - 96-1 - Simplify/Fix check for shebang starting with "/"