From 830ca266448dd9436cb3b8e16da46f8b255c7c47 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Mon, 21 Mar 2016 20:30:39 +0100 Subject: [PATCH 1/2] hooks/post-install: add hook to rewrite unversioned python shebangs. --- .../post-install/07-rewrite-python-shebang.sh | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 common/hooks/post-install/07-rewrite-python-shebang.sh diff --git a/common/hooks/post-install/07-rewrite-python-shebang.sh b/common/hooks/post-install/07-rewrite-python-shebang.sh new file mode 100644 index 00000000000..06c94dddecb --- /dev/null +++ b/common/hooks/post-install/07-rewrite-python-shebang.sh @@ -0,0 +1,27 @@ +# This hook executes the following tasks: +# - rewrites python shebangs with the corresponding python version + +hook() { + local pyver= shebang= warn= + + for i in $python_versions; do + if [ "$pyver" ]; then + warn=1 + break; + fi + pyver=$i + done + + : ${pyver:=2.7} + shebang="#!/usr/bin/python$pyver" + find ${PKGDESTDIR} -type f -print0 | \ + xargs -0 grep -l -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]\|$\)" -- | while read f; do + if [ "$warn" ]; then + msg_warn "$pkgname: multiple python versions defined!" + msg_warn "$pkgname: using $pyver for shebang" + warn= + fi + echo " Unversioned shebang replaced by '$shebang': ${f#$PKGDESTDIR}" + sed -i "1s@.*python@${shebang}@" -- "$f" + done +} From eb2621ca460ab5f503c5c03a7ef9895a4bef58f1 Mon Sep 17 00:00:00 2001 From: Enno Boland Date: Tue, 22 Mar 2016 09:03:06 +0100 Subject: [PATCH 2/2] hooks/post-install/07-rewrite-python-shebang.sh: use IFS and -r for read. cc @chneukirchen --- common/hooks/post-install/07-rewrite-python-shebang.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/hooks/post-install/07-rewrite-python-shebang.sh b/common/hooks/post-install/07-rewrite-python-shebang.sh index 06c94dddecb..04436409546 100644 --- a/common/hooks/post-install/07-rewrite-python-shebang.sh +++ b/common/hooks/post-install/07-rewrite-python-shebang.sh @@ -15,7 +15,7 @@ hook() { : ${pyver:=2.7} shebang="#!/usr/bin/python$pyver" find ${PKGDESTDIR} -type f -print0 | \ - xargs -0 grep -l -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]\|$\)" -- | while read f; do + xargs -0 grep -l -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]\|$\)" -- | while IFS= read -r f; do if [ "$warn" ]; then msg_warn "$pkgname: multiple python versions defined!" msg_warn "$pkgname: using $pyver for shebang"