#!/bin/bash
# 
# Copyright (c) 2012 Tresys Technology LLC, Columbia, Maryland, USA
#
# This software was developed by Tresys Technology LLC
# with U.S. Government sponsorship.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FILE=/etc/audit/audit.rules

[ -f $FILE ] || exit 1

# add_rule with no order
add_rule() {
	/bin/grep -qP -- "^$1$" $FILE && return
	/bin/sed -i -r -e "/^# Feel free/a$1" $FILE
}

# add_after 'RULE' 'regex'
add_after() {
	/bin/grep -qPzo -- "$2\n$1" $FILE && return
	/bin/sed -i -r -e "/^$(/bin/echo -n $1 | /usr/bin/tr "/" ".")$/d" $FILE
	/bin/sed -i -r -e "/$2/a$1" $FILE
/bin/echo =================
/bin/cat $FILE
}
