#!/bin/sh
#
# LAST CHANGE: Damjan Lampret, 19/Jan/2000
#

#if [ "${USER}" != "root" ]; then
#	echo Must be run with root priviledges
#	exit 1
#fi

#export BASH_ENV=/root/.bashrc
export TERM=xterm

cd /home/oc/ml-archive

for ARCH_DIR in *.listarchive ; do
	ARCH_DIR=`echo ${ARCH_DIR} | cut -f1 -d '.'`
#	if [ -s ${ARCH_DIR}.listarchive/listarchive ]; then
		mkdir ${ARCH_DIR}.tmp
		nice -n 20 /usr/local/mhonarc/mhonarc -sort -reverse -tsort -treverse -outdir ${ARCH_DIR}.tmp ${ARCH_DIR}.listarchive/listarchive 2> /dev/null
		chown oc.users  ${ARCH_DIR}.tmp/*.html
		chown oc.users  ${ARCH_DIR}.tmp/.mhonarc.db
		cp ml-convert.cgi ${ARCH_DIR}.tmp
		cd ${ARCH_DIR}.tmp
		./ml-convert.cgi
		chown oc.users *
		cd ..
		cp -pr ${ARCH_DIR}.processed ${ARCH_DIR}.old
		ln -s ${ARCH_DIR}.old ${ARCH_DIR}
		rm -rf ${ARCH_DIR}.processed
		mv ${ARCH_DIR}.tmp ${ARCH_DIR}.processed
		chown oc.users ${ARCH_DIR}.processed
		rm ${ARCH_DIR}
		ln -s ${ARCH_DIR}.processed ${ARCH_DIR}
		rm -rf ${ARCH_DIR}.old
		chown oc.users ${ARCH_DIR}
#               ./email_conv.pl /home/oc/ml-archive/${ARCH_DIR}
#	fi

        echo -e ""
done
