#!/bin/bash
# $Header: /cvs/WebShield/wsrc/files/mgmt/remove_extra_rules,v 1.2 2004/02/02 14:19:15 bwhittak Exp $
#
# (C) Copyright Networks Associates Techonolgy Inc. 2003
#
# Called by the UI to remove an extra.rule file obtained from user.
#
if [ -f $NETAWSS/.profile.vars ]; then
    . $NETAWSS/.profile.vars
else
    . /var/NAIENV/.profile.vars
fi
[[ "$PATH" == "$wsPATH":* || -z "$wsPATH" ]] || PATH=$wsPATH:$PATH

shopt -s extglob
shopt -s nullglob
. spam-functions

#Example output format
#echo "<OK/>"
#or
#echo "<Error>Error text</Error>"

echo '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
echo "<result>"
trap 'echo "</result>"' EXIT

[[ $# -gt 0 ]] || XMLdie "No file"

cd "$SPAMRPMEXTRA" || XMLdie "No extra rules directory"

a=( )

for f do
    t=( @("$f") "$f".*.rpm )	# RPM files matching argument
    [[ ${#t[@]} -gt 0 ]] || XMLdie "No file $f"
    a=( "${a[@]}" "${t[@]}" )
done

rm -f "${a[@]}"

# restart spamd
out=$(/etc/init.d/spamassassin_jail restart) || XMLdie "$out"

XMLele OK
