🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #2386

Re: Removing newsgroups on an INN server (was Re: Active.times)

#2386
From: Joe Greco
Date: Tue, 25 Jan 1994 16:36
224 lines
6595 bytes
In news.software.nntp article <2hm51qINN8cn@rodan.uu.net>, rsalz@uunet.uu.net (Rich Salz) wrote:
:I want to include such a script in 1.5; it would help if I someone else
:sent me a good one.

I sent the following to Rich.  I took my "removegroup" script and reworked
it to be more portable and INN-ish, and may have introduced a hidden bug or
two in the process(?)  ;-)  but it works well.


Subject: INN-compatible removegroup script
To: rsalz@uunet.uu.net
Date: Fri, 21 Jan 94 18:03:00 CST

Hi all,

What follows is a version of a removegroup(s) script that I've been using.
I went through this afternoon and removed dependencies for my system, so it
should run with little or no modification.

It will:

1) lock files and pause INN to prevent confusion
2) hit INN with a rmgroup
3) delete the entries from "newsgroups" and "active.times"
4) delete the news articles
5) delete the news overview database for the group
6) Try to do rudimentary directory pruning (possibly not very portably).

7) (my personal pet peeve about a lot of things) It will delete a LOT OF
GROUPS AT ONCE if specified on the command line (although it will thrash
around with the newsgroups and active.times files)

I do not promise that it is bug free or even correct, it simply works for
me.  You are welcome to use it in any way, shape, or form, provided of
course that I get credit for the initial revision.  I'd also like to hear of
any corrections or enhancements!

Enjoy,

.. Joe

-------------------------------------------------------------------------------
Joe Greco - Systems Administrator			      jgreco@ns.sol.net
Solaria Public Access UNIX - Milwaukee, WI			   414/342-4847


#! /bin/sh -
#
# Script to remove one or more newsgroups.
#
# BUGS:
# We should probably log the use of this script someplace...
# The path to the overview data is hardwired since there is no hook for this
# in innshellvars.
# The path to the news spool is hardwired since there is no hook for this
# in innshellvars.
# A more portable way to delete an empty directory could be found.  Works
# for me though.
# Doesn't delete pathnames from the history file.
# No command-line options.  :-/  Although you probably always want to do the
# same things each time anyways.
#
# removegroup <groupname>
#
# Joe Greco <jgreco@ns.sol.net>
#
# 940103 Initial translation to INN
# 940120 Cleanups

##  =()<. @<_PATH_SHELLVARS>@>()=
. /usr/local1/news/innshellvars

# Some defaults.
DOACTIVETIMES=true
DONEWSGROUPS=true
DODELETE=true
DORMDIR=true
DODELETEOVER=true

PROGNAME=`basename $0`

OVERVIEWDIR=/var/spool/news
OVERVIEW=.overview
SPOOL=/var/spool/news

# Check who is running this.

if [ "${NEWSUSER}" != "`whoami`" ]; then
	echo "${PROGNAME}: only ${NEWSUSER} wants to run ${PROGNAME}." 1>&2
	exit 1
fi

# Don't run if news.daily is active, just in case.

if [ -f "${DAILY}" ]; then
	echo "${PROGNAME}: news.daily in progress." 1>&2
	exit 1
fi

# Pause INN so that it doesn't hash what we are doing to newsgroups or
# active.times.

INNMODE="${PROGNAME}[$$] deleting groups"

ctlinnd -s pause "${INNMODE}"

# Lock the newsgroups file.

if ${DONEWSGROUPS} ; then
	NLOCK=${LOCKS}/LOCK.newsgroups
	NTEMP=${TMPDIR}/newsgroups.new
	PID=$$
	TRY=0
	MAXTRY=60
	export NLOCK MAXTRY PID LOGFILE TRY NTEMP
	while [ ${TRY} -lt ${MAXTRY} ]; do
		shlock -p ${PID} -f ${NLOCK} && break
		sleep 2
		TRY=`expr ${TRY} + 1`
	done

	# Did we catch the lock?

	test ${TRY} -lt ${MAXTRY} || {
		echo "${PROGNAME}: newsgroups locked by" `cat ${NLOCK}` 1>&2
		exit 1
	}

	rm -f ${NTEMP}
fi

# Lock the active.times file (does this need to be done?).

