home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Unix System Administration Handbook 1997 October
/
usah_oct97.iso
/
news
/
cnews.tar
/
ctl
/
checkgroups
next >
Wrap
Text File
|
1994-09-08
|
3KB
|
103 lines
#! /bin/sh
# checkgroups - check active file for missing or extra newsgroups or groups
# with incorrect moderation status, and update the newsgroups file.
# stdin must a checkgroups news article
# =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
. ${NEWSCONFIG-/etc/news/bin/config}
PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH ; export PATH
desc=/tmp/cg$$d
hiers=/tmp/cg$$h
canact=/tmp/cg$$a
newact=/tmp/cg$$n
diffs=/tmp/cg$$df
actgrps=/tmp/cg$$ag
newgrps=/tmp/cg$$ng
samegrps=/tmp/cg$$sg
addgrps=/tmp/cg$$ad
remgrps=/tmp/cg$$rm
sameact=/tmp/cg$$sa
samenew=/tmp/cg$$sn
modchng=/tmp/cg$$mc
umask $NEWSUMASK
trap 'rm -f /tmp/cg$$* ; trap 0 ; exit' 0 1 2 15
# behead stdin (checkgroups article) & ignore lines that don't fit the syntax
# (should just be able to reject tabless lines, but Bitnet buggers that).
# ignore signatures and initial !mod lines.
ngalpha='-_+a-zA-Z0-9'
sed -n -e '1,/^$/d' -e '1{/^!mod$/d;}' -e '/^-- $/,$d' \
-e "/^[$ngalpha][ ][ ]*/p" \
-e "/^[$ngalpha][$ngalpha.]*[$ngalpha][ ][ ]*/p" \
>$desc
# generate list of hierarchies affected
sed 's/\..*//' $desc | sort -u >$hiers
# backup newsgroups before updating it
if test -r $NEWSCTL/newsgroups
then
cp $NEWSCTL/newsgroups $NEWSCTL/newsgroups.bac || exit 1
else
>$NEWSCTL/newsgroups.bac
fi
# toss out old newsgroups rubbish
hierlist="`cat $hiers`" # message is assumed authoritative for these
hierpat="` echo $hierlist | tr ' ' , `" # one more time, with commas
(gngp -av "$hierpat" $NEWSCTL/newsgroups.bac
# add new newsgroups rubbish
cat $desc) >$NEWSCTL/newsgroups
# canonicalise active file & select interesting hierarchies
awk '{
modstat = $4
if (modstat != "y" && modstat != "m")
modstat = "y"
print $1, modstat
}' $NEWSCTL/active | gngp -a "$hierpat" | sort >$canact
# canonicalise body into an active-file-like thing
awk '
/Moderated/ { print $1, "m" } # TODO: " (Moderated)$"? as per B 2.11.19
!/Moderated/ { print $1, "y" }
' $desc | sort >$newact
# what's different? first, what groups have vanished or appeared?
sed 's/ .*//' $canact >$actgrps
sed 's/ .*//' $newact >$newgrps
comm -12 $actgrps $newgrps >$samegrps
comm -23 $actgrps $newgrps >$remgrps
comm -13 $actgrps $newgrps >$addgrps
if test -s $remgrps; then
echo
echo 'obsolete groups:'
cat $remgrps
fi >$diffs
if test -s $addgrps; then
echo
echo 'new groups:'
join $addgrps $newact
fi >>$diffs
# next, what surviving groups have changed moderation status?
join $samegrps $canact >$sameact
join $samegrps $newact >$samenew
comm -13 $sameact $samenew >$modchng
if test -s $modchng; then
echo
echo 'groups needing moderation status changed to that shown:'
cat $modchng
fi >>$diffs
if test -s $diffs; then
(echo "Subject: possible active file problems"; echo;
echo "If you believe this checkgroups control message for hierarchies"
echo "\`$hierpat', the following differences may reflect groups"
echo "that should be added, deleted, or have their moderation"
echo "status(es) changed:"
cat $diffs) | report 'checkgroups output'
fi
exit 0 ## end of new one