Blame subr/pkg_fetch.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 570129
#
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
# . ./build.vars and set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
# See warning at the top of build.vars.
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
#
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
# N.B.	URLs ($1) may contain `?' or '&' characters.
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
pkgp_fetch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	_f_url="${1}"; _f_sha256sum_src="${2}";
Lucio Andrés Illanes Albornoz (arab, vxp) 608811
	if [ -z "${3}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 608811
		_f_url_dst="${DLCACHEDIR}/$(basename "${_f_url}")";
Lucio Andrés Illanes Albornoz (arab, vxp) 608811
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 608811
		_f_url_dst="${DLCACHEDIR}/${3}";
Lucio Andrés Illanes Albornoz (arab, vxp) 608811
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	if [ ${ARG_OFFLINE:-0} -eq 1 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	|| [ -e ${_f_url_dst}.fetched ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		unset _f_url _f_sha256sum_src _f_url_dst;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		wget ${WGET_ARGS} -c -O ${_f_url_dst} "${_f_url}";
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	if [ -n "${_f_sha256sum_src}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		set -- $(openssl dgst -sha256 ${_f_url_dst}); shift $((${#}-1));
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		if [ "${_f_sha256sum_dst:=${1}}" != "${_f_sha256sum_src}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			if [ ${ARG_IGNORE_SHA256SUMS:-0} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
				log_msg failexit "Error: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)";
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
				log_msg warn "Warning: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)";
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	touch ${_f_url_dst}.fetched;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	unset _f_url _f_url_dst _f_sha256sum_src _f_sha256sum_dst;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
pkgp_fetch_git() {
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	_fg_subdir="${1}"; _fg_url="${2}"; _fg_branch="${3}";
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	if [ ${ARG_OFFLINE:-0} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		if [ -e "${DLCACHEDIR}/${_fg_subdir}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
			build_fileop cd ${DLCACHEDIR}/${_fg_subdir} &&\
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
				git pull origin ${_fg_branch:-main} &&\
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
					build_fileop cd ${OLDPWD};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			git clone ${_fg_url} ${DLCACHEDIR}/${_fg_subdir};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			if [ -n "${_fg_branch}" -a		\
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			     \( -z "${_fg_branch#main}" \) -a	\
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			     \( -z "${_fg_branch#master}" \) ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
				build_fileop cd ${DLCACHEDIR}/${_fg_subdir}	&&\
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
					git checkout -b ${_fg_branch}		&&\	
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
						build_fileop cd ${OLDPWD};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
	build_fileop rm ${_fg_subdir};
Lucio Andrés Illanes Albornoz (arab, vxp) bd97b6
	build_fileop cp ${DLCACHEDIR}/${_fg_subdir} .;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
pkgp_fetch_urls_git() {
Lucio Andrés Illanes Albornoz (arab, vxp) 7fa1ad
	for _ppfu_url_spec in "${@}"; do
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		_ppfu_subdir=${_ppfu_url_spec%=*};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		_ppfu_url=${_ppfu_url_spec#*=};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		_ppfu_url=${_ppfu_url%@*};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		if [ "${_ppfu_url_spec#*@}" != "${_ppfu_url_spec}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			_ppfu_git_branch=${_ppfu_url_spec#*@};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		pkgp_fetch_git ${_ppfu_subdir} ${_ppfu_url} ${_ppfu_git_branch};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	unset _ppfu_url_spec _ppfu_subdir _ppfu_url _ppfu_git_branch;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
pkg_fetch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	if [ -n "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		if [ "${1}" = "-git" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			shift; pkgp_fetch_urls_git ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			pkgp_fetch ${1} ${2};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		if [ -n "${PKG_URL}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 608811
			pkgp_fetch ${PKG_URL} ${PKG_SHA256SUM} ${PKG_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		if [ -n "${PKG_URLS_GIT}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
			pkgp_fetch_urls_git ${PKG_URLS_GIT};
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 03a637
		set_build_script_done fetch -extract;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
};
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
Lucio Andrés Illanes Albornoz (arab, vxp) 570129
# vim:filetype=sh