#! /bin/sh
##  $Revision: 1.14 $
##  Rmgroup control-message handler

PROG=rmgroup
##  Some shells don't pass in $* unless we explicitly pass it in here.
## =()<. @<_PATH_PARSECTL>@ "$@">()=
. /usr/local/news/parsecontrol "$@"

case ${ACTION} in
mail)
    grep "^$1 " ${ACTIVE} >/dev/null 2>&1 || {
	# Group doesn't exist
	exit
    }
    P1=$1
    export FROM P1 NEWSBIN ARTICLE
    (
	echo "${FROM} requested that ${P1} be removed."
	echo 'To do this, type the following:'
	echo "	${NEWSBIN}/ctlinnd rmgroup ${P1}"
	echo ''
	echo 'The full article was:'
	cat ${ARTICLE}
    ) | ${MAILCMD} -s "rmgroup $1 by ${FROM}" ${NEWSMASTER}
    exit
    ;;
esac

##  Make sure the article is approved and that the group exists.
sed -e '/^$/q' <$ARTICLE >${TEMP}
grep '^Approved:' <${TEMP} >/dev/null 2>&1 || {
    ${WRITELOG} ${LOGFILE} "Unapproved rmgroup by ${FROM}" <${ARTICLE}
    rm ${TEMP}
    exit
}
rm ${TEMP}
grep "^$1 " ${ACTIVE} >/dev/null 2>&1 || {
    # Group doesn't exist
    exit
}

case ${ACTION} in
logit)
    ${WRITELOG} ${LOGFILE} "rmgroup $1 by ${FROM} skipped" <${ARTICLE}
    exit
    ;;
esac

##  Do the work.
ctlinnd -s rmgroup "$1"
${WRITELOG} ${LOGFILE} "rmgroup $1 by ${FROM}" <${ARTICLE}
grep -v "^$1[ 	]" <${NEWSGROUPS} >${TEMP}
cat ${TEMP} >${NEWSGROUPS}
#I don't know about this:
#sed -e "s/^$1 /# `date` $1 /" <${ACTIVETIMES} >${TEMP}
#cat ${TEMP} >${ACTIVETIMES}

exit
