#! /bin/sh
#
#	Shell script for the installation of the PortMaster daemon
#	on the local Host.
#
#	@(#)pm_host_upgrade	1.2 6/15/90  Copyright 1990 Livingston Enterprises Inc
#
#
#
PATH=/bin:/usr/bin:/usr/ucb:$PATH
#
#	Set up global variables.
#
HOSTNAME=`hostname`
HOSTSFILE="/etc/hosts"
SERVICES="/etc/services"
INETD_CONF="/etc/inetd.conf"
PMD="in.pmd"
SYSBIN="/usr/etc"
ALT_SYSBIN="/etc"
DEFAULT_INTERNET="192.9.200.1"
UNAME=`whoami`
DIR=`expr \
  ${0-.}'/' : '\(/\)[^/]*/$' \
  \| ${0-.}'/' : '\(.*[^/]\)//*[^/][^/]*//*$' \
  \| .`
#
#	Must be run as root
#
if [ "$UNAME" != "root" ]; then
	echo "Host upgrade must be run as root."
	echo "Upgrade Aborted."
	exit 0
fi
#
echo 'Performing Host Upgrade.'
#
#	Copy new in.pmd to executable directory
	echo "Upgrading in.pmd daemon"
#
#	Find out where the installation directory is
#
	if [ ! -f $SYSBIN/$PMD ]; then
		if [ -f $ALT_SYSBIN/$PMD ]; then
			$SYSBIN=$ALT_SYSBIN
		fi
	fi
		
#	Check to see if in.pmd has already been upgraded.
	

	if [ -f $SYSBIN/$PMD ]; then
		NEW_VERSION=`what $DIR/$PMD | grep Livingston`
		CURRENT_VERSION=`what $SYSBIN/$PMD | grep Livingston`
		if [ "$NEW_VERSION" = "$CURRENT_VERSION" ]; then
			echo -n "This host appears to already be upgraded. Continue anyway? (y/n) "
			read ANSWER
			if [ "$ANSWER" != "y" ]; then
				echo "Upgrade Aborted."
				exit 0
			fi
		fi

#		Move the old file to a backup location

		mv -f $SYSBIN/$PMD $SYSBIN/$PMD-
	fi

#	Copy in the new version

	cp $DIR/$PMD $SYSBIN/$PMD >/dev/null

	if [ ! -f $SYSBIN/$PMD ]; then
		echo "Could not copy $PMD to either $SYSBIN"
		echo "Upgrade Aborted."
		exit 1
	fi
#
	echo "Host Upgrade completed."
#
