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
|
|
|
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
|
|
|
|
|
2020-04-21 18:55:14 +00:00
|
|
|
if [ -n "$python_version" ]; then
|
|
|
|
pyver="$python_version"
|
2016-10-16 14:46:46 +00:00
|
|
|
fi
|
|
|
|
|
2020-04-21 18:55:14 +00:00
|
|
|
if [ -n "$pyver" ]; then
|
2020-06-09 02:36:59 +00:00
|
|
|
default_shebang="#!/usr/bin/python${pyver%.*}"
|
2016-11-17 16:37:37 +00:00
|
|
|
fi
|
|
|
|
|
2021-01-27 23:42:31 +00:00
|
|
|
grep -rlIZ -m1 '^#!.*python' "${PKGDESTDIR}" |
|
2019-12-28 04:50:24 +00:00
|
|
|
while IFS= read -r -d '' file; do
|
|
|
|
[ ! -s "$file" ] && continue
|
2020-06-09 02:36:59 +00:00
|
|
|
|
2020-06-17 00:00:09 +00:00
|
|
|
pyinterp=$(sed -n -E -e 2q -e 's@^#!.*([[:space:]]|/)(python([0-9](\.[0-9]+)?)?)([[:space:]]+.*|$)@\2@p' "$file")
|
2020-06-09 02:36:59 +00:00
|
|
|
[ -z "$pyinterp" ] && continue
|
|
|
|
|
|
|
|
pyver=${pyinterp#python}
|
|
|
|
if [ -n "$pyver" ]; then
|
|
|
|
shebang="#!/usr/bin/python${pyver%.*}"
|
|
|
|
else
|
|
|
|
shebang="$default_shebang"
|
|
|
|
fi
|
|
|
|
|
|
|
|
basefile=${file#$PKGDESTDIR}
|
|
|
|
|
|
|
|
[ -n "$shebang" ] || msg_error "python_version missing in template: unable to convert shebang in $basefile\n"
|
|
|
|
|
|
|
|
echo " Shebang converted to '$shebang': $basefile"
|
2019-12-28 04:50:24 +00:00
|
|
|
sed -i "1s@.*python.*@${shebang}@" -- "$file"
|
|
|
|
done
|
2016-03-21 19:30:39 +00:00
|
|
|
}
|