> ${TmpRules}
for rules in $(/bin/ls -1v ${SourceRulesDir} | grep "\.rules$") ; do
cat ${SourceRulesDir}/${rules}
done | awk '
BEGIN {
minus_e = "";
minus_D = "";
minus_f = "";
minus_b = "";
rest = 0;
} {
if (length($0) < 1) { next; }
if (match($0, "^\\s*#")) { next; }
if (match($0, "^\\s*-e")) { minus_e = $0; next; }
if (match($0, "^\\s*-D\\s*$")) { minus_D = $0; next; }
if (match($0, "^\\s*-f")) { minus_f = $0; next; }
if (match($0, "^\\s*-b")) { minus_b = $0; next; }
rules[rest++] = $0;
}
END {
printf "%s\n%s\n%s\n", minus_D, minus_b, minus_f;
for (i = 0; i < rest; i++) { printf "%s\n", rules[i]; }
printf "%s\n", minus_e;
}' >> ${TmpRules}
# If empty then quit
if [ ! -s ${TmpRules} ]; then
echo "$0: No rules"
rm -f ${TmpRules}
try_load
exit $RETVAL
fi
# If the same then quit
cmp -s ${TmpRules} ${DestinationFile} > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo "$0: No change"
rm -f ${TmpRules}
try_load
exit $RETVAL
elif [ $OnlyCheck -eq 1 ] ; then
echo "$0: Rules have changed and should be updated"
rm -f ${TmpRules}
exit 0
fi
# Otherwise we install the new file
if [ -f ${DestinationFile} ]; then
cp ${DestinationFile} ${DestinationFile}.${ASuffix}
fi
# We copy the file so that it gets the right selinux lable
cp ${TmpRules} ${DestinationFile}
chmod 0640 ${DestinationFile}
# Restore context on MLS system. /tmp is SystemLow & audit.rules is SystemHigh
if [ -x /usr/sbin/restorecon ] ; then
/usr/sbin/restorecon -F ${DestinationFile}
fi
rm -f ${TmpRules}
try_load
exit $RETVAL