#! /bin/sh

# SCCS file install_newcm rev 1.3 created 1/4/94 at 15:18:57

# Copyright 1993 by Amdahl Corporation, Sunnyvale, CA.
#
#			All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software
# and its documentation for any purpose and without fee is hereby
# granted, provided that the above copyright notice appears in all
# copies and that both that copyright notice and this permission
# notice appear in supporting documentation, and that the name of
# Amdahl not be used in advertising or publicity pertaining to
# distribution of the software without specific prior written
# permission. Amdahl Corp. makes no representations or warranty,
# either express or implied, with respect to this software, its
# quality, performance, or about the suitability of this software
# for any purpose.
# 
# AMDAHL CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  AS A
# RESULT, THIS SOFTWARE IS PROVIDED "AS IS" AND YOU THE USER ARE
# ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND PERFORMANCE.  IN
# NO EVENT SHALL AMDAHL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

#################################################################
# PLEASE MODIFY THE FOLLOWING TO INDICATE THE SOURCE AND TARGET #
# DIRECTORIES FOR NEWCM_D					#
#################################################################

# SRCDIR should be set to the directory containing the compiled newcm_d.
SRCDIR=/usr/local/src/newcm_d-1.1

# TGTDIR should be set to the directory where newcm_d should be installed.
TGTDIR=/usr/etc


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

NCM=$SRCDIR/newcm_d

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

if [ ! -x $NCM ]; then
  echo The executable $NCM does not exist... Exiting...
  exit 1
fi

echo "newcm_d - Copyright 1993 Amdahl Corporation"
echo "$0 installs the rpc.cmsd replacement daemon in $TGTDIR"
echo "from $SRCDIR, and modifies /etc/inetd.conf to start up"
echo "newcm_d instead of rpc.cmsd."

cp $NCM $TGTDIR/newcm_d
chmod 0700 $TGTDIR/newcm_d

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 must
# start in the first column.
#
        sed "s/^100068/#100068/
t add
b noop
:add
a\\
100068/3      dgram  rpc/udp wait root $TGTDIR/newcm_d     newcm_d
d
:noop" < /etc/inetd.conf > /etc/inetd.conf+
        mv /etc/inetd.conf+ /etc/inetd.conf
else
  cat >> /etc/inetd.conf <<ADD_THIS
#
# newcm_d is a replacement daemon for rpc.cmsd which allows you to
# have centralized calendar manager servers.
100068/3      dgram  rpc/udp wait root $TGTDIR/newcm_d    newcm_d
ADD_THIS
fi

PID=`ps ax | grep 'newcm_d' | grep -v grep`

if [ "$PID" != "" ]
then
  echo "Bringing down newcm_d process..."
  echo ""
  set $PID
  kill $1
fi

PID=`ps ax | grep 'rpc.cmsd' | grep -v grep`

if [ "$PID" != "" ]
then
  echo "Bringing down rpc.cmsd process..."
  echo ""
  set $PID
  kill $1
fi

PID=`ps ax | grep 'inetd$' | grep -v grep`

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 partially completed."
else
   set $PID
   kill -HUP $1
   echo "Installation is completed and inetd is set up for the new daemon."
   echo "Please kill and restart any cm processes on this machine."
fi

