debian-cis/lib/main.sh

75 lines
2.1 KiB
Bash
Raw Normal View History

2016-04-01 16:48:31 +02:00
LONG_SCRIPT_NAME=$(basename $0)
SCRIPT_NAME=${LONG_SCRIPT_NAME%.sh}
# Variable initialization, to avoid crash
2016-04-17 23:10:47 +02:00
CRITICAL_ERRORS_NUMBER=0 # This will be used to see if a script failed, or passed
2016-04-01 16:48:31 +02:00
status=""
[ -r $CIS_ROOT_DIR/lib/constants.sh ] && . $CIS_ROOT_DIR/lib/constants.sh
[ -r $CIS_ROOT_DIR/etc/hardening.cfg ] && . $CIS_ROOT_DIR/etc/hardening.cfg
[ -r $CIS_ROOT_DIR/lib/common.sh ] && . $CIS_ROOT_DIR/lib/common.sh
[ -r $CIS_ROOT_DIR/lib/utils.sh ] && . $CIS_ROOT_DIR/lib/utils.sh
# Source specific configuration file
[ -r $CIS_ROOT_DIR/etc/conf.d/$SCRIPT_NAME.cfg ] && . $CIS_ROOT_DIR/etc/conf.d/$SCRIPT_NAME.cfg
# Environment Sanitizing
export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
info "Working on $SCRIPT_NAME"
if [ -z $status ]; then
crit "Could not find status variable for $SCRIPT_NAME, considered as disabled"
exit 2
2016-04-01 16:48:31 +02:00
fi
2016-04-17 23:10:47 +02:00
# Arguments parsing
while [[ $# > 0 ]]; do
ARG="$1"
case $ARG in
--audit)
if [ $status != 'disabled' -a $status != 'false' ]; then
2016-04-17 23:10:47 +02:00
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
2016-04-01 16:48:31 +02:00
case $status in
2016-04-04 11:23:03 +02:00
enabled | true )
info "Checking Configuration"
check_config
2016-04-01 16:48:31 +02:00
info "Performing audit"
audit # Perform audit
info "Applying Hardening"
apply # Perform hardening
;;
audit )
2016-04-04 11:23:03 +02:00
info "Checking Configuration"
check_config
2016-04-01 16:48:31 +02:00
info "Performing audit"
audit # Perform audit
;;
disabled | false )
info "$SCRIPT_NAME is disabled, ignoring"
exit 2 # Means unknown status
2016-04-01 16:48:31 +02:00
;;
*)
warn "Wrong value for status : $status. Must be [ enabled | true | audit | disabled | false ]"
;;
esac
2016-04-17 23:10:47 +02:00
if [ $CRITICAL_ERRORS_NUMBER = 0 ]; then
ok "Check Passed"
exit 0 # Means ok status
2016-04-17 23:10:47 +02:00
else
crit "Check Failed"
exit 1 # Means critical status
2016-04-17 23:10:47 +02:00
fi