2016-03-21 19:30:39 +00:00
|
|
|
# This hook executes the following tasks:
|
|
|
|
# - rewrites python shebangs with the corresponding python version
|
|
|
|
|
|
|
|
hook() {
|
2016-10-16 14:46:46 +00:00
|
|
|
local pyver= shebang= off=
|
2016-03-21 19:30:39 +00:00
|
|
|
|
2016-10-16 14:46:46 +00:00
|
|
|
: ${pyver:=2}
|
2016-03-21 19:30:39 +00:00
|
|
|
|
2016-10-16 14:46:46 +00:00
|
|
|
if [ -d ${PKGDESTDIR}/usr/lib/python* ]; then
|
|
|
|
pycompile_version="$(find ${PKGDESTDIR}/usr/lib/python* -type d | grep -o '[[:digit:]]\.[[:digit:]]$')"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$pycompile_version" ]; then
|
|
|
|
pyver="$pycompile_version"
|
|
|
|
fi
|
|
|
|
|
|
|
|
shebang="#!/usr/bin/python${pyver%.*}"
|
2016-03-21 19:30:39 +00:00
|
|
|
find ${PKGDESTDIR} -type f -print0 | \
|
2016-10-16 14:46:46 +00:00
|
|
|
xargs -0 grep -H -b -m 1 "^#!.*\([[:space:]]\|/\)python\([[:space:]]*\|$\)" -- | while IFS=: read -r f off _; do
|
2016-04-17 15:12:14 +00:00
|
|
|
[ -z "$off" ] && continue
|
2016-10-16 14:46:46 +00:00
|
|
|
echo " Shebang converted to '$shebang': ${f#$PKGDESTDIR}"
|
|
|
|
sed -i "1s@.*python.*@${shebang}@" -- "$f"
|
2016-03-21 19:30:39 +00:00
|
|
|
done
|
|
|
|
}
|