mirror of
https://github.com/ovh/debian-cis.git
synced 2024-11-23 05:55:38 +01:00
Added argument parsing and test checks
This commit is contained in:
parent
e1337d76df
commit
ef14c475fe
@ -19,7 +19,7 @@ audit () {
|
|||||||
info "Fetching upgrades ..."
|
info "Fetching upgrades ..."
|
||||||
apt_check_updates "CIS_APT"
|
apt_check_updates "CIS_APT"
|
||||||
if [ $FNRET -gt 0 ]; then
|
if [ $FNRET -gt 0 ]; then
|
||||||
warn "$RESULT"
|
crit "$RESULT"
|
||||||
FNRET=1
|
FNRET=1
|
||||||
else
|
else
|
||||||
ok "No upgrades available"
|
ok "No upgrades available"
|
||||||
|
@ -58,6 +58,8 @@ cecho () {
|
|||||||
|
|
||||||
crit () {
|
crit () {
|
||||||
[ $MACHINE_LOG_LEVEL -ge 1 ] && _logger $BRED "[ KO ] $*"
|
[ $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 () {
|
warn () {
|
||||||
|
29
lib/main.sh
29
lib/main.sh
@ -1,6 +1,7 @@
|
|||||||
LONG_SCRIPT_NAME=$(basename $0)
|
LONG_SCRIPT_NAME=$(basename $0)
|
||||||
SCRIPT_NAME=${LONG_SCRIPT_NAME%.sh}
|
SCRIPT_NAME=${LONG_SCRIPT_NAME%.sh}
|
||||||
# Variable initialization, to avoid crash
|
# Variable initialization, to avoid crash
|
||||||
|
CRITICAL_ERRORS_NUMBER=0 # This will be used to see if a script failed, or passed
|
||||||
status=""
|
status=""
|
||||||
|
|
||||||
[ -r $CIS_ROOT_DIR/lib/constants.sh ] && . $CIS_ROOT_DIR/lib/constants.sh
|
[ -r $CIS_ROOT_DIR/lib/constants.sh ] && . $CIS_ROOT_DIR/lib/constants.sh
|
||||||
@ -21,6 +22,25 @@ if [ -z $status ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
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
|
case $status in
|
||||||
enabled | true )
|
enabled | true )
|
||||||
info "Checking Configuration"
|
info "Checking Configuration"
|
||||||
@ -43,3 +63,12 @@ case $status in
|
|||||||
warn "Wrong value for status : $status. Must be [ enabled | true | audit | disabled | false ]"
|
warn "Wrong value for status : $status. Must be [ enabled | true | audit | disabled | false ]"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
info "Results : "
|
||||||
|
if [ $CRITICAL_ERRORS_NUMBER = 0 ]; then
|
||||||
|
ok "Check Passed"
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
crit "Check Failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user