2016-03-21 20:30:39 +01:00
|
|
|
# This hook executes the following tasks:
|
|
|
|
# - rewrites python shebangs with the corresponding python version
|
|
|
|
|
|
|
|
hook() {
|
2016-10-16 16:46:46 +02:00
|
|
|
local pyver= shebang= off=
|
2016-03-21 20:30:39 +01:00
|
|
|
|
2016-10-16 16:46:46 +02:00
|
|
|
if [ -d ${PKGDESTDIR}/usr/lib/python* ]; then
|
2016-10-27 15:17:02 +02:00
|
|
|
pyver="$(find ${PKGDESTDIR}/usr/lib/python* -prune -type d | grep -o '[[:digit:]]\.[[:digit:]]$')"
|
2016-10-16 16:46:46 +02:00
|
|
|
fi
|
|
|
|
|
2020-04-21 20:55:14 +02:00
|
|
|
if [ -n "$python_version" ]; then
|
|
|
|
pyver="$python_version"
|
2016-10-16 16:46:46 +02:00
|
|
|
fi
|
|
|
|
|
2020-04-21 20:55:14 +02:00
|
|
|
if [ -n "$pyver" ]; then
|
2020-06-09 04:36:59 +02:00
|
|
|
default_shebang="#!/usr/bin/python${pyver%.*}"
|
2016-11-17 17:37:37 +01:00
|
|
|
fi
|
|
|
|
|
2021-01-28 00:42:31 +01:00
|
|
|
grep -rlIZ -m1 '^#!.*python' "${PKGDESTDIR}" |
|
2019-12-28 05:50:24 +01:00
|
|
|
while IFS= read -r -d '' file; do
|
|
|
|
[ ! -s "$file" ] && continue
|
2020-06-09 04:36:59 +02:00
|
|
|
|
2020-06-17 02:00:09 +02:00
|
|
|
pyinterp=$(sed -n -E -e 2q -e 's@^#!.*([[:space:]]|/)(python([0-9](\.[0-9]+)?)?)([[:space:]]+.*|$)@\2@p' "$file")
|
2020-06-09 04:36:59 +02: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 05:50:24 +01:00
|
|
|
sed -i "1s@.*python.*@${shebang}@" -- "$file"
|
|
|
|
done
|
2016-03-21 20:30:39 +01:00
|
|
|
}
|