Skip to content

Commit

Permalink
Add parameters to control the behaviour in case of errors
Browse files Browse the repository at this point in the history
Issue #12
  • Loading branch information
JF Le Fillâtre committed Jul 15, 2016
1 parent 58c799c commit 6280c87
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 11 deletions.
35 changes: 35 additions & 0 deletions configuration/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,46 @@ The complete list of command line parameters is:
- ``-d``
Runs all post scripts in full debug mode (``bash -x``)


The following options are mainly useful for automated testing:

- ``--nocolor``
Display all output messages without any color.
Note that this only applies to the messages coming from the configuration
tool itself; other commands called by post scripts may still use colors.

- ``--dontstopmenow``
Do not stop for user input when an error occurs.

- ``--bailout``
Soft stop: exit the configuration tool when any post script returns an error
code. This is not default as not all post scripts have error code
management.

- ``--hitthewall``
Hard stop: exit both the current post script and the configuration tool when
any error of any form happens in the script. This may be overkill in a lot
of cases as there are legitimate situations where a post script may not care
about the return code of any command within, including an error, yet will be
terminated. (Think of ``grep`` returning a non-zero code when the string
isn't matched...)


A few additional rules:

- ``-v`` and ``-q`` are mutually exclusive;

- ``--dontstopmenow`` is mutually exclusive with ``--bailout`` and
``--hitthewall``

- ``--hitthewall`` selects ``--bailout`` too


All options are *positional*, that is they apply only to the configuration files
after them on the command line. Therefore it's possible to run two or three
configurations with normal parameters, and a last one in full debug and hard
exit mode.


Example
~~~~~~~
Expand Down
18 changes: 17 additions & 1 deletion configuration/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ function echo_header {
echo -e "${NOCOLOR-$COL_RESET}"
}

# Display a big fat footer in colors

function echo_footer {
echo -e "${NOCOLOR-$COL_GREEN}"
echo -e "################################################################################"
echo -e "${NOCOLOR-$COL_RESET}"
}

# Display a standard progress message

function echo_progress {
Expand Down Expand Up @@ -85,13 +93,21 @@ function echo_error {
echo -e "${NOCOLOR-$COL_RED}"
echo "[ ERROR ] $@"
echo -e "${NOCOLOR-$COL_RESET}"

if [[ "${SOFTSTOP+x}" == x ]] ; then
echo 'Stop requested, exiting now.'
exit 1
fi
}

# Same, and wait for user input

function echo_error_wait {
echo_error "$@"
read -p " Press Enter to continue."

if [[ "${NOSTOP+x}" == x ]] ; then
read -p " Press Enter to continue."
fi
}

typeset -fx echo_header
Expand Down
51 changes: 41 additions & 10 deletions configuration/configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,24 @@
# Right number of arguments?

if ! (( $# )) ; then
echo "Syntax: $0 [-v|-q] [-d] [--no-color] config_file [config_file ...]" >&2
echo "Please refer to the documentation for more details." >&2
echo "Syntax: $0 [options] config_file [config_file ...]" >&2
echo "
Options: -v be more verbose
-q be quieter
-d run the post scripts in debug mode (bash -x)
--nocolor don't use color escape codes in the messages
--dontstopmenow don't wait for user input on error
--bailout exit when a post script returns an error code
--hitthewall exit on any error inside a post script (bash -e)
-v and -q are mutually exclusive.
--dontstopmenow is mutually exclusive with --bailout and --hitthewall
--hitthewall selects --bailout too
All options are positional, that is they apply only to the configuration files
after them on the command line
" >&2
echo 'Please refer to the documentation for more details.' >&2
exit 1
fi

Expand Down Expand Up @@ -60,7 +76,6 @@ source "$POST_COMMON"

function run_one_script {


export POST_PKGLIST="${POSTDIR}/${1}.pkglist"
export POST_SCRIPT="${POSTDIR}/${1}.sh"
export POST_FILEDIR="${POSTDIR}/${1}"
Expand All @@ -86,7 +101,7 @@ function run_one_script {
# Then run the script if we have one
if [[ -r "$POST_SCRIPT" ]] ; then
echo_progress "Running post script: $POST_SCRIPT"
bash ${DEBUG+-x} "$POST_SCRIPT"
bash ${DEBUG+-x} ${HARDSTOP+-e} "$POST_SCRIPT"
ret=$?
else
echo_info "No post script found: $POST_SCRIPT"
Expand Down Expand Up @@ -158,30 +173,46 @@ echo "Beginning of script: $(date)"
unset QUIET VERBOSE DEBUG NOCOLOR

while (( $# )) ; do

case "$1" in

-q )
declare -x QUIET=
unset VERBOSE
;;

-v )
declare -x VERBOSE=
unset QUIET
;;

-d )
declare -x DEBUG=
;;

--nocolor )
declare -x NOCOLOR=
;;


--dontstopmenow )
declare -x NOSTOP=
unset HARDSTOP
unset SOFTSTOP
;;

--hitthewall )
declare -x HARDSTOP=
;&

--bailout )
declare -x SOFTSTOP=
unset NOSTOP
;;

* )
echo_header "CONFIGURATION FILE: $1"
apply_config "$1"
echo_footer
;;
esac
shift
Expand Down

0 comments on commit 6280c87

Please sign in to comment.