muddy/
muddy/CVS/
muddy/area/
muddy/area/CVS/
muddy/clans/CVS/
muddy/classes/CVS/
muddy/doc/
muddy/doc/CVS/
muddy/etc/CVS/
muddy/etc/i3/
muddy/etc/i3/CVS/
muddy/imc/CVS/
muddy/lang/CVS/
muddy/licenses/CVS/
muddy/msgdb/CVS/
muddy/new/CVS/
muddy/notes/
muddy/player/
muddy/races/CVS/
muddy/religions/CVS/
muddy/src/CVS/
muddy/src/comm/CVS/
muddy/src/db/CVS/
muddy/src/intermud/
muddy/src/intermud/CVS/
muddy/src/irc/CVS/
muddy/src/olc/CVS/
#!/bin/sh
umask 002

LC_ALL=ru_RU.KOI8-R

export LC_ALL

lastlog=tmp/lastlog
muddy=bin/muddy
index=0

cd ~mudsrv/muddy

if [ -r tmp/shutdown.txt ]; then
    rm tmp/shutdown.txt
fi

if [ -x bin/strgrep ]; then
    bin/strgrep
fi

while [ 1 ]
do
    if [ -r $lastlog ]; then
        index=`cat $lastlog`
    fi

    while [ 1 ]
    do
        logfile=`printf "log/%05d.log" $index`
        if [ -r $logfile ]
        then
            index=$(($index + 1))
        else
            break
        fi
    done

    echo $(($index+1)) > $lastlog
    $muddy >$logfile 2>&1
    exitcode=$?

    avail=`df -k /home | tail -1 | awk '{ print $4 }'`
    if [ -r muddy.core ]
    then
        chmod g+rw muddy.core
        if [ $avail -gt 65535 ]
        then
            mv muddy.core corefiles/core.$index
            cp -p $muddy corefiles/muddy.$index
        else
            echo `date` "Low space (${avail}k) on disk: corefile not renamed" >> $logfile
        fi
        sleep 5
        continue
    fi

    if [ -r tmp/shutdown.txt ]
    then
        rm -f tmp/shutdown.txt
        break
    fi

    if [ $exitcode -ne 0 ]
    then
        break
    fi
    sleep 5
done