termux-packages/scripts/build/get_source/termux_extract_src_archive.sh
Henrik Grimler 4e902a41a5 building packages: create termux_step_get_source function
Calls termux_git_clone_src if TERMUX_PKG_SRCURL ends with .git, and
termux_download_src_archive and termux_extract_src_archive otherwise.
termux_step_extract_package has been split up into the latter two
functions.

termux_step_post_extract_package has been renamed to
termux_step_post_get_source to reflect these changes.
2020-07-21 10:14:00 +02:00

23 lines
816 B
Bash

termux_extract_src_archive() {
# STRIP=1 extracts archives straight into TERMUX_PKG_SRCDIR while STRIP=0 puts them in subfolders. zip has same behaviour per default
# If this isn't desired then this can be fixed in termux_step_post_get_source.
local STRIP=1
local PKG_SRCURL=(${TERMUX_PKG_SRCURL[@]})
local PKG_SHA256=(${TERMUX_PKG_SHA256[@]})
for i in $(seq 0 $(( ${#PKG_SRCURL[@]}-1 ))); do
local file="$TERMUX_PKG_CACHEDIR/$(basename "${PKG_SRCURL[$i]}")"
local folder
set +o pipefail
if [ "${file##*.}" = zip ]; then
folder=$(unzip -qql "$file" | head -n1 | tr -s ' ' | cut -d' ' -f5-)
rm -Rf $folder
unzip -q "$file"
mv $folder "$TERMUX_PKG_SRCDIR"
else
test "$i" -gt 0 && STRIP=0
tar xf "$file" -C "$TERMUX_PKG_SRCDIR" --strip-components=$STRIP
fi
set -o pipefail
done
}