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
|
2016-10-27 13:17:02 +00:00
|
|
|
pyver="$(find ${PKGDESTDIR}/usr/lib/python* -prune -type d | grep -o '[[:digit:]]\.[[:digit:]]$')"
|
2016-10-16 14:46:46 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$pycompile_version" ]; then
|
|
|
|
pyver="$pycompile_version"
|
|
|
|
fi
|
|
|
|
|
2016-11-17 16:37:37 +00:00
|
|
|
if [ "$python_version" = "3" ]; then
|
|
|
|
pyver="$python_version"
|
|
|
|
fi
|
|
|
|
|
2016-10-16 14:46:46 +00:00
|
|
|
shebang="#!/usr/bin/python${pyver%.*}"
|
2017-04-17 06:49:06 +00:00
|
|
|
find "${PKGDESTDIR}" -type f -print0 | \
|
2019-12-28 04:50:24 +00:00
|
|
|
while IFS= read -r -d '' file; do
|
|
|
|
[ ! -s "$file" ] && continue
|
|
|
|
[ -z "$(sed -n -E -e 2q -e '/^#!.*([[:space:]]|\/)python([0-9]\.[0-9])?([[:space:]]+|$)/p' "$file")" ] && continue
|
|
|
|
echo " Shebang converted to '$shebang': ${file#$PKGDESTDIR}"
|
|
|
|
sed -i "1s@.*python.*@${shebang}@" -- "$file"
|
|
|
|
done
|
2016-03-21 19:30:39 +00:00
|
|
|
}
|