#! /bin/sh
#
#  @(#)install_cmgr	2.9 9/14/91
#
#  Copyright (c) 1987-1990 Sun Microsystems, Inc.
#  All Rights Reserved.
#
#  Sun considers its source code as an unpublished, proprietary
#  trade secret, and it is available only under strict license
#  provisions.  This copyright notice is placed here only to protect
#  Sun in the event the source is deemed a published work.  Dissassembly,
#  decompilation, or other means of reducing the object code to human
#  readable form is prohibited by the license agreement under which
#  this code is provided to the user or company in possession of this
#  copy.
#
#  RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
#  Government is subject to restrictions as set forth in subparagraph
#  (c)(1)(ii) of the Rights in Technical Data and Computer Software
#  clause at DFARS 52.227-7013 and in similar clauses in the FAR and
#  NASA FAR Supplement.
#
#
#  install_cmgr is a script to bring down the Calendar Manager Service Daemon
#  if one exists and update the /etc/inetd.conf file initiate the
#  daemon by inetd.  After inetd.conf has been changed, a signal HUP is sent
#  to inetd.  This script should be run for the first time installation or
#  after a Deskset upgrade.
#

PATH="/bin:/usr/ucb:/usr/bin:/etc"
export PATH

DEFAULT=/usr/etc
OPENDIR=$OPENWINHOME/bin
CMSD=$OPENDIR/rpc.cmsd

if [ `whoami` != "root" ]
then
	echo "install_cmgr: Must be run in super-user mode."
	exit 1
fi

if [ "$OPENWINHOME" = "" ]
then
	echo 'Installation failed because $OPENWINHOME is undefined.'
	echo 'Please set $OPENWINHOME and rerun this script.'
	exit 1
else
	echo "Installing $CMSD..."
fi

UNAME=`uname -r 2>/dev/null` ||.;
case $UNAME in
	'') PID=`ps ax | grep 'rpc.cmsd$' | grep -v grep`;;
	4.*) PID=`ps ax | grep 'rpc.cmsd$' | grep -v grep`;;
	*) PID=`ps -e | grep 'rpc.cmsd$' | grep -v grep`;;
esac
if [ "$PID" != "" ]
then
	echo "Bringing down rpc.cmsd process..."
	echo ""
	set $PID
	kill $1
fi

ENTRY=`grep "^100068/" /etc/inetd.conf`
if [ $? -eq 0 ]
then
#
# inetd.conf has an entry already; probably upgrading the daemon.
# remove the entry and readd the new entry. The next stuff (ex)
# must start in the first column.
#
	sed "s/^100068/#100068/
t add
b noop
:add
a\\
100068/2-3	dgram	rpc/udp	wait root $OPENDIR/rpc.cmsd	rpc.cmsd
d
:noop" < /etc/inetd.conf > /etc/inetd.conf+
	mv /etc/inetd.conf+ /etc/inetd.conf
else
	cat >> /etc/inetd.conf <<ADD_THIS
#
# rpc.cmsd is a data base daemon which manages calendar data backed
# by files in /usr/spool/calendar
100068/2-3	dgram	rpc/udp	wait root $OPENDIR/rpc.cmsd	rpc.cmsd
ADD_THIS
fi

#
# Notify inetd to read the new inetd.conf
#
case $UNAME in
	'') PID=`ps ax | grep 'inetd$' | grep -v grep`;;
	4.*) PID=`ps ax | grep 'inetd$' | grep -v grep`;;
	*) PID=`ps -e | grep 'inetd$' | grep -v grep`;;
esac
if [ "$PID" = "" ]
then
	echo "Unable to notify inetd to read the new inetd.conf."
	echo "Please issue 'kill -HUP pid-of-inetd' manually to reset inetd."
	echo "Installation is partial completed."
else
	set $PID
	kill -HUP $1
	echo "Installation is completed and inetd is set up for the new daemon."
fi
