midipix / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame subr/pkg_fetch_wget.subr

Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
#
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
# set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
#
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
# N.B.	URLs ($1) may contain `?' or '&' characters.
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
pkgp_fetch_wget() {
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	local _url="${1}" _sha256sum_src="${2}";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	if [ -z "${3}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
		_url_dst="${DLCACHEDIR}/$(ex_basename "${_url}")";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	else
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		_url_dst="${DLCACHEDIR}/${3}";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	if [ "${ARG_OFFLINE:-0}" -eq 1 ]\
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	|| [ -e "${_url_dst}.fetched" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	else
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		wget ${DEFAULT_WGET_ARGS} -c -O "${_url_dst}" "${_url}";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	if [ -n "${_sha256sum_src}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		set -- $(openssl dgst -sha256 "${_url_dst}"); shift $((${#}-1));
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		if [ "${_sha256sum_dst:=${1}}" != "${_sha256sum_src}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
			if [ "${ARG_IGNORE_SHA256SUMS:-0}" -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 32ad21
				ex_log_msg failexit "Error: hash mismatch for URL \`${_url}' (is: ${_sha256sum_dst}, should be: ${_sha256sum_src}.)";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 3961f3
				ex_log_msg vnfo "Warning: hash mismatch for URL \`${_url}' (is: ${_sha256sum_dst}, should be: ${_sha256sum_src}.)";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	touch "${_url_dst}.fetched";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
};
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
pkg_fetch_wget() {
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	if [ -n "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		pkgp_fetch_wget "${1}" "${2}";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	else
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		if [ -n "${PKG_URL}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
			pkgp_fetch_wget "${PKG_URL}" "${PKG_SHA256SUM}" "${PKG_FNAME}";
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
};
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
Lucio Andrés Illanes Albornoz (arab, vxp) c27bea
# vim:filetype=sh