#!/bin/csh -fx
# User interface for pmdc.  Compiles and installs a Personal Mail Daemon.
#
# Usage: install_pmd [-A] rules-file [pmd-file-name]
#

# this is the home directory for the pmdc system.
# it will need to be changed depending on where the system is installed
set noforward
set pmdc=/usr/local/lib/pmdc

if($#argv > 1 && $1 == '-A') then
    set athena
    shift
else if($#argv > 1 && $1 == '-n') then
    set noforward
    shift
endif

if($#argv == 0 || $#argv > 2) then
    echo "Usage: install_pmd [-A] rules-file [pmd-file-name]"
    exit 1
else if($#argv == 1) then
    set pmd=/pozzo/usr/src.LOCAL/cmd/pmdc/.pmd
else if($2 !~ /*) then
    echo "Pmd name must be absolute."
    exit 1
else
    set pmd=$2
endif

echo "Parsing rules file..."
${pmdc}/pmdc < $1 > /tmp/pmdc$$.c
if($status) then
    echo "Cleaning up..."
    rm -f /tmp/pmdc$$.c
    exit 1
endif

echo "Compiling pmd..."
chdir /tmp
cc -o pmdc$$ -O -s -I${pmdc} pmdc$$.c ${pmdc}/runtime.o

if($status) then
    echo "Cleaning up..."
    exit 1
endif

rm -f pmdc$$.c
rm -f pmdc$$.o

echo "Installing new pmd..."

# Now do the actual install
mv -f /tmp/pmdc$$ $pmd
chmod 4755 $pmd
exit
