enhance(scripts): add TERMUX_PKG_NO_SHEBANG_FIX_FILES

This commit is contained in:
Jia Yuan Lo 2023-10-27 18:24:00 +08:00
parent 85cd5b5a45
commit b7b9bb184d
2 changed files with 17 additions and 1 deletions

View File

@ -61,9 +61,25 @@ termux_step_massage() {
fi
fi
local pattern=""
for file in ${TERMUX_PKG_NO_SHEBANG_FIX_FILES}; do
if [[ -z "${pattern}" ]]; then
pattern="${file}"
continue
fi
pattern+='|'"${file}"
done
if [[ -n "${pattern}" ]]; then
pattern='(|./)('"${pattern}"')$'
fi
if [ "$TERMUX_PKG_NO_SHEBANG_FIX" != "true" ]; then
# Fix shebang paths:
while IFS= read -r -d '' file; do
if [[ -n "${pattern}" ]] && [[ -n "$(echo "${file}" | grep -E "${pattern}")" ]]; then
echo "INFO: Skip shebang fix for ${file}"
continue
fi
if head -c 100 "$file" | head -n 1 | grep -E "^#!.*/bin/.*" | grep -q -E -v -e "^#! ?/system" -e "^#! ?$TERMUX_PREFIX_CLASSICAL"; then
sed --follow-symlinks -i -E "1 s@^#\!(.*)/bin/(.*)@#\!$TERMUX_PREFIX/bin/\2@" "$file"
fi

View File

@ -158,6 +158,7 @@ termux_step_setup_variables() {
TERMUX_PKG_METAPACKAGE=false
TERMUX_PKG_NO_ELF_CLEANER=false # set this to true to disable running of termux-elf-cleaner on built binaries
TERMUX_PKG_NO_SHEBANG_FIX=false # if true, skip fixing shebang accordingly to TERMUX_PREFIX
TERMUX_PKG_NO_SHEBANG_FIX_FILES="" # files to be excluded from fixing shebang
TERMUX_PKG_NO_STRIP=false # set this to true to disable stripping binaries
TERMUX_PKG_NO_STATICSPLIT=false
TERMUX_PKG_STATICSPLIT_EXTRA_PATTERNS=""
@ -175,7 +176,6 @@ termux_step_setup_variables() {
TERMUX_PKG_TMPDIR=$TERMUX_TOPDIR/$TERMUX_PKG_NAME/tmp
TERMUX_PKG_SERVICE_SCRIPT=() # Fill with entries like: ("daemon name" 'script to execute'). Script is echoed with -e so can contain \n for multiple lines
TERMUX_PKG_GROUPS="" # https://wiki.archlinux.org/title/Pacman#Installing_package_groups
TERMUX_PKG_NO_SHEBANG_FIX=false # if true, skip fixing shebang accordingly to TERMUX_PREFIX
TERMUX_PKG_ON_DEVICE_BUILD_NOT_SUPPORTED=false # if the package does not support compilation on a device, then this package should not be compiled on devices
TERMUX_PKG_SETUP_PYTHON=false # setting python to compile a package
TERMUX_PYTHON_VERSION=$(. $TERMUX_SCRIPTDIR/packages/python/build.sh; echo $_MAJOR_VERSION) # get the latest version of python