Fix some bugs and add apply method for CentOS.

This commit is contained in:
Samson-W 2019-08-26 18:03:29 +08:00
parent 783d6e4455
commit f5de9a24f9
2 changed files with 23 additions and 11 deletions

View File

@ -54,11 +54,11 @@ audit_debian () {
audit_redhat () {
check_param_pair_by_value $FILE_REDHAT $OPTIONNAME ge $CONDT_VAL
if [ $FNRET = 0 ]; then
ok "$OPTIONNAME set condition is $CONDT_VAL"
ok "Option $OPTIONNAME set condition is $CONDT_VAL in $FILE_REDHAT"
elif [ $FNRET = 1 ]; then
crit "$OPTIONNAME set condition is not set $CONDT_VAL"
crit "Option $OPTIONNAME set condition is not set $CONDT_VAL in $FILE_REDHAT"
elif [ $FNRET = 2 ]; then
crit "$OPTIONNAME is not conf"
crit "Option $OPTIONNAME is not conf in $FILE_REDHAT"
elif [ $FNRET = 3 ]; then
crit "Config file $FILE_REDHAT is not exist!"
fi
@ -97,7 +97,17 @@ apply_debian () {
}
apply_redhat () {
:
if [ $FNRET = 0 ]; then
ok "$OPTIONNAME set condition is $CONDT_VAL in $FILE_REDHAT"
elif [ $FNRET = 1 ]; then
warn "Set option $OPTIONNAME to $CONDT_VAL in $FILE_REDHAT"
replace_in_file $FILE_REDHAT "^$OPTIONNAME.*" "$OPTIONNAME = $CONDT_VAL"
elif [ $FNRET = 2 ]; then
warn "$OPTIONNAME is not conf, add to $FILE_REDHAT"
add_end_of_file $FILE_REDHAT "$OPTIONNAME = $CONDT_VAL"
elif [ $FNRET = 3 ]; then
crit "Config file $FILE_REDHAT is not exist!"
fi
}
# This function will be called if the script status is on enabled mode

View File

@ -595,18 +595,20 @@ check_param_pair_by_value ()
# OPTION="minlen"
# COMPARE="ge"
# OP_VALUE=15
if [ -f "$FILENAME" ];then
RESULT=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $FILENAME | grep "^$OPTION[[:space:]]=[[:space:]]")
if [ $(echo $RESULT | wc -l) -eq 1 ]; then
COUNT=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $FILENAME | grep "^$OPTION[[:space:]]=[[:space:]]" | wc -l)
if [ $COUNT -eq 1 ]; then
debug "$OPTION is conf"
RESULT=$(sed -e '/^#/d' -e '/^[ \t][ \t]*#/d' -e 's/#.*$//' -e '/^$/d' $FILENAME | grep "^$OPTION[[:space:]]=[[:space:]]")
if [ "$(echo $RESULT | awk -F'= ' '{print $2}')" "-$COMPARE" "$OP_VALUE" ]; then
debug "$OPTION conf is right."
FNRET=0
debug "$OPTION conf is right."
FNRET=0
else
debug "$OPTION conf is not right."
FNRET=1
debug "$OPTION conf is not right."
FNRET=1
fi
else
else
debug "$OPTION is not conf of $FILENAME"
FNRET=2
fi