#!/bin/sh
#	$Author: zacheiss $
#	$Source: /mit/olcdev/mkserv/RCS/olc.add,v $
#	$Id: olc.add,v 2.3 1999/05/06 20:10:34 zacheiss Exp $
# 	$Revision: 2.3 $
#	$Platforms: vax,rt,decmips,sun4$

#### copying binaries (start)
# In order to get OLC binaries from the packs (when they start living
# there again, probably in 8.2), this section of olc.add should be
# removed and olc.sync should be changed as marked.

OpsOlc=/afs/athena.mit.edu/astaff/project/ops/services/olc
BINARIES=`/usr/athena/bin/athdir $OpsOlc`

if [ ! -d "${BINARIES}" ]; then
    echo "Binary directory not found! (binaries will not be installed)";
else
    for dir in "" /usr /usr/athena /usr/athena/etc; do
	if [ ! -d "${SERVERDIR}$dir" ]; then
	    echo "Creating ${SERVERDIR}$dir ..."
	    mkdir "${SERVERDIR}$dir"
	fi
    done

    for prog in olcd lumberjack rpd polld olcm; do
	if [ ! -f "${BINARIES}/$prog" ]; then
	    echo "Binary for '$prog' not found! (ignoring)"
	else
	    echo "Installing testing $prog ..."
	    rm -f ${SERVERDIR}/usr/athena/etc/$prog.old
	    mv -f ${SERVERDIR}/usr/athena/etc/$prog \
		    ${SERVERDIR}/usr/athena/etc/$prog.old
	    /usr/athena/bin/install -m 755 ${BINARIES}/$prog \
						${SERVERDIR}/usr/athena/etc
	fi
    done
fi
#### copying binaries (end)

#### Configuration variables

Oconf=/etc/athena/olc
Ospool=/var/athena/olc
olc_syslog=local6	# facility for OLC logging

host=`hostname | sed -e 's/\..*$//' | tr '[A-Z]' '[a-z]'`
fqdn=`hostinfo -h ${host} | tr '[a-z]' '[A-Z]'`

aliases=/etc/aliases
syslog_conf=/etc/syslog.conf
newsyslog_conf=/etc/athena/newsyslog.conf

case "`machtype`" in
  decmips) crontab=/etc/crontab ;
	   syslog_conf=/etc/nsyslog.conf ;;
     sun4) aliases=/etc/mail/aliases ;;
esac

#### Creating configuration directories

for dir in ${Oconf} ${Oconf}/specialties ${Oconf}/acls ${Oconf}/olcm; do
    if [ ! -d "$dir" ]; then
	echo "Creating $dir ..."
	mkdir "$dir"
    fi
done


#### Creating stub configuration files, if necessary

cat >> ${LOGFILE} <<EOF
===> Remember to install an olc.${host} srvtab in ${Oconf}/srvtab.
EOF

## title/instance database
if [ ! -f "${Oconf}/database" ]; then
    cat > "${Oconf}/database" <<EOF
# This file contains optional data about people using OLC.
# The format of each line (except comments) is
#	principal  user_title  max_questions consult_title  max_answer
# where user_title is the title used when asking a question, consult_title
# the title used when answering questions, and max_questions and max_answer
# the maximum numbers of questions that can be asked and answered
# (respectively) at any one time.  The default is:
#	<whoever>  user        1             consultant     2
# Titles must be one word and the numbers of instances >0.
# (Giving people >0 consulting instances does not bestow any consulting bits.)

# Example entry (commented out)
#bert@ATHENA.MIT.EDU        Watchmaker       20       consultant      20
EOF
    echo "===> You should probably edit ${Oconf}/database." >> ${LOGFILE}
fi

## Discuss prefix for lumberjack
if [ ! -f "${Oconf}/ds_prefix" ]; then
    echo "${fqdn}:/usr/spool/discuss/o" > "${Oconf}/ds_prefix"
fi

## hours
if [ ! -f "${Oconf}/hours" ]; then
    touch "${Oconf}/hours"
fi
if [ ! -s "${Oconf}/hours" ]; then
    echo "===> Edit ${Oconf}/hours if you wish to specify working hours." \
								>> ${LOGFILE}
fi

## list of services, currently only used by Mac OLxx
if [ ! -f "${Oconf}/services" ]; then
    cat > "${Oconf}/services" <<EOF
# A list of services used for the Mac OLx client.
# Lines starting with '#' are comments, while the rest have this format:
#       long name:hesiod service name
# (yes, the colon is the delimiter).  The "long name" is a description
# displayed in the client.  The "hesiod service name" is used by the client
# to find the host service machine via Hesiod.
Computer Consultants      - OLC:OLC
Teaching Assistants       - OLTA:olta
Reference Librarians      - OWL:owl
EOF
fi

## motd and motd_timeout aren't necessary at this point

## topics list (can't really create!)
if [ ! -f "${Oconf}/topics" ]; then
    touch "${Oconf}/topics"
fi

## specialties directory
if [ -s "${Oconf}/topics" ]; then
    if [ ! -d "${Oconf}/specialties" ]; then
	mkdir "${Oconf}/specialties"
    fi
    # now both the specialties directory and the topics file exist; compare.
    for topic in `awk '!/^#/{print $1}' "${Oconf}/topics"`; do
	if [ ! -f "${Oconf}/specialties/$topic.acl" ]; then
	    echo "===> Create ${Oconf}/specialties/$topic.acl"	>> ${LOGFILE}
	fi
    done
