Conan_Kudo / build / midipix_build

Forked from build/midipix_build 4 years ago
Clone

Blame subr/rtl.subr

Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
#
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# . ./build.vars and set -o errexit -o noglob are assumed.
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# See warning at the top of build.vars.
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
#
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
date() { command date +"${1:-${TIMESTAMP_FMT}}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
get_var_unsafe() { eval echo \${${1}}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
set_var_unsafe() { eval ${1}=\"${2}\"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
push_IFS() { _pI_IFS="${IFS}"; IFS="${1}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
pop_IFS() { IFS="${_pI_IFS}"; unset _pI_IFS; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
set_build_dir() { PKG_BUILD_DIR=${1}-${2}-${TARGET}; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
split() { push_IFS "${1}"; set -- ${2}; pop_IFS; echo "${*}"; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
test_cmd() { command -v "${1}" >/dev/null; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
unsplit() { push_IFS "${1}"; shift; set -- "${@}"; echo "${*}"; pop_IFS; };
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
get_vars_unsafe() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		_gvu_vval="$(eval echo \${${1}})";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		[ -z "${_gvu_vval}" ] || _gvu_vval_="${_gvu_vval}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done; echo "${_gvu_vval_}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	unset _gvu_vval _gvu_vval_;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
log_msg() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	_lm_lvl=${1}; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	case ${_lm_lvl} in
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		failexit) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fail) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		info) printf "\033[0m\033[${LOG_MSG_INFO_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		succ) printf "\033[0m\033[${LOG_MSG_SUCC_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		warn) printf "\033[0m\033[${LOG_MSG_WARN_COLOUR}m"; ;;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	esac;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ $# -gt 1 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		printf "==> %s %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}" "$*";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		printf "==> %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi; [ ${_lm_lvl} = failexit ] && exit 1 || unset _lm_lvl;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
insecure_mkdir() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ -z "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		elif [ ! -e "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			[ "${ARG_VERBOSE:-0}" -eq 1 ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				log_msg warn "Making directory \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			mkdir -p -- "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
match_list() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	_ml_cmp="${3}"; push_IFS "${2}"; set -- ${1}; pop_IFS;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ "${1}" = "${_ml_cmp}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			unset _ml_cmp; return 0;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done; unset _ml_cmp; return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
secure_cd() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	if [ \( -z "${1}" \) -o \( ! -e "${1}" \) ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		(cd "${1}"; [ "${PWD#${PREFIX_ROOT}}" = "${PWD}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			return 1 || return 0);
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ ${?} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			[ "${ARG_VERBOSE:-0}" -eq 1 ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				log_msg warn "Changing working directory to \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			cd -- "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			log_msg failexit "secure_cd() called with pathname \`${1}' not below \${PREFIX_ROOT} (${PREFIX_ROOT}). This is a bug.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
secure_rm() {
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	while [ ${#} -gt 0 ]; do
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		if [ -z "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			return 1;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		elif [ -e "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			if [ -d "${1}" ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				_sr_pname_check="${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				_sr_pname_check="$(dirname "${1}")";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			(cd "${_sr_pname_check}"; [ "${PWD#${PREFIX_ROOT}}" = "${PWD}" ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				return 1 || return 0);
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			if [ ${?} -eq 0 ]; then
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				unset _sr_pname_check;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				[ "${ARG_VERBOSE:-0}" -eq 1 ] &&\
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
					log_msg warn "Removing directory or file \`${1}'.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				rm -rf -- "${1}";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			else
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
				log_msg failexit "secure_rm() called with pathname \`${1}' not below \${PREFIX_ROOT} (${PREFIX_ROOT}). This is a bug.";
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
			fi;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
		fi; shift;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
	done;
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
};
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
Lucio Andrés Illanes Albornoz (arab, vxp) 59765f
# vim:filetype=sh