Skip to content

Commit

Permalink
fix(scripts/termux_step_install_license): fix logic error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TomJo2000 committed Aug 2, 2024
1 parent 2d7aa53 commit 9c28a98
Showing 1 changed file with 37 additions and 28 deletions.
65 changes: 37 additions & 28 deletions scripts/build/termux_step_install_license.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ termux_step_install_license() {
done <<< "${TERMUX_PKG_LICENSE_FILE//,/$'\n'}"
else # If a license file wasn't specified, find the one we need
local TO_LICENSE # link target for generic licenses
local FROM_SOURCES=0 # flag to check if we've included licenses from the source files yet
local COMMON_LICENSE_FILES=( # search list for licenses with copyright information
'COPYING' 'Copyright.txt'
'copyright' 'Copyright' 'COPYRIGHT'
Expand All @@ -52,35 +53,43 @@ termux_step_install_license() {
'BSD'|'BSD 2-Clause'|'BSD 3-Clause'|'BSD Simplified'\
|'curl'|'HPND'|'ISC'|'Libpng'|'MIT'|'Openfont-1.1'\
|'PythonPL'|'X11'|'ZLIB')
# Find the license file in the source files
for FILE in "${COMMON_LICENSE_FILES[@]}"; do
[[ -f "$TERMUX_PKG_SRCDIR/$FILE" ]] && {
if (( COUNTER )); then
cp -f "${TERMUX_PKG_SRCDIR}/$FILE" "${TERMUX_PREFIX}/share/doc/${TERMUX_PKG_NAME}/copyright.${COUNTER}"
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
# We only want to include the license files from the source files once
if (( ! FROM_SOURCES )); then
local FILE
# Find the license file(s) in the source files
for FILE in "${COMMON_LICENSE_FILES[@]}"; do
[[ -f "$TERMUX_PKG_SRCDIR/$FILE" ]] && {
if (( COUNTER )); then
cp -f "${TERMUX_PKG_SRCDIR}/$FILE" "${TERMUX_PREFIX}/share/doc/${TERMUX_PKG_NAME}/copyright.${COUNTER}"
else
cp -f "${TERMUX_PKG_SRCDIR}/$FILE" "${TERMUX_PREFIX}/share/doc/${TERMUX_PKG_NAME}/copyright"
fi
(( ++COUNTER, ++FROM_SOURCES ))
}
done
# If we have not found any licenses after searching, that's an error.
if (( ! FROM_SOURCES )); then
termux_error_exit "${TERMUX_PKG_NAME}: Could not find a license file for $LICENSE in the package sources"
fi
fi
;;
# 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
if (( COUNTER )); then
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
}
*) # For the rest we can use a link to the generic license file
[[ -f "$TERMUX_SCRIPTDIR/packages/termux-licenses/LICENSES/${LICENSE}.txt" ]] || {
# If we get here, no license file could be found
termux_error_exit "${TERMUX_PKG_NAME}: Could not find a license file for $LICENSE in packages/termux-licenses"
}
# the link target depends on the libc being used
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}"
else
ln -sf "$TO_LICENSE" "$TERMUX_PREFIX/share/doc/$TERMUX_PKG_NAME/copyright"
fi
(( ++COUNTER ))
;;
esac
done <<< "${TERMUX_PKG_LICENSE//,/$'\n'}"
Expand Down

0 comments on commit 9c28a98

Please sign in to comment.