if ${DOACTIVETIMES} ; then
	ALOCK=${LOCKS}/LOCK.active.times
	ATEMP=${TMPDIR}/active.times.new
	PID=$$
	TRY=0
	MAXTRY=60
	export ALOCK MAXTRY PID LOGFILE TRY ATEMP
	while [ ${TRY} -lt ${MAXTRY} ]; do
		shlock -p ${PID} -f ${ALOCK} && break
		sleep 2
		TRY=`expr ${TRY} + 1`
	done

	# Did we catch the lock?

	test ${TRY} -lt ${MAXTRY} || {
		echo "${PROGNAME}: active.times locked by" `cat ${ALOCK}` 1>&2
		exit 1
	}

	rm -f ${ATEMP}
fi

while [ "$*" ]; do
	grep "^$1 " ${ACTIVE} > /dev/null 2>&1 || {
		# Group does not exist
		echo "${PROGNAME}: ${1} not found" 1>&2
		shift
		continue
	}

	# Do the work.
	ctlinnd -s rmgroup "$1"

	# Remove the newsgroups line.
	if ${DONEWSGROUPS} ; then
		${EGREP} -v "^$1[ 	]" < ${NEWSGROUPS} > ${NTEMP}
		cat ${NTEMP} > ${NEWSGROUPS}
	fi

	# Remove the active.times line.
	if ${DOACTIVETIMES} ; then
		${EGREP} -v "^$1[ 	]" < ${ACTIVETIMES} > ${ATEMP}
		cat ${ATEMP} > ${ACTIVETIMES}
	fi

	DOTTOSLASH="`echo $1 | sed 's:\.:/:g'`"
	#DOTTOSLASH="`echo $1 | tr \. \/`"

	# Delete the spool articles.
	if ${DODELETE} ; then
		FILEDIR="${SPOOL}/${DOTTOSLASH}"
		# Incremental delete in case we have a lot of files.
		(cd ${FILEDIR}; rm -f [1-5][0-9]*; rm -f [6-9][0-9]*)
	fi

	# Delete the overview file.
	if ${DODELETEOVER} ; then
		FILEDIR="${OVERVIEWDIR}/${DOTTOSLASH}"
		(cd ${FILEDIR}; rm ${OVERVIEW})
	fi

	# (try to) Delete the directory, if it is empty.  Also possibly
	# clean up the parent directories.
	if ${DORMDIR} ; then
		FILEDIR="${SPOOL}/${DOTTOSLASH}"
		while rmdir ${FILEDIR} 2> /dev/null ; do
			FILEDIR="`dirname ${FILEDIR}`"
		done
	fi

	shift
done

# Unlock newsgroups.

if ${DONEWSGROUPS} ; then
	rm -f ${NLOCK} ${NTEMP}
fi

# Unlock active.times.

if ${DOACTIVETIMES} ; then
	rm -f ${ALOCK} ${ATEMP}
fi

# And away we go!

ctlinnd -s go "${INNMODE}"

exit 0
Technical Details
Message-ID: <2i3hr4$80o@fleis.moneng.mei.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!xlink.net!rz.uni-karlsruhe.de!news.uni-ulm.de!zib-berlin.de!zrz.TU-Berlin.DE!netmbx.de!Germany.EU.net!EU.net!howland.reston.ans.net!news.moneng.mei.com!fleis.moneng.mei.com!not-for-mail
References: <2hk37f$mv5@nermal.cs.uoguelph.ca> <BRYAN.94Jan19125036@solstice.jpl.nasa.gov> <2hm51qINN8cn@rodan.uu.net>

Show Full Headers
Complete Article Headers
Message-ID: <2i3hr4$80o@fleis.moneng.mei.com>
Subject: Re: Removing newsgroups on an INN server (was Re: Active.times)
Date: Tue, 25 Jan 1994 16:36:52 +0000
From: jgreco@fleis.moneng.mei.com (Joe Greco)
References: <2hk37f$mv5@nermal.cs.uoguelph.ca> <BRYAN.94Jan19125036@solstice.jpl.nasa.gov> <2hm51qINN8cn@rodan.uu.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!archive!mbox2nntp-news.software.readers.mbox.zip!gmd.de!xlink.net!rz.uni-karlsruhe.de!news.uni-ulm.de!zib-berlin.de!zrz.TU-Berlin.DE!netmbx.de!Germany.EU.net!EU.net!howland.reston.ans.net!news.moneng.mei.com!fleis.moneng.mei.com!not-for-mail
Newsgroups: news.software.nntp,news.software.readers
Organization: Solaria Public Access UNIX - Milwaukee, WI
Lines: 225
Distribution: inet
NNTP-Posting-Host: fleis.moneng.mei.com