From 53c7c423245fb945536745bd945b46d158f713c8 Mon Sep 17 00:00:00 2001 From: Tristan PILAT Date: Mon, 25 Mar 2019 17:06:09 +0100 Subject: [PATCH] Import some functions from the cleanup branch --- evocheck.sh | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 1 deletion(-) diff --git a/evocheck.sh b/evocheck.sh index 49808f9..6483614 100755 --- a/evocheck.sh +++ b/evocheck.sh @@ -44,6 +44,9 @@ IS_SSHPERMITROOTNO=1 IS_EVOMAINTENANCEUSERS=1 IS_EVOMAINTENANCECONF=1 +# Default return code : 0 = no error +RC=0 + # Verbose function verbose() { msg="${1:-$(cat /dev/stdin)}" @@ -53,7 +56,107 @@ verbose() { # Source configuration file test -f /etc/evocheck.cf && . /etc/evocheck.cf -VERBOSE="${VERBOSE:-0}" +# Functions + +show_version() { + cat <, + Romain Dessort , + Benoit Série , + Gregory Colpart , + Jérémy Lecour , + Tristan Pilat , + Victor Laborie + and others. + +evocheck comes with ABSOLUTELY NO WARRANTY. This is free software, +and you are welcome to redistribute it under certain conditions. +See the GNU General Public License v3.0 for details. +END +} + +show_help() { + cat < /dev/null | grep -q -E '^(i|h)i' || return 1 + done +} + +# logging +failed() { + check_name=$1 + shift + check_comments=$* + + RC=1 + if [ "${QUIET}" != 1 ]; then + if [ -n "${check_comments}" ] && [ "${VERBOSE}" = 1 ]; then + printf "%s FAILED! %s\n" "${check_name}" "${check_comments}" 2>&1 + else + printf "%s FAILED!\n" "${check_name}" 2>&1 + fi + fi +} + +# Parse options +# based on https://gist.github.com/deshion/10d3cb5f88a21671e17a +while :; do + case $1 in + -h|-\?|--help) + show_help + exit 0 + ;; + --version) + show_version + exit 0 + ;; + --cron) + IS_KERNELUPTODATE=0 + IS_UPTIME=0 + ;; + -v|--verbose) + VERBOSE=1 + ;; + -q|--quiet) + QUIET=1 + VERBOSE=0 + ;; + --) + # End of all options. + shift + break + ;; + -?*|[[:alnum:]]*) + # ignore unknown options + printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2 + ;; + *) + # Default case: If no more options then break out of the loop. + break + ;; + esac + + shift +done # If --cron is passed, ignore some checks. if [ "$1" = "--cron" ]; then