From d824e1e651835014ce7c5d9b0c21f7bc403d5646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucio=20Andr=C3=A9s=20Illanes=20Albornoz=20=28arab=2C=20vx?= =?UTF-8?q?p=29?= Date: Wed, 2 Mar 2016 12:44:33 +0100 Subject: - Emit warnings whenever a potentially dangerous operation is invoked by the build scripts. Currently, this only includes rm_if_exists(). - Adds pedantic mode (-pt,) which additionally adds manual confirmation of each potentially dangerous operation. --- .gitignore | 1 + build.sh | 1 + build.subr | 19 +++++++++++++++++-- build.usage | 6 +++++- build.vars | 1 + 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 5953a191..00b28afd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build.log *.sw[op] +TODO diff --git a/build.sh b/build.sh index 26879b1f..db7c9cd0 100755 --- a/build.sh +++ b/build.sh @@ -8,6 +8,7 @@ while [ ${#} -gt 0 ]; do case ${1} in -c) ARG_CLEAN=1; ;; -nd) ARG_NO_DOWNLOAD=1; ;; +-pt) ARG_PEDANTIC=1; ;; -r) [ -n "${ARG_RESTART_SCRIPT}" ] && exec cat build.usage; match_any "${2}" : \ && { ARG_RESTART_SCRIPT="${2%%:*}"; ARG_RESTART_SCRIPT_AT="${2##*:}"; } \ diff --git a/build.subr b/build.subr index 48560774..30a45fa8 100644 --- a/build.subr +++ b/build.subr @@ -75,8 +75,22 @@ find_with_no_paths() { rm_if_exists() { [ -z "${1#-m}" ] && { _rie_arg_m=1; shift; }; [ -z "${1#-c}" ] && { _rie_arg_c=1; shift; }; - [ -d ${1} -o -f ${1} ] && rm -rf ${1}; - [ ${_rie_arg_m:-0} -eq 1 ] && { mkdir ${1}; unset _rie_arg_m; }; + if [ -d ${1} -o -f ${1} ]; then + log_msg warn "Removing directory or file \`${1}'."; + if [ ${ARG_PEDANTIC:-0} -eq 1 ]; then + printf "Confirm deletion (y|N) "; + read _rie_prompt; case "${_rie_prompt}" in + [yY]) rm -rf ${1}; ;; + *) log_msg warn "Skipping removal of \`${1}'."; + _rie_arg_m=0; ;; + esac; + else + rm -rf ${1}; + fi; + fi; + [ ${_rie_arg_m:-0} -eq 1 ] && { + log_msg warn "Making directory \`${1}'."; + mkdir ${1}; unset _rie_arg_m; }; [ ${_rie_arg_c:-0} -eq 1 ] && { cd ${1}; unset _rie_arg_c; }; return 0; }; @@ -231,6 +245,7 @@ log_msg() { 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"; ;; esac; if [ $# -gt 1 ]; then printf "==> %s %s %s\033[0m\n" "$(date "${TIMESTAMP_FMT}")" "${1}" "$*"; diff --git a/build.usage b/build.usage index ea09ad17..c4d33da5 100644 --- a/build.usage +++ b/build.usage @@ -1,11 +1,15 @@ usage: ./build.sh [-c] [-nd] [-r ALL|name[:step]] [-h] [-t] -c Clean $PREFIX before processing build scripts. -nd Don't rm(1) and re-download tarballs when not required. + -h Show this screen. + -pt Enable pedantic mode. In addition to the warnings emitted + whenever a potentially dangerous operation is invoked by + the build scripts, manual confirmation will be required. + This currently only includes rm_if_exists(). -r ALL|name[:step] Restart all or the specified build script(s) completely or at the optionally specified build step. Currently defined build steps are: fetch extract patch configure clean build install configure1 configure2 build1 build2 install1 install2. - -h Show this screen. -t Produce a distribution tarball containing $PREFIX sans $WORKDIR and $PREFIX/src/midipix_build at the end of a build with zero failures. diff --git a/build.vars b/build.vars index a534d031..04f99c7b 100644 --- a/build.vars +++ b/build.vars @@ -24,6 +24,7 @@ : ${LOG_MSG_FAIL_COLOUR:=91}; : ${LOG_MSG_INFO_COLOUR:=93}; : ${LOG_MSG_SUCC_COLOUR:=92}; +: ${LOG_MSG_WARN_COLOUR:=96}; : ${MAKEFLAGS_DEFAULT:=-j8}; : ${TARBALL_FNAME_PREFIX:=midipix.}; : ${TARBALL_EXCLUDE_PATHS:="src tmp"}; -- cgit v1.2.3