|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
#
|
|
Lucio Andrés Illanes Albornoz |
e1d469 |
# set +o errexit -o noglob -o nounset is assumed.
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
#
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
|
|
Lucio Andrés Illanes Albornoz |
63d19c |
rtlp_fetch_url_git() {
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
local _tgtdir="${1}" _subdir="${2}" _url="${3}" _branch="${4}" \
|
|
Lucio Andrés Illanes Albornoz |
907bd3 |
_oldpwd="";
|
|
Lucio Andrés Illanes Albornoz |
e1d469 |
(set -o errexit -o noglob -o nounset;
|
|
Lucio Andrés Illanes Albornoz |
847bee |
rtl_flock_acquire 4 || exit "${?}";
|
|
Lucio Andrés Illanes Albornoz |
e1d469 |
trap "rm -f \"${BUILD_DLCACHEDIR}/${_subdir%%[/]}.fetching\"" EXIT;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
if [ -e "${BUILD_DLCACHEDIR}/${_subdir}" ]; then
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
(rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\
|
|
Lucio Andrés Illanes Albornoz |
d279a9 |
git pull ${DEFAULT_GIT_ARGS} origin "${_branch:-main}");
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
(rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\
|
|
Lucio Andrés Illanes Albornoz |
adfcc4 |
git submodule update);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
else
|
|
Lucio Andrés Illanes Albornoz |
d279a9 |
git clone ${DEFAULT_GIT_ARGS} "${_url}" "${BUILD_DLCACHEDIR}/${_subdir}";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
76f7b7 |
if [ -n "${_branch}" ]; then
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
(rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
76f7b7 |
git checkout "${_branch}");
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
fi;
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
(rtl_fileop cd "${BUILD_DLCACHEDIR}/${_subdir}" &&\
|
|
Lucio Andrés Illanes Albornoz |
adfcc4 |
git submodule update --init);
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
fi;
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
_oldpwd="${PWD}"; rtl_fileop cd "${PKG_BASE_DIR}";
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_fileop rm "${_tgtdir}/${_subdir}";
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_fileop cp "${BUILD_DLCACHEDIR}/${_subdir}" "${_tgtdir}";
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_fileop cd "${_oldpwd}";) 4<>"${BUILD_DLCACHEDIR}/${_subdir%%[/]}.fetching";
|
|
Lucio Andrés Illanes Albornoz |
689d3c |
if [ "${?}" -eq 0 ]; then
|
|
Lucio Andrés Illanes Albornoz |
689d3c |
cd "$(pwd)";
|
|
Lucio Andrés Illanes Albornoz |
689d3c |
else
|
|
Lucio Andrés Illanes Albornoz |
bf9edf |
return 1;
|
|
Lucio Andrés Illanes Albornoz |
689d3c |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_fetch_urls_git() {
|
|
Lucio Andrés Illanes Albornoz |
907bd3 |
local _tgtdir="" _url_spec="" _subdir="" _url="" _git_branch="";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
fce0a9 |
_tgtdir="${1}"; shift;
|
|
Lucio Andrés Illanes Albornoz |
d279a9 |
if [ "${ARG_FETCH_FORCE}" = "offline" ]; then
|
|
Lucio Andrés Illanes Albornoz |
d279a9 |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
d279a9 |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
for _url_spec in "${@}"; do
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
_subdir="${_url_spec%=*}";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
_url="${_url_spec#*=}";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
_url="${_url%@*}";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
if [ "${_url_spec#*@}" != "${_url_spec}" ]; then
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
_git_branch=${_url_spec#*@};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
fi;
|
|
Lucio Andrés Illanes Albornoz |
63d19c |
rtlp_fetch_url_git "${_tgtdir}" "${_subdir}" \
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
"${_url}" "${_git_branch}";
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
done;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
# N.B. URLs ($1) may contain `?' or '&' characters.
|
|
Lucio Andrés Illanes Albornoz |
c6d6e0 |
rtl_fetch_url_wget() {
|
|
Lucio Andrés Illanes Albornoz |
408967 |
local _urls="${1}" _sha256sum_src="${2}" _target_fname="${3}" _rc=0 _target_fname_full=""\
|
|
Lucio Andrés Illanes Albornoz |
408967 |
_url="" _urls_count=0 RTL_CHECK_DIGEST_DIGEST="";
|
|
Lucio Andrés Illanes Albornoz |
d279a9 |
if [ "${ARG_FETCH_FORCE}" = "offline" ]; then
|
|
Lucio Andrés Illanes Albornoz |
d279a9 |
return 0;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
else _urls_count="$(rtl_llength "${_urls}")";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
for _url in ${_urls}; do
|
|
Lucio Andrés Illanes Albornoz |
408967 |
if [ -z "${_target_fname}" ]; then
|
|
Lucio Andrés Illanes Albornoz |
408967 |
_target_fname="$(rtl_basename "${_url}")";
|
|
Lucio Andrés Illanes Albornoz |
689d3c |
fi;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
_target_fname_full="${BUILD_DLCACHEDIR}/${_target_fname}";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
(set +o errexit -o noglob -o nounset;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
rtl_flock_acquire 4 || exit 1;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
trap "_rc=\"\${?}\"; rm -f \"${_target_fname_full}.fetching\"; exit \"\${_rc}\";" EXIT;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
if [ -z "${_sha256sum_src}" ]\
|
|
Lucio Andrés Illanes Albornoz |
408967 |
|| ! rtl_check_digest_file "${_target_fname_full}" "${_sha256sum_src}" "${_target_fname_full}.fetched"; then
|
|
Lucio Andrés Illanes Albornoz |
408967 |
wget ${DEFAULT_WGET_ARGS} -O "${_target_fname_full}" "${_url}"; _rc="${?}";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
if [ "${_rc}" -ne 0 ]; then
|
|
Lucio Andrés Illanes Albornoz |
408967 |
exit $((${_rc}+2));
|
|
Lucio Andrés Illanes Albornoz |
408967 |
elif [ -n "${_sha256sum_src}" ]\
|
|
Lucio Andrés Illanes Albornoz |
408967 |
&& ! rtl_check_digest "${_target_fname_full}" "${_sha256sum_src}"; then
|
|
Lucio Andrés Illanes Albornoz |
408967 |
exit 2;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
else
|
|
Lucio Andrés Illanes Albornoz |
408967 |
printf "%s" "${RTL_CHECK_DIGEST_DIGEST}" > "${_target_fname_full}.fetched"; exit 0;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
fi;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
else
|
|
Lucio Andrés Illanes Albornoz |
408967 |
exit 0;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
fi;) 4<>"${_target_fname_full}.fetching"; _rc="${?}"; : $((_urls_count-=1));
|
|
Lucio Andrés Illanes Albornoz |
408967 |
case "${_rc}" in
|
|
Lucio Andrés Illanes Albornoz |
408967 |
0) break; ;;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
1) if [ "${_urls_count}" -ge 1 ]; then
|
|
Lucio Andrés Illanes Albornoz |
408967 |
rtl_log_msg warning "Warning: failed to acquire fetching lock for URL \`%s', retrying with alternative URL..." "${_url}";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
else
|
|
Lucio Andrés Illanes Albornoz |
408967 |
rtl_log_msg fatalexit "Error: failed to acquire fetching lock for URL \`%s'." "${_url}";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
fi; ;;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
2) if [ "${_urls_count}" -ge 1 ]; then
|
|
Lucio Andrés Illanes Albornoz |
408967 |
rtl_log_msg warning "Warning: hash mismatch for URL \`%s', retrying with alternative URL... (downloaded file: %s, from build variables: %s.)"\
|
|
Lucio Andrés Illanes Albornoz |
408967 |
"${_url}" "${RTL_CHECK_DIGEST_DIGEST}" "${_sha256sum_src}";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
else
|
|
Lucio Andrés Illanes Albornoz |
408967 |
rtl_log_msg fatalexit "Error: hash mismatch for URL \`%s' (downloaded file: %s, from build variables: %s.)"\
|
|
Lucio Andrés Illanes Albornoz |
408967 |
"${_url}" "${RTL_CHECK_DIGEST_DIGEST}" "${_sha256sum_src}";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
fi; ;;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
*) if [ "${_urls_count}" -ge 1 ]; then
|
|
Lucio Andrés Illanes Albornoz |
408967 |
rtl_log_msg warning "Warning: failed to fetch URL \`%s', retrying with alternative URL... (wget(1) exit status: %s)"\
|
|
Lucio Andrés Illanes Albornoz |
408967 |
"${_url}" "$((${_rc}-2))";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
else
|
|
Lucio Andrés Illanes Albornoz |
408967 |
rtl_log_msg fatalexit "Error: failed to fetch URL \`%s' (wget(1) exit status: %s)"\
|
|
Lucio Andrés Illanes Albornoz |
408967 |
"${_url}" "$((${_rc}-2))";
|
|
Lucio Andrés Illanes Albornoz |
408967 |
fi; ;;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
esac;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
done;
|
|
Lucio Andrés Illanes Albornoz |
408967 |
return "${_rc}";
|
|
Lucio Andrés Illanes Albornoz |
63d19c |
fi;
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
};
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
|
|
Lucio Andrés Illanes Albornoz (arab, vxp) |
ec19f0 |
# vim:filetype=sh
|