diff options
Diffstat (limited to 'build.subr')
-rw-r--r-- | build.subr | 63 |
1 files changed, 27 insertions, 36 deletions
@@ -6,7 +6,6 @@ date() { command date +"${1:-${TIMESTAMP_FMT}}"; }; get_var_unsafe() { eval echo \${${1}}; }; set_var_unsafe() { eval ${1}=\"${2}\"; }; -match_uname_any() { set -- ${1} $(uname -s); [ "${2#*${1}*}" != "${2}" ]; }; push_IFS() { _pI_IFS="${IFS}"; IFS="${1}"; }; pop_IFS() { IFS="${_pI_IFS}"; unset _pI_IFS; }; set_build_dir() { PKG_BUILD_DIR=${1}-${2}-${TARGET}; }; @@ -14,36 +13,36 @@ split() { push_IFS "${1}"; set -- ${2}; pop_IFS; echo "${*}"; }; test_cmd() { command -v "${1}" >/dev/null; }; unsplit() { push_IFS "${1}"; shift; set -- "${@}"; echo "${*}"; pop_IFS; }; -compare_hash() { - # Push the output of dgst(1SSL) and the caller-supplied hash - # value to compare the former with on the pseudo-stack and - # shift off# all but the last two positional parameters. - # This corresponds to the hash output and caller-supplied - # hash values. - set -- $(openssl dgst -sha256 ${1}) ${2}; shift $((${#}-2)); - [ "${1}" = "${2}" ] || echo "${1}"; -}; - # N.B. URLs ($1) may contain `?' or '&' characters. fetch() { _f_url="${1}"; _f_sha256sum_src="${2}"; _f_url_dst="${DLCACHEDIR}/$(basename "${_f_url}")"; - wget ${WGET_ARGS} -c -O ${_f_url_dst} "${_f_url}"; + if [ -e ${_f_url_dst}.fetched ]; then + unset _f_url _f_sha256sum_src _f_url_dst; + return 0; + else + wget ${WGET_ARGS} -c -O ${_f_url_dst} "${_f_url}"; + fi; if [ -n "${_f_sha256sum_src}" ]; then - _f_sha256sum_dst="$(compare_hash ${_f_url_dst} ${_f_sha256sum_src})"; - if [ -n "${_f_sha256sum_dst}" ]; then - set -- "${_f_url}" ${_f_sha256sum_dst} ${_f_sha256sum_src}; - unset _f_url _f_url_dst _f_sha256sum_src _f_sha256sum_dst; - log_msg failexit "Error: hash mismatch for URL \`${1}' (is: ${2}, should be: ${3}.)"; - fi; unset _f_sha256sum_dst; - fi; unset _f_url _f_url_dst _f_sha256sum_src; + set -- $(openssl dgst -sha256 ${_f_url_dst}); shift $((${#}-1)); + if [ "${_f_sha256sum_dst:=${1}}" != "${_f_sha256sum_src}" ]; then + log_msg failexit "Error: hash mismatch for URL \`${_f_url}' (is: ${_f_sha256sum_dst}, should be: ${_f_sha256sum_src}.)"; + fi; + fi; + touch ${_f_url_dst}.fetched; + unset _f_url _f_url_dst _f_sha256sum_src _f_sha256sum_dst; }; fetch_git() { - [ -z "${1}" ] && return 1; - rm_if_exists ${1}; - [ -d ${1} ] && (cd ${1} && git pull origin main)\ - || git clone ${3} ${2} ${1}; + _fg_subdir="${1}"; _fg_url="${2}"; _fg_git_args_extra="${3}"; + if [ -e "${DLCACHEDIR}/${_fg_subdir}" ]; then + (cd ${DLCACHEDIR}/${_fg_subdir} && git pull origin main); + else + git clone ${_fg_git_args_extra} ${_fg_url} ${DLCACHEDIR}/${_fg_subdir}; + fi; + rm_if_exists ${_fg_subdir}; + echo cp -pr ${DLCACHEDIR}/${_fg_subdir} .; + cp -pr ${DLCACHEDIR}/${_fg_subdir} .; }; insert_build_script_link() { @@ -157,11 +156,11 @@ log_env_vars() { log_msg() { _lm_lvl=${1}; shift; case ${_lm_lvl} in - failexit) printf "\033[${LOG_MSG_FAIL_COLOUR}m"; ;; - fail) printf "\033[${LOG_MSG_FAIL_COLOUR}m"; ;; - info) printf "\033[${LOG_MSG_INFO_COLOUR}m"; ;; - succ) printf "\033[${LOG_MSG_SUCC_COLOUR}m"; ;; - warn) printf "\033[${LOG_MSG_WARN_COLOUR}m"; ;; + failexit) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;; + fail) printf "\033[0m\033[${LOG_MSG_FAIL_COLOUR}m"; ;; + info) printf "\033[0m\033[${LOG_MSG_INFO_COLOUR}m"; ;; + succ) printf "\033[0m\033[${LOG_MSG_SUCC_COLOUR}m"; ;; + warn) printf "\033[0m\033[${LOG_MSG_WARN_COLOUR}m"; ;; esac; if [ $# -gt 1 ]; then printf "==> %s %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}" "$*"; @@ -243,12 +242,4 @@ run_cmd_unsplit() { unset _rcu_cmd _rcu_cmdline; return ${_rcu_rc}; }; -set_env_vars() { - _sev_val_new="${1}"; shift; - while [ ${#} -gt 1 ]; do - [ -z "${_sev_val_new}" ] && unset ${1} ||\ - export "${1}=${_sev_val_new}"; shift; - done; unset _sev_val_new; -}; - # vim:filetype=sh |