hooks/rewrite-python-shebang: simplify and check for unset $off correctly.

This commit is contained in:
Juan RP 2016-04-17 17:12:14 +02:00
parent 947966bd76
commit 054a73caf2

View file

@ -2,7 +2,7 @@
# - rewrites python shebangs with the corresponding python version # - rewrites python shebangs with the corresponding python version
hook() { hook() {
local pyver= shebang= warn= local pyver= shebang= warn= off=
case $pkgname in case $pkgname in
python-*) python-*)
@ -26,11 +26,10 @@ hook() {
shebang="#!/usr/bin/python$pyver" shebang="#!/usr/bin/python$pyver"
find ${PKGDESTDIR} -type f -print0 | \ find ${PKGDESTDIR} -type f -print0 | \
xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]\|$\)" -- | while IFS=: read -r f off _; do xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]\|$\)" -- | while IFS=: read -r f off _; do
[ "$off" -a "$off" -eq 0 ] || continue [ -z "$off" ] && continue
if [ "$warn" ]; then if [ "$warn" ]; then
msg_warn "$pkgname: multiple python versions defined!" msg_warn "$pkgver: multiple python versions defined! (using $pyver for shebangs)\n"
msg_warn "$pkgname: using $pyver for shebang" unset warn
warn=
fi fi
echo " Unversioned shebang replaced by '$shebang': ${f#$PKGDESTDIR}" echo " Unversioned shebang replaced by '$shebang': ${f#$PKGDESTDIR}"
sed -i "1s@.*python@${shebang}@" -- "$f" sed -i "1s@.*python@${shebang}@" -- "$f"