diff options
author | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-03-19 20:43:42 +0100 |
---|---|---|
committer | Lucio Andrés Illanes Albornoz <lucio@lucioillanes.de> | 2020-03-19 20:43:42 +0100 |
commit | 11ef380346ff5e91634b614b4cc9e23740270957 (patch) | |
tree | 198637e076e88053b36844744d5125b432f3d701 /subr/rtl_complex.subr | |
parent | 847bee79d77df86299bb5ac909b15b22ad221bd7 (diff) | |
download | midipix_build-11ef380346ff5e91634b614b4cc9e23740270957.tar.bz2 midipix_build-11ef380346ff5e91634b614b4cc9e23740270957.tar.xz |
subr/{build,pkgtool}_init.subr: minor cleanup.
subr/rtl_complex.subr:rtl_{check_prereqs,prompt,rc}(): initial implementation.
Diffstat (limited to 'subr/rtl_complex.subr')
-rw-r--r-- | subr/rtl_complex.subr | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/subr/rtl_complex.subr b/subr/rtl_complex.subr index 8aa59bec..2c23cfe8 100644 --- a/subr/rtl_complex.subr +++ b/subr/rtl_complex.subr @@ -15,6 +15,19 @@ rtl_check_path_vars() { return "${_rc}"; }; +rtl_check_prereqs() { + local _cmd="" _cmds_missing="" _rc=0; _status=""; + for _cmd in "${@}"; do + if ! which "${_cmd}" >/dev/null 2>&1; then + _cmds_missing="${_cmds_missing:+${_cmds_missing} }${_cmd}"; + fi; + done; + if [ -n "${_cmds_missing}" ]; then + _rc=1; _status="Error: missing prerequisite package(s): ${_cmds_missing}"; + fi; + return "${_rc}"; +}; + rtl_clean_env() { local _env_vars_except="${1}" _env_var="" _env_vars=""; _env_vars="$(export | sed -ne '/^export/{s/^export //;s/=.*$//p}')"; @@ -173,6 +186,29 @@ rtl_kill_tree() { fi; }; +rtl_prompt() { + local _fmt="${1}" _choice=""; shift; + printf "${_fmt}? (y|N) " "${@}"; + read -r _choice; + case "${_choice}" in + [yY]) _choice=1; ;; + *) _choice=0; ;; + esac; + return "${_choice}"; +}; + +rtl_rc() { + local _nflag="${1}" _cmd="${2}"; shift 2; + case "${_nflag}" in + 1) if [ "${#}" -gt 0 ]; then + rtl_log_msg notice "Command line: %s %s" "${_cmd}" "${*}"; + else + rtl_log_msg notice "Command line: %s" "${_cmd}"; + fi; ;; + *) "${_cmd}" "${@}"; + esac; +}; + rtl_run_cmd_unsplit() { local _cmd="${1}" _cmdline="" _rc="" IFS; shift; while [ ${#} -gt 0 ]; do |