diff options
Diffstat (limited to 'common/hooks/pre-pkg/03-rewrite-python-shebang.sh')
-rw-r--r-- | common/hooks/pre-pkg/03-rewrite-python-shebang.sh | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/common/hooks/pre-pkg/03-rewrite-python-shebang.sh b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh new file mode 100644 index 00000000000..cdd608f4b46 --- /dev/null +++ b/common/hooks/pre-pkg/03-rewrite-python-shebang.sh @@ -0,0 +1,36 @@ +# This hook executes the following tasks: +# - rewrites python shebangs with the corresponding python version + +hook() { + local pyver= shebang= warn= + + case $pkgname in + python-*) + pyver=2.7;; + python3.4-*) + pyver=3.4;; + *) + for i in $python_versions; do + if [ "$pyver" ]; then + warn=1 + break; + fi + pyver=$i + done + : ${pyver:=2.7} + ;; + esac + + shebang="#!/usr/bin/python$pyver" + find ${PKGDESTDIR} -type f -print0 | \ + xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]\|$\)" -- | while IFS=: read -r f off _; do + [ "$off" -eq 0 ] || continue + 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 +} |