summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--subr/build_init.subr38
-rw-r--r--subr/pkgtool_init.subr29
-rw-r--r--subr/rtl_complex.subr36
3 files changed, 72 insertions, 31 deletions
diff --git a/subr/build_init.subr b/subr/build_init.subr
index 6d1635db..49f0dca8 100644
--- a/subr/build_init.subr
+++ b/subr/build_init.subr
@@ -91,9 +91,9 @@ buildp_init_env() {
elif ! umask 022; then
printf "Error: failed to set umask(2).\n" >&2; exit 1;
elif ! BUILD_HNAME="$(hostname)"; then
- _rc=1; _status="Error: failed to obtain hostname.";
+ printf "Error: failed to obtain hostname." >&2; exit 1;
elif ! BUILD_USER="$(id -nu)"; then
- _rc=1; _status="Error: failed to obtain username.";
+ printf "Error: failed to obtain username." >&2; exit 1;
else for _fname in $(find subr -name *.subr); do
if ! . "${_fname}"; then
printf "Error: failed to source \`%s'.\n" "${_fname}"; exit 1;
@@ -215,34 +215,36 @@ buildp_init_getopts() {
return "${_rc}";
};
+buildp_init_getopts_help() {
+ local _opt="";
+ while getopts a:b:C:D:Fhp:Pr:R _opt 2>/dev/null; do
+ case "${_opt}" in
+ h) cat etc/build.usage; exit 0; ;;
+ esac; done; shift $((${OPTIND}-1));
+};
+
buildp_init_prereqs() {
- local _cmd="" _cmds_missing="" _rc=0; _status="";
- for _cmd in \
+ if ! rtl_check_prereqs \
awk bunzip2 bzip2 cat chmod cmake cp date find flock \
g++ gcc git grep gunzip gzip hostname id install kill \
ln lzip make mkdir mkfifo mktemp mv paste patch perl \
pgrep pkill printf readlink rm sed sha256sum sort \
- tail tar test touch tr uniq wget xz zip; 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}";
+ tail tar test touch tr uniq wget xz zip; then
+ printf "%s\n" "${_status}" >&2; exit 1;
elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT; \
sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); then
- _rc=1; _status="Error: sed(1) in \${PATH} does not support the \`-i' option.";
+ printf "Error: sed(1) in \${PATH} does not support the \`-i' option.\n" >&2; exit 1;
fi;
- return "${_rc}";
};
build_init() {
local _rc=0; _status="";
- if ! buildp_init_env \
- || ! buildp_init_getopts "${@}" \
- || ! buildp_init_prereqs \
- || ! ex_pkg_load_vars \
- || ! buildp_init_args \
+ if ! buildp_init_env \
+ || ! buildp_init_getopts_help "${@}" \
+ || ! buildp_init_prereqs \
+ || ! buildp_init_getopts "${@}" \
+ || ! ex_pkg_load_vars \
+ || ! buildp_init_args \
|| ! buildp_init_files; then
_rc=1; _status="${_status}";
fi; return "${_rc}";
diff --git a/subr/pkgtool_init.subr b/subr/pkgtool_init.subr
index 309dc612..f5eb21fc 100644
--- a/subr/pkgtool_init.subr
+++ b/subr/pkgtool_init.subr
@@ -74,7 +74,7 @@ pkgtoolp_init_getopts() {
done;
if [ "${_rc:-0}" -eq 0 ]; then
if [ "${#}" -ne 1 ]\
- && [ -z "${PKGTOOL_PKG_NAME}" ]; then
+ && [ -z "${PKGTOOL_PKG_NAME:-}" ]; then
_rc=1; _status="Error: missing package name.";
elif [ "${#}" -eq 1 ]; then
PKGTOOL_PKG_NAME="${1}"; export PKGTOOL_PKG_NAME;
@@ -83,29 +83,32 @@ pkgtoolp_init_getopts() {
fi; return "${_rc}";
};
+pkgtoolp_init_getopts_help() {
+ local _opt="";
+ while getopts a:b:hirst _opt 2>/dev/null; do
+ case "${_opt}" in
+ h) cat etc/build.usage; exit 0; ;;
+ esac; done; shift $((${OPTIND}-1));
+};
+
pkgtoolp_init_prereqs() {
- local _cmd="" _cmds_missing="" _rc=0; _status="";
- for _cmd in \
+ if ! rtl_check_prereqs \
awk bzip2 cat chmod cp date find grep hostname mkdir \
mktemp mv paste printf readlink rm sed sort tar test \
- touch tr uniq; 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}";
+ touch tr uniq; then
+ printf "%s\n" "${_status}" >&2; exit 1;
elif ! (FNAME="$(mktemp)" && { trap "rm -f \"\${FNAME}\"" EXIT; \
sed -i'' -e '' "${FNAME}" >/dev/null 2>&1; }); then
- _rc=1; _status="Error: sed(1) in \${PATH} does not support the \`-i' option.";
- fi; return "${_rc}";
+ printf "Error: sed(1) in \${PATH} does not support the \`-i' option.\n" >&2; exit 1;
+ fi;
};
pkgtool_init() {
local _fname="" _rc=0; _status="";
if ! pkgtoolp_init_env \
- || ! pkgtoolp_init_getopts "${@}" \
+ || ! pkgtoolp_init_getopts_help "${@}" \
|| ! pkgtoolp_init_prereqs \
+ || ! pkgtoolp_init_getopts "${@}" \
|| ! ex_pkg_load_vars \
|| ! pkgtoolp_init_args; then
_rc=1; _status="${_status}";
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