Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
#
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
# . ./build.vars and set -o errexit are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# See warning at the top of build.vars.
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
#
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
date() { command date +"${1:-${TIMESTAMP_FMT}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_basename() { set -- $(get_name_without_slash ${1}); echo "${1##*/}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
get_var_dyn() { ${1}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
get_var_unsafe() { eval echo \${${1}}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
set_var_dyn() { eval ${1}\(\) \{ echo \"${2}\"\; \}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
set_var_unsafe() { eval ${1}=\"${2}\"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 9ba5d3
get_name_without_slash() { while [ "${1%/}" != ${1} ]; do set -- ${1%/}; done; echo ${1}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_postfix_lrg() { echo "${1##*${2}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_prefix_lrg() { echo "${1%%${2}*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_postfix() { echo "${1#*${2}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
get_prefix() { echo "${1%${2}*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 9ba5d3
match_any() { [ "${1#*${2}*}" != "${1}" ]; };
Lucio Andrés Illanes Albornoz (arab, vxp) 41d5cc
match_uname_any() { set -- ${1} $(uname -s); [ "${2#*${1}*}" != "${2}" ]; };
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
push_IFS() { _pI_IFS="${IFS}"; IFS="${1}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
pop_IFS() { IFS="${_pI_IFS}"; unset _pI_IFS; };
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
set_build_dir() { PKG_BUILD_DIR=${1}-${2}-${TARGET}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
split() { push_IFS "${1}"; set -- ${2}; pop_IFS; echo "${*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
test_cmd() { command -v "${1}" >/dev/null; };
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
unsplit() { push_IFS "${1}"; shift; set -- "${@}"; echo "${*}"; pop_IFS; };
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
build_times_init() { BUILD_TIMES_SECS=$(command date +%s); };
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
build_times_get() {
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	: $((BUILD_TIMES_SECS=$(command date +%s)-${BUILD_TIMES_SECS}));
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	: $((BUILD_TIMES_HOURS=${BUILD_TIMES_SECS}/3600));
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	: $((BUILD_TIMES_MINUTES=(${BUILD_TIMES_SECS}%3600)/60));
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	: $((BUILD_TIMES_SECS=(${BUILD_TIMES_SECS}%3600)%60));
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
clean_prefix() {
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	log_msg info "-c specified, cleaning prefix...";
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	set -- bin include lib lib64 libexec native share x86_64-nt64-midipix;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	while [ ${#} -gt 0 ]; do rm -rf ${PREFIX}/${1}; shift; done;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	find ${PREFIX}/tmp -mindepth 1 -maxdepth 1 -not -iname \*.tar\* -exec rm -rf {} \;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	find ${PREFIX}/tmp -mindepth 1 -maxdepth 1 -type f -iname .\* -exec rm -rf {} \;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
clean_build_status() {
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
	set -- BUILD_STATUS_IN_PROGRESS_FNAME BUILD_STATUS_PROGRESS_FNAME BUILD_STATUS_TARBALL_PROGRESS_FNAME;
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
		unset ${1}; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
	done; touch ${PREFIX}/BUILD_ABORTED_AT_$(date %Y-%m-%d-%H-%M-%S);
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
	log_msg fail "Build aborted at $(date %Y-%m-%d-%H-%M-%S).";
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
};
Lucio Andrés Illanes Albornoz (arab, vxp) b94746
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
export_vars_subst() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_evs_pfx=${1}; _evs_pfx_new=${2}; shift 2;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
		if [ -n "${_evs_vval:=$(get_var_unsafe ${_evs_pfx}${1})}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			export "${_evs_pfx_new}${1}=${_evs_vval}";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		fi; unset _evs_vval; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; unset _evs_pfx _evs_pfx_new;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
fetch_git() {
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	rm_if_exists ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	[ -d ${1} ] && (cd ${1} && git pull origin main)\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		|| git clone ${3} ${2} ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
rm_if_exists() {
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
	[ -z "${1#-m}" ] && { _rie_arg_m=1; shift; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
	[ -z "${1#-c}" ] && { _rie_arg_c=1; shift; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
	[ -d ${1} -o -f ${1} ] && rm -rf ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
	[ ${_rie_arg_m:-0} -eq 1 ] && { mkdir ${1}; unset _rie_arg_m; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
	[ ${_rie_arg_c:-0} -eq 1 ] && { cd ${1}; unset _rie_arg_c; };
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
	return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
rotate_files() {
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	set -- $(find ${PREFIX} -mindepth 1 -maxdepth 1 -type f -iname "${1}" |\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
			sort | sed -n $((${2}+1)),\$p);
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		rm -f "${1}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
set_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_sev_val_new="${1}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 1 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		[ -z "${_sev_val_new}" ] && unset ${1} ||\
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			export "${1}=${_sev_val_new}"; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; unset _sev_val_new;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Download GNU bash-style patch sets into ${2}-patches-extra and
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# apply them to ${2} in the correct order.
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
apply_patches() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	(rm_if_exists -m -c ${2}-patches-extra;
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
	wget -c -nd -np -r -R \*.htm\* -R \*.sig ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	for _ap_patch_fname in		\
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
			$(find . -type f -not -iname \*.sig | sort); do
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		patch -b -d ../${2} -p0 < ${_ap_patch_fname};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; unset _ap_patch_fname);
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
};
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Check whether all supplied arguments contain non-empty valid values.
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
check_path_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
		if [ -z "${_cpv_val:=$(get_var_unsafe "${1}")}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: variable \`${1}' is empty or unset.";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		elif match_any "${_cpv_val}" " "; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: variable \`${1}' contains one or more whitespace characters.";
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		else
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
			shift;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		unset _cpv_val;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
};
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Check whether all supplied command names resolve.
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
check_prereqs() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if ! command -v ${1} >/dev/null; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: missing prerequisite command \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
};
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# Clear the environment by unsetting each exported variable except
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
# for those named by the caller. 
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
clear_env_with_except() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_cewe_vfilter="${*}"; _cewe_unset_cmds="$(mktemp -q)";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	export | while read _cewe_vspec; do
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		set -- ${_cewe_vspec}; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 9ba5d3
		[ "${1#*[^\"\'=a-zA-Z0-9_]}" != "${1}" ] && continue;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		if ! match_list "${_cewe_vfilter}" " "	\
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
				$(get_prefix_lrg ${1} =); then
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			echo unset $(get_prefix_lrg ${1} =) >> ${_cewe_unset_cmds};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; . "${_cewe_unset_cmds}"; rm -f "${_cewe_unset_cmds}" 2>/dev/null;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	unset _cewe_vfilter _cewe_vspec;
lalbornoz 340f4c
};
lalbornoz 340f4c
lalbornoz 340f4c
fetch() {
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	[ ${ARG_NO_DOWNLOAD:-0} -eq 0 ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		rm_if_exists $(get_basename ${1});
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	wget ${WGET_ARGS} ${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	if [ ${#} -eq 2 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		set -- $(get_basename ${1}) "$(compare_hash $(get_basename ${1}) ${2})" ${2};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		if [ -n "${2}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: hash mismatch for URL \`${1}' (is: ${2}, should be: ${3}.)";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi;
lalbornoz 340f4c
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
compare_hash() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# Push the output of dgst(1SSL) and the caller-supplied hash
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# value to compare the former with on the pseudo-stack and
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# shift off# all but the last two positional parameters.
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# This corresponds to the hash output and caller-supplied
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	# hash values.
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	set -- $(openssl dgst -sha256 ${1}) ${2}; shift $((${#}-2));
Lucio Andrés Illanes Albornoz (arab, vxp) 9ba5d3
	[ "${1}" = "${2}" ] || echo "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
};
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
compare_hash_manifest() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
		if ! compare_hash ${1} ${2}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			log_msg failexit "Error: hash mismatch for patch file \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
	done; return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) f9c386
};
Lucio Andrés Illanes Albornoz (arab, vxp) 6e940c
lalbornoz 340f4c
is_build_script_done() {
Lucio Andrés Illanes Albornoz (arab, vxp) 6e48a0
	if [ -n "${ARG_RESTART_SCRIPT_AT}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		if [ "${1}" = clean ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		&& [ -z "${ARG_RESTART_SCRIPT_AT#ALL}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
			return 0;	# Skip
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		elif [ "${1}" = finish ]\
Lucio Andrés Illanes Albornoz (arab, vxp) 6e48a0
		|| [ -z "${ARG_RESTART_SCRIPT_AT#ALL}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			return 1;	# Build
Lucio Andrés Illanes Albornoz (arab, vxp) 6e48a0
		elif ! match_list ${ARG_RESTART_SCRIPT_AT} , ${1}; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			return 0;	# Skip
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
			return 1;	# Build
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	elif [ -f ${WORKDIR}/.${2:-$(get_basename ${SCRIPT_FNAME%.build})}.${1} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		return 0;		# Skip
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		return 1;		# Build
Lucio Andrés Illanes Albornoz (arab, vxp) f5eeee
	fi;
lalbornoz 340f4c
};
lalbornoz 340f4c
set_build_script_done() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_sbsd_script_fname=${SCRIPT_FNAME##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_sbsd_done_fname=${WORKDIR}/.${_sbsd_script_fname%.build};
lalbornoz 340f4c
	while [ $# -ge 1 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 9ba5d3
		if [ "${1#-}" != "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			rm -f ${_sbsd_done_fname}.${1#-};
lalbornoz 340f4c
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			touch ${_sbsd_done_fname}.${1};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			log_msg info "Finished build step ${1} of build script \`${_sbsd_script_fname}'.";
lalbornoz 340f4c
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; unset _sbsd_script_fname _sbsd_done_fname;
lalbornoz 340f4c
};
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
log_env_vars() {
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	log_msg info "Variables for this build:";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	while [ ${_lev_nvar:=0} -lt ${#} ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		_lev_arg="$(eval echo \${${_lev_nvar}})";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		_lev_arg="${_lev_arg%%=*}";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		if [ ${#_lev_arg} -gt ${_lev_arg_len_max:=0} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			_lev_arg_len_max=${#_lev_arg};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		fi; : $((_lev_nvar+=1));
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; unset _lev_nvar _lev_arg;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		log_msg info "$(printf					\
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			"%${_lev_arg_len_max}.${_lev_arg_len_max}s=%s"	\
Lucio Andrés Illanes Albornoz (arab, vxp) 090fd4
			"${1%%=*}" "$(get_var_unsafe ${1#*=})")";
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; unset _lev_arg_len_max;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
lalbornoz 340f4c
log_msg() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_lm_lvl=${1}; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	case ${_lm_lvl} in
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		failexit) printf "\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
		fail) printf "\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
		info) printf "\033[${LOG_MSG_INFO_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 31dc75
		succ) printf "\033[${LOG_MSG_SUCC_COLOUR}m"; ;;
lalbornoz 340f4c
	esac;
lalbornoz 340f4c
	if [ $# -gt 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		printf "==> %s %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}" "$*";
lalbornoz 340f4c
	else
Lucio Andrés Illanes Albornoz (arab, vxp) d30b8f
		printf "==> %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	fi; [ ${_lm_lvl} = failexit ] && exit 1 || unset _lm_lvl;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
match_list() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_ml_cmp="${3}"; push_IFS "${2}"; set -- ${1}; pop_IFS;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 9ba5d3
		if [ "${1}" = "${_ml_cmp}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			unset _ml_cmp; return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done; unset _ml_cmp; return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
};
Lucio Andrés Illanes Albornoz (arab, vxp) 1d0876
lalbornoz 340f4c
parse_with_pkg_name() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	PKG_LVL=${1}; PKG_NAME=${2}; shift 2;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	while [ ${#} -ge 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 9ba5d3
		if [ "${PKG_NAME}" = ${1} ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			export_vars_subst PKG_LVL${PKG_LVL}_ PKG_ ${PKG_BUILD_VARS};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			export_vars_subst PKG_$(echo ${PKG_NAME} | tr a-z A-Z)_ PKG_ ${PKG_BUILD_VARS};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			[ -z "${PKG_URL}" ] && return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			[ -z "${PKG_FNAME}" ] && PKG_FNAME=${PKG_URL##*/};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			[ -z "${PKG_SUBDIR}" ] && PKG_SUBDIR=${PKG_FNAME%%.tar*};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			[ -n "${PKG_ENV_VARS_EXTRA}" ] && export ${PKG_ENV_VARS_EXTRA};
Lucio Andrés Illanes Albornoz (arab, vxp) 2dd87f
			export PKG_PREFIX=$(get_var_unsafe PREFIX_LVL${PKG_LVL}); return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) c49754
	done; return 1;
lalbornoz 340f4c
};
lalbornoz 340f4c
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
run_cmd_unsplit() {
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	_rcu_cmd=${1}; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		[ -n "${1}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
			_rcu_cmdline="${_rcu_cmdline:+${_rcu_cmdline},}${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
		shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	push_IFS ,; ${_rcu_cmd} ${_rcu_cmdline}; _rcu_rc=$?; pop_IFS;
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
	unset _rcu_cmd _rcu_cmdline; return ${_rcu_rc};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
};
Lucio Andrés Illanes Albornoz (arab, vxp) 392fef
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
update_build_status() {
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	case ${1} in
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	build_start)
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		touch ${BUILD_STATUS_IN_PROGRESS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		touch ${BUILD_STATUS_PROGRESS_FNAME:=${PREFIX}/BUILD_STARTED_AT_${BUILD_DATE_START:=$(date %Y-%m-%d-%H-%M-%S)}};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		;;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	build_finish)
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		[ -f ${BUILD_STATUS_PROGRESS_FNAME} ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
			rm -f ${BUILD_STATUS_PROGRESS_FNAME};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		touch ${BUILD_STATUS_FINISHED_AT_FNAME:=${PREFIX}/BUILD_FINISHED_AT_$(date ${TIMESTAMP_FMT_STATUS_FILES})};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		rotate_files BUILD_FINISHED_AT_\* 8;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		ln -sf ${BUILD_STATUS_FINISHED_AT_FNAME}\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
			${BUILD_STATUS_FINISHED_AT_CURRENT_FNAME}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	tarball_start)
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		rotate_files midipix.\*.tar.bz2 8;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		touch ${BUILD_STATUS_TARBALL_PROGRESS_FNAME:=${PREFIX}/TARBALL_STARTED_AT_$(date ${TIMESTAMP_FMT_STATUS_FILES})};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		;;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	tarball_finish)
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		[ -f ${BUILD_STATUS_TARBALL_PROGRESS_FNAME} ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
			rm -f ${BUILD_STATUS_TARBALL_PROGRESS_FNAME}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	finish)
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
		[ -f ${BUILD_STATUS_IN_PROGRESS_FNAME} ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
			rm -f ${BUILD_STATUS_IN_PROGRESS_FNAME}; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	esac; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
};
Lucio Andrés Illanes Albornoz (arab, vxp) 0724e5
lalbornoz 340f4c
# vim:filetype=sh