From dbc0b5547ba2bb8673072adfdb4446152cfeec9e Mon Sep 17 00:00:00 2001 From: TomIO Date: Wed, 31 Jul 2024 14:06:54 +0200 Subject: [PATCH] fix(scripts/termux_step_install_license): fix logic error Move counter advance to the end of the while loop. This fixes a logic error where the counter wouldn't advance if the first license was "generic", and the second one was author specific. This would cause `cp` to attempt to copy through the dangling symlink to the generic license in `termux-licenses` which fails and dies. --- scripts/build/termux_step_install_license.sh | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scripts/build/termux_step_install_license.sh b/scripts/build/termux_step_install_license.sh index b9e7bc886d96a65..277a1193eefc424 100644 --- a/scripts/build/termux_step_install_license.sh +++ b/scripts/build/termux_step_install_license.sh @@ -60,29 +60,27 @@ termux_step_install_license() { else cp -f "${TERMUX_PKG_SRCDIR}/$FILE" "${TERMUX_PREFIX}/share/doc/${TERMUX_PKG_NAME}/copyright" fi - # since this is a post-increment, (( 0 )) would be falsey - # thus `set -e` would kill the script on the first iteration - # using `true` prevents this - : $(( COUNTER++ )) } done ;; # For the rest we can use a link to the generic license file *) [[ -f "$TERMUX_SCRIPTDIR/packages/termux-licenses/LICENSES/${LICENSE}.txt" ]] && { # the link target depends on the libc being used - if [[ "$TERMUX_PACKAGE_LIBRARY" == 'bionic' ]]; then - TO_LICENSE="../../LICENSES/${LICENSE}.txt" - elif [[ "$TERMUX_PACKAGE_LIBRARY" == 'glibc' ]]; then - TO_LICENSE="../../../../share/LICENSES/${LICENSE}.txt" - fi + case "$TERMUX_PACKAGE_LIBRARY" in + 'bionic') TO_LICENSE="../../LICENSES/${LICENSE}.txt";; + 'glibc') TO_LICENSE="../../../../share/LICENSES/${LICENSE}.txt";; + *) termux_error_exit "'$TERMUX_PACKAGE_LIBRARY' is not a supported libc";; + + esac if (( COUNTER )); then - ln -sf "$TO_LICENSE" "$TERMUX_PREFIX/share/doc/$TERMUX_PKG_NAME/copyright.$((COUNTER++))" + ln -sf "$TO_LICENSE" "$TERMUX_PREFIX/share/doc/$TERMUX_PKG_NAME/copyright.${COUNTER}" else ln -sf "$TO_LICENSE" "$TERMUX_PREFIX/share/doc/$TERMUX_PKG_NAME/copyright" fi } ;; esac + (( ++COUNTER )) done <<< "${TERMUX_PKG_LICENSE//,/$'\n'}" local license_files license_files="$(find -L "$TERMUX_PREFIX/share/doc/$TERMUX_PKG_NAME" -maxdepth 1 \( -type f -o -type l \) -name "copyright*")"