Add brp-mangle-shebangs
This commit is contained in:
parent
1591a6fbf8
commit
257a3a95c7
54
brp-mangle-shebangs
Executable file
54
brp-mangle-shebangs
Executable file
@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/sh -eu
|
||||||
|
|
||||||
|
# If using normal root, avoid changing anything.
|
||||||
|
if [ -z "$RPM_BUILD_ROOT" -o "$RPM_BUILD_ROOT" = "/" ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
cd "$RPM_BUILD_ROOT"
|
||||||
|
|
||||||
|
trim() {
|
||||||
|
printf '%s' "$*"
|
||||||
|
}
|
||||||
|
|
||||||
|
fail=0
|
||||||
|
for f in $(find -executable -type f | xargs --no-run-if-empty file -N --mime-type | grep -Po "^\K.+(?=: text/)"); do
|
||||||
|
|
||||||
|
ts=$(stat -c %y "$f")
|
||||||
|
|
||||||
|
read orig_shebang < "$f" || :
|
||||||
|
shebang=$(trim $(echo "$orig_shebang" | grep -Po "#!\K.*" || echo))
|
||||||
|
if [ -z "$shebang" ]; then
|
||||||
|
echo >&2 "*** WARNING: $f is executable but has empty or no shebang, removing executable bit"
|
||||||
|
chmod -x "$f"
|
||||||
|
touch -d "$ts" "$f"
|
||||||
|
continue
|
||||||
|
elif [ "${shebang%${shebang#?}}" != "/" ]; then
|
||||||
|
echo >&2 "*** ERROR: $f has shebang which doesn't start with '/' ($shebang)"
|
||||||
|
fail=1
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! { echo "$shebang" | grep -q -P "^/(?:usr/)?(?:bin|sbin)/"; }; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Replace "special" env shebang:
|
||||||
|
# /whatsoever/env foo → /whatsoever/foo
|
||||||
|
shebang=$(echo "$shebang" | sed -r -e 's@^(.+/)env (.+)$@\1\2@')
|
||||||
|
|
||||||
|
# Replace ambiguous python with python2
|
||||||
|
py_shebang=$(echo "$shebang" | sed -r -e 's@/usr/bin/python(\s|$)@/usr/bin/python2\1@')
|
||||||
|
|
||||||
|
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!"
|
||||||
|
elif [ "#!$shebang" != "$orig_shebang" ]; then
|
||||||
|
sed -i -e "1c #!$shebang" "$f"
|
||||||
|
echo "mangling shebang in $f from $orig_shebang to #!$shebang"
|
||||||
|
fi
|
||||||
|
|
||||||
|
touch -d "$ts" "$f"
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $fail
|
2
macros
2
macros
@ -107,6 +107,7 @@
|
|||||||
%__brp_strip_static_archive /usr/lib/rpm/brp-strip-static-archive %{__strip}
|
%__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_bytecompile /usr/lib/rpm/brp-python-bytecompile %{__python} %{?_python_bytecompile_errors_terminate_build}
|
||||||
%__brp_python_hardlink /usr/lib/rpm/brp-python-hardlink
|
%__brp_python_hardlink /usr/lib/rpm/brp-python-hardlink
|
||||||
|
%__brp_mangle_shebangs /usr/lib/rpm/redhat/brp-mangle-shebangs
|
||||||
|
|
||||||
%__os_install_post \
|
%__os_install_post \
|
||||||
%{?__brp_ldconfig} \
|
%{?__brp_ldconfig} \
|
||||||
@ -118,6 +119,7 @@
|
|||||||
%{?__brp_strip_static_archive} \
|
%{?__brp_strip_static_archive} \
|
||||||
%{?py_auto_byte_compile:%{?__brp_python_bytecompile}} \
|
%{?py_auto_byte_compile:%{?__brp_python_bytecompile}} \
|
||||||
%{?__brp_python_hardlink} \
|
%{?__brp_python_hardlink} \
|
||||||
|
%{?__brp_mangle_shebangs} \
|
||||||
%{nil}
|
%{nil}
|
||||||
|
|
||||||
%__spec_install_post\
|
%__spec_install_post\
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
Summary: Red Hat specific rpm configuration files
|
Summary: Red Hat specific rpm configuration files
|
||||||
Name: redhat-rpm-config
|
Name: redhat-rpm-config
|
||||||
Version: 89
|
Version: 90
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
# No version specified.
|
# No version specified.
|
||||||
License: GPL+
|
License: GPL+
|
||||||
@ -42,6 +42,12 @@ Source152: macros.vpath
|
|||||||
Source153: macros.forge
|
Source153: macros.forge
|
||||||
Source154: macros.ldconfig
|
Source154: macros.ldconfig
|
||||||
|
|
||||||
|
# Build policy scripts
|
||||||
|
# this comes from https://github.com/rpm-software-management/rpm/pull/344
|
||||||
|
# added a python -> python2 conversion for fedora with warning
|
||||||
|
# and an echo when the mangling happens
|
||||||
|
Source201: brp-mangle-shebangs
|
||||||
|
|
||||||
# Dependency generator scripts (deprecated)
|
# Dependency generator scripts (deprecated)
|
||||||
Source300: find-provides
|
Source300: find-provides
|
||||||
Source301: find-provides.ksyms
|
Source301: find-provides.ksyms
|
||||||
@ -122,6 +128,7 @@ install -p -m 444 -t %{buildroot}%{rrcdir} redhat-hardened-*
|
|||||||
install -p -m 444 -t %{buildroot}%{rrcdir} redhat-annobin-*
|
install -p -m 444 -t %{buildroot}%{rrcdir} redhat-annobin-*
|
||||||
install -p -m 755 -t %{buildroot}%{rrcdir} config.*
|
install -p -m 755 -t %{buildroot}%{rrcdir} config.*
|
||||||
install -p -m 755 -t %{buildroot}%{rrcdir} dist.sh rpmsort symset-table kmodtool
|
install -p -m 755 -t %{buildroot}%{rrcdir} dist.sh rpmsort symset-table kmodtool
|
||||||
|
install -p -m 755 -t %{buildroot}%{rrcdir} brp-*
|
||||||
|
|
||||||
install -p -m 755 -t %{buildroot}%{rrcdir} find-*
|
install -p -m 755 -t %{buildroot}%{rrcdir} find-*
|
||||||
mkdir -p %{buildroot}%{rrcdir}/find-provides.d
|
mkdir -p %{buildroot}%{rrcdir}/find-provides.d
|
||||||
@ -140,6 +147,7 @@ install -p -m 755 -t %{buildroot}%{_rpmconfigdir} kmod.prov
|
|||||||
%dir %{rrcdir}
|
%dir %{rrcdir}
|
||||||
%{rrcdir}/macros
|
%{rrcdir}/macros
|
||||||
%{rrcdir}/rpmrc
|
%{rrcdir}/rpmrc
|
||||||
|
%{rrcdir}/brp-*
|
||||||
%{rrcdir}/dist.sh
|
%{rrcdir}/dist.sh
|
||||||
%{rrcdir}/redhat-hardened-*
|
%{rrcdir}/redhat-hardened-*
|
||||||
%{rrcdir}/redhat-annobin-*
|
%{rrcdir}/redhat-annobin-*
|
||||||
@ -168,6 +176,9 @@ install -p -m 755 -t %{buildroot}%{_rpmconfigdir} kmod.prov
|
|||||||
%{_rpmconfigdir}/macros.d/macros.kmp
|
%{_rpmconfigdir}/macros.d/macros.kmp
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Jan 29 2018 Miro Hrončok <mhroncok@redhat.com> - 90-1
|
||||||
|
- Add brp-mangle-shebangs
|
||||||
|
|
||||||
* Mon Jan 29 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 89-1
|
* Mon Jan 29 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 89-1
|
||||||
- Add macros.ldconfig
|
- Add macros.ldconfig
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user