Added argument parsing and test checks

This commit is contained in:
thibault.dewailly 2016-04-17 23:10:47 +02:00
parent e1337d76df
commit ef14c475fe
3 changed files with 32 additions and 1 deletions

View File

@ -19,7 +19,7 @@ audit () {
info "Fetching upgrades ..."
apt_check_updates "CIS_APT"
if [ $FNRET -gt 0 ]; then
warn "$RESULT"
crit "$RESULT"
FNRET=1
else
ok "No upgrades available"

View File

@ -58,6 +58,8 @@ cecho () {
crit () {
[ $MACHINE_LOG_LEVEL -ge 1 ] && _logger $BRED "[ KO ] $*"
# This variable incrementation is used to measure failure or success in tests
CRITICAL_ERRORS_NUMBER=$((CRITICAL_ERRORS_NUMBER+1))
}
warn () {

View File

@ -1,6 +1,7 @@
LONG_SCRIPT_NAME=$(basename $0)
SCRIPT_NAME=${LONG_SCRIPT_NAME%.sh}
# Variable initialization, to avoid crash
CRITICAL_ERRORS_NUMBER=0 # This will be used to see if a script failed, or passed
status=""
[ -r $CIS_ROOT_DIR/lib/constants.sh ] && . $CIS_ROOT_DIR/lib/constants.sh
@ -21,6 +22,25 @@ if [ -z $status ]; then
exit 0
fi
# Arguments parsing
while [[ $# > 0 ]]; do
ARG="$1"
case $ARG in
--audit)
if [ $status != 'disabled' -o $status != 'false' ]; then
debug "Audit argument detected, setting status to audit"
status=audit
else
info "Audit argument passed but script is disabled"
fi
;;
*)
debug "Unknown option passed"
;;
esac
shift
done
case $status in
enabled | true )
info "Checking Configuration"
@ -43,3 +63,12 @@ case $status in
warn "Wrong value for status : $status. Must be [ enabled | true | audit | disabled | false ]"
;;
esac
info "Results : "
if [ $CRITICAL_ERRORS_NUMBER = 0 ]; then
ok "Check Passed"
exit 0
else
crit "Check Failed"
exit 1
fi