else
    # topics don't exist
    echo "===> Please create a list of topics in ${Oconf}/topics." \
								>> ${LOGFILE}
    echo "===> Create a <topic-name>.acl file in ${Oconf}/specialties" \
								>> ${LOGFILE}
    echo "===>   for each topic" 			>> ${LOGFILE}
fi

## acls: olc.acl
if [ ! -f "${Oconf}/acls/olc.acl" ]; then
    echo "*.*@ATHENA.MIT.EDU" > "${Oconf}/acls/olc.acl"
fi

## acls: admin.acl
if [ ! -f "${Oconf}/acls/admin.acl" ]; then
    touch "${Oconf}/acls/admin.acl"
fi
if [ ! -s "${Oconf}/acls/admin.acl" ]; then
    echo "===> Add admin types to ${Oconf}/acls/admin.acl" 	>> ${LOGFILE}
fi

## acls: consult.acl
if [ ! -f "${Oconf}/acls/consult.acl" ]; then
    touch "${Oconf}/acls/consult.acl"
fi
if [ ! -s "${Oconf}/acls/consult.acl" ]; then
    echo "===> Add consultants to ${Oconf}/acls/consult.acl" 	>> ${LOGFILE}
fi

## acls: gmessage.acl
if [ ! -f "${Oconf}/acls/gmessage.acl" ]; then
    touch "${Oconf}/acls/gmessage.acl"
fi
if [ ! -s "${Oconf}/acls/gmessage.acl" ]; then
    cat >> ${LOGFILE} <<EOF
===> Add people allowed to send messages without grabbing
===>   to ${Oconf}/acls/gmessage.acl
EOF
fi

## acls: other consult
for type in gask gchtopic gcomment grab gresolve monitor motd on; do
    if [ ! -f "${Oconf}/acls/${type}.acl" ]; then
	# -h breaks on Ultrix, but [1] graciously so, and [2] I don't care
	if [ -h "${Oconf}/acls/${type}.acl" ]; then
	    echo "===> WARNING: ${Oconf}/acls/${type}.acl is a dangling link" \
								>> ${LOGFILE}
	else
	    ln -s consult.acl "${Oconf}/acls/${type}.acl"
	fi
    fi
done

## hardware name translations file
if [ ! -f "${Oconf}/translations" ]; then
    # The translations don't currently work, even for DECstations, so
    # we might as well ignore this.
    cat > "${Oconf}/translations" <<EOF
0
0
EOF
fi

## olcm feed
if egrep -s "olcm" ${aliases}; then
    : # olcm exists in aliases file.
else
    echo "===> You may need to set up mail feeds for olcm."	>> ${LOGFILE}
fi

#### Creating spool directories

for dir in ${Ospool} ${Ospool}/questions ${Ospool}/donelogs \
           ${Ospool}/admin ${Ospool}/stats; do
    if [ ! -d "$dir" ]; then
	echo "Creating $dir ..."
	mkdir "$dir"
    fi
done

#### Creating stub spool files, if necessary

## ASCII backup file
if [ ! -f "${Ospool}/backup.ascii" ]; then
    cat > "${Ospool}/backup.ascii" <<EOF

EMPTY INITIAL QUEUE
This file will be overwritten by olcd.
It is here to start off olcd with an empty queue.
The arrangement of whitespace and non-whitespace lines *does* matter!
[If the queue was written by olcd, this block would be statistics.]

[This line would be the number of knuckles.]
EOF
fi

## don't create queue file, olcd will do that for us.

## Create stats files.
if [ ! -f "${Ospool}/stats/ask_stats" ]; then
    touch "${Ospool}/stats/ask_stats"
fi
if [ ! -f "${Ospool}/stats/res_stats" ]; then
    touch "${Ospool}/stats/res_stats"
fi

## create syslog file
if [ ! -f "${Ospool}/admin/syslog" ]; then
    touch "${Ospool}/admin/syslog"
fi

#### Other configuration files

## syslog.conf
if egrep -s "^${olc_syslog}" ${syslog_conf}; then
    : # Not editing ${syslog_conf}.
else
    echo "Editing ${syslog_conf}."
    echo "${olc_syslog}.debug			${Ospool}/admin/syslog" \
							    >> ${syslog_conf}
fi

## newsyslog.conf
if egrep -s "^${Ospool}/admin/syslog" ${newsyslog_conf}; then
    : # Not editing ${newsyslog_conf}.
else
    echo "Editing ${newsyslog_conf}."
    echo "${Ospool}/admin/syslog 600 10 100 * ZD" 	>> ${newsyslog_conf}
fi

## crontab
if [ -z "${crontab}" ]; then
    # no crontab, use root's
    crtmp=/tmp/olc.crontab.$$
    crontab -l > $crtmp
else
    # crontab exists
    crtmp="${crontab}"
fi
if egrep -s "polld" ${crtmp}; then
    : # Not editing crontab.
else
    echo "Editing crontab."
    echo "1,11,21,31,41,51 * * * *	/usr/athena/etc/polld" 	>> ${crtmp}

    if [ -z "${crontab}" ]; then
	# revert root's crontab
	crontab < $crtmp
	rm -f $crtmp
    fi
fi

#### rc.conf variables

echo "conf OLC true"		>> ${CONFCNG}
echo "conf AUTOUPDATE false"	>> ${CONFCNG}
# Note: based on past record, turning off AUTOUPDATE is a very recommended
#       step for OLC servers. =)


cat >> ${LOGFILE} <<EOF
===> If you haven't done so, create a discuss archive for each topic.
EOF

exit 0
