#! /bin/sh
#
# @(#)setlpsstartup	1.24	LPS_UNX_COM	3/16/95
#
# Copyright 1995   Digital Equipment Corporation, Maynard, MA
#
# setlpsstartup
#
# Standalone script to check for and optionally install the Bourne shell
# commands needed to startup all required LPS components at system boot
# time in a platform-specific manner.
#
#    usage:  setlpsstartup [-q]
#
#    where:  -q  Optional "query" flag that allows the user to decline
#                the installation of the startup commands.  If this flag
#                is not specified, then installation will automatically
#                be performed.
#
# This script is structured into the following "phases":
#
#    Phase 1 - INITIALIZE   Initialize the environment, parse cmdline.
#    Phase 2 - CHECK        Check to see if installation already done.
#    Phase 3 - QUERY        Ask the user if installation should be done. 
#    Phase 4 - BUILD        Construct new startup file in working file.
#    Phase 5 - INSTALL      Install required LPS startup commands.
#    Phase 6 - CLEANUP      Clean up and get out.
#
# The startup commands are installed in the proper system file or
# directory, based on the operating system type.  The platform type is
# automatically derived by this script from the LPS Object Database.
#
# Prior to installation, the original system file (if applicable) is
# preserved (usually renamed) and the user is informed of the path of
# the preserved file.
#
# If set for query, then if the user declines the installation, a mail
# message is sent to the "root" account describing the commands that must
# be placed in the given system file/directory to effect proper host-level
# startup of LPS components (most notably "lpsad", the Management Client
# daemon).
#
# Exit values:
#    0 - Returned if:
#           - The startup commands are already installed, or
#           - The user did not possess sufficient privileges, or
#           - The user declined the installation.
#    1 - Returned if:
#           - A required system utility could not be found, or
#           - A required system utility returned an error, or
#           - The os name could not be resolved, or
#           - File access error of any kind was encountered.
#
# That is, an error value is returned if the installation should have
# been performed, but for some reason failed.  A success value does
# *not* imply the installation was successfully performed, only that
# all instructions were carried out (including the user indicating
# that the installation should not be performed).
###

#----------------------------------------------------------------------

# Phase 1 - INITIALIZE
#
# Set key environment variables.  Most can be set externally by
# the knowledgeable user.

set -a	# Automatically export all variables we create and/or modify

PATH=$PATH:/usr/ucb	# Needed for Solaris

SCRIPTNAME=`basename $0`

: ${CAT:=/bin/cat}
: ${CP:="/bin/cp"}
: ${ECHO:="echo"}
: ${ECHON:="echo -n"}
: ${GREP:=/bin/grep}
: ${HELP:=true}
: ${LOCALHOST:=`hostname`}
: ${LPSAD:=lpsad}
: ${LPSODB:=/etc/lpsodb}
: ${LPSODBLIST:=/etc/lpsodblist}
: ${MAILACCT:=root}
: ${PAGER:=more}
: ${RM:=/bin/rm}
: ${SED:=/bin/sed}
: ${TMPDIR:=/tmp}
: ${UNAME:=uname}

# Temporary files used here

HELPFILE=$TMPDIR/lpshelp.$$		# General help info for LPS startup
LPSCMDSFILE=$TMPDIR/lpscmds.$$		# Complete set of LPS startup cmds
NEWSTARTUPFILE=$TMPDIR/newstart.$$	# Working copy of new startup file
TROUBLE=$TMPDIR/trouble.$$		# General use error log file

TMPFILES="$HELPFILE $LPSCMDSFILE $NEWSTARTUPFILE $TROUBLE"

#----------------------------------------------------------------------

# Define some common functions

Error ()
{
    if [ "$*" ]
    then
	$ECHO ''            1>&2
	$ECHO "${SCRIPTNAME}: $*" 1>&2
    else
	$ECHO 1>&2
    fi

    return 1   # Ensures non-success value in case of simple "exit"
}

cleanup ()
{
    $RM -f $TMPFILES
}

# Setup activities to be executed upon encountering certain signals

trap 'echo ; \
      echo $SCRIPTNAME script terminating... ; \
      echo ; \
      echo LPS startup commands may not be completely installed. ; \
      echo ; \
      cleanup ; \
      exit 1' \
      1 2 3 15

#----------------------------------------------------------------------

# Parse and validate the command line, and ensure the user is 'root'.

error=false
cnt=$#

case $cnt in
    0 ) QUERY=false ;;
    1 ) if [ "$1" = "-q" ] ; then QUERY=true ; else error=true ; fi ;;
    * ) error=true ;;
esac

if $error
then
    Error "usage: $SCRIPTNAME [-q]"
fi

# Ensure the user is running as 'root'

if /usr/bin/id | $GREP 'uid=0(' > /dev/null 2>&1
then
    :
else
    Error "You must be running as 'root' to execute this script."
    error=true
fi

if $error
then
    Error
    exit 1
fi

#----------------------------------------------------------------------

# Determine if all required files are intact, checking as many as
# possible before we punt on an error.

ODB="LPS Object Database"

if [ ! -f $LPSODB ]
then
    Error "The $ODB file '$LPSODB' does not exist!"
    error=true
fi

if [ -f $LPSODBLIST ]
then
    if [ -x $LPSODBLIST ]
    then
	DESC="LPS Management Client daemon"

	if LPSBIN=`$LPSODBLIST -f $LPSODB -e -v lpsbin`
	then
	    LPSADPATH=$LPSBIN/$LPSAD

	    if [ -f $LPSADPATH ]
	    then
		if [ ! -x $LPSADPATH ]
		then
		    Error "The $DESC '$LPSADPATH' is not set as executable!"
		    error=true
		fi
	    else
		Error "The $DESC '$LPSADPATH' does not exist!"
		error=true
	    fi
	else
	    Error "Problem encountered with the $ODB file '$LPSODB'"
	    error=true
	fi
    else
	Error "The $ODB list utility '$LPSODBLIST' is not set as executable!"
	error=true
    fi
else
    Error "The $ODB list utility '$LPSODBLIST' does not exist!"

    cat 1>&2 << EOF
    The "lpsodblist" utility should at least exist with all other
    PrintServer software binaries in the directory as installed
    on this system.  You might want to search around on your system
    to locate where you installed the PrintServer software, then copy
    the "lpsodblist" utility to $LPSODBLIST and re-run this script.
EOF

    error=true
fi

if $error
then
    Error
    exit 1
fi

#----------------------------------------------------------------------

# Initialize common and platform-specific environment variables, etc.

LPSROOT=`$LPSODBLIST -f $LPSODB -e -v lpsroot`  # Path of LPS root directory
OSNAME=`$LPSODBLIST  -f $LPSODB -e -v osname` 	# Operating system name

PATH="$LPSROOT/scripts:$LPSBIN:$PATH"	# For LPS scripts & executables

CMDSEXIST=false     # Set true if LPS startup commands are found to exist
REASON="(unknown)"  # Text of reason why installation was not performed
PRESERVE=true	    # Controls perservation of modified system file(s)
LINKFILE=""	    # Symbolic link to real startup file
GID=system	    # Default group id for file ownership

case $OSNAME in
      "AIX" ) : ${STARTUPFILE:=/etc/rc.tcpip}
	      FILEMODE=750
	      CMDPREFIX=""
	      INSTALLINFO="appending the commands to the end of the file."
	      ;;

     "DYNIX" ) : ${STARTUPFILE:=/etc/init.d/LPSstartup}
              FILEMODE=755
              CMDPREFIX=""
              INSTALLINFO="copying the commands into that file."
              #
              # For Sequent DYNIX/ptx we need to create a symbolic
              # link to the actual startup file.
              #
              LINKFILE=/etc/rc2.d/S65LPSstartup
              PRESERVE=false
              GID=sys
              ;;
 
    "HP-UX" ) : ${STARTUPFILE:=/etc/rc}
	      FILEMODE=544
	      : ${MAGICLINE:=": # do nothing instruction"}
	      CMDPREFIX="	"  # Contains a single TAB character!
	      INSTALLINFO="inserting the commands after the 'magic cookie'
character sequence \"$MAGICLINE\" found in the system startup file."
	      ECHON=echon
	      ;;

     "IRIX" ) : ${STARTUPFILE:=/etc/init.d/LPSstartup}
	      FILEMODE=755
	      CMDPREFIX=""
	      INSTALLINFO="copying the commands into that file."
	      #
	      # For Silicon Graphics' IRIX we need to create a symbolic
	      # link to the actual startup file.
	      #
	      LINKFILE=/etc/rc2.d/S65LPSstartup
	      PRESERVE=false
	      GID=sys
	      ;;

     "OSF1" ) : ${STARTUPFILE:=/sbin/init.d/LPSstartup}
	      FILEMODE=755
	      CMDPREFIX=""
	      INSTALLINFO="copying the commands into that file."
	      #
	      # For OSF/1 we need to create a symbolic link to the
	      # actual startup file.
	      #
	      LINKFILE=/sbin/rc3.d/S99LPSstartup
	      PRESERVE=false
	      ;;

      "OSx" ) : ${STARTUPFILE:=/etc/init.d/LPSstartup}
              FILEMODE=755
              CMDPREFIX=""
              INSTALLINFO="copying the commands into that file."
              #
              # For Pyramid OSx we need to create a symbolic
              # link to the actual startup file.
              #
              LINKFILE=/etc/rc2.d/S65LPSstartup
              PRESERVE=false
              GID=sys
              ;;
      "SCO" ) : ${STARTUPFILE:=/etc/rc2.d/S97LPSstartup}
	      FILEMODE=754
	      CMDPREFIX=""
	      INSTALLINFO="copying the commands into that file."
	      ;;

  "Solaris" ) : ${STARTUPFILE:=/etc/rc2.d/S82LPSstartup}
	      FILEMODE=744
	      CMDPREFIX=""
	      INSTALLINFO="copying the commands into that file."
	      ECHON=echon
	      ;;

    "SunOS" ) : ${STARTUPFILE:=/etc/rc.local}
	      FILEMODE=650
	      CMDPREFIX=""
	      INSTALLINFO="appending the commands to the end of the file."
	      ;;
         * )  Error "This system does not appear to be supported by this script."
	      Error
	      exit 1
	      ;;
esac

#----------------------------------------------------------------------

# Create the temporary file containing the LPS startup commands.
#
# Creating this file at this point may seem like a waste, but it turns out
# that some activities require these commands (in this form) even if the
# installation is not performed.
#
# Note: the ${CMDPREFIX} stuff is a hack so as to allow for special
#       indentation when required to be a good platform "citizen".

$CAT << ENDOFINPUT > $LPSCMDSFILE

${CMDPREFIX}# Startup all LPS Management Client daemons
${CMDPREFIX}#
${CMDPREFIX}# These commands were created by $SCRIPTNAME
${CMDPREFIX}# on `date`
${CMDPREFIX}#
${CMDPREFIX}if [ -f $LPSODB -a -x $LPSODBLIST ]
${CMDPREFIX}then
${CMDPREFIX}    \`$LPSODBLIST -f $LPSODB -e -v lpsbin\`/$LPSAD -s
${CMDPREFIX}fi
ENDOFINPUT

if [ $? -ne 0 ]
then
    Error "Unable to create the temporary file for the startup commands."
    Error
    exit 1
fi

#----------------------------------------------------------------------

# Create the temporary file containing helpful text describing the
# need for the LPS startup commands, etc.

$CAT << ENDOFINPUT > $HELPFILE
If you wish to have all Management Client daemons on $LOCALHOST
automatically started whenever $LOCALHOST starts, then some lines
must be added to the system startup procedure.

If you elect not to have this done, and you configure a Management 
Client to boot a PrintServer printer, then the daemon will not be 
automatically started when you reboot your system.  As a result, if 
the printer ever needs to be rebooted, this daemon will have to be 
manually started in order to perform the boot procedure with the printer.

Similarly, if you define one or more Management Clients to
perform accounting and event logging, these daemons will not be
present when your system is rebooted.

If you later decide that you would like to have all Management
Clients on $LOCALHOST automatically restarted at boot time,
you can issue the following command while running under the
'root' account:

    # $LPSBIN/$SCRIPTNAME

If you prefer, you may manually install the following commands
to effect the automatic startup of required PrintServer programs:

`$CAT $LPSCMDSFILE 2>&1`

You should install the above LPS startup commands in the system file
'$STARTUPFILE' by $INSTALLINFO

ENDOFINPUT

if [ "$LINKFILE" ]	# Extra stuff needed for a symbolic link file
then
    $CAT << ENDOFINPUT >> $HELPFILE
After creating the '$STARTUPFILE' startup file, you must create a
symbolic link to that file in the `basename $LINKFILE` directory
using the following command:

    # ln -s $STARTUPFILE  $LINKFILE

ENDOFINPUT
fi

$CAT << ENDOFINPUT >> $HELPFILE
Note that the PrintServer Software boot-time startup commands
do not in any way effect the operation of any Print Clients you
might define on your system.  Only Management Clients are
affected by the boot-time startup commands.

For further information, refer to the PrintServer Software
Management Guide.
ENDOFINPUT

if [ $? -ne 0 ]
then
    Error "Unable to create the temporary file for the help text."
    Error
    exit 1
fi

#----------------------------------------------------------------------

# mailhelp() - A common function for mailing "help" information
#
# The REASON variable should already be set appropriately.

mailhelp ()
{
    mail $MAILACCT << ENDOFINPUT
On `date` the script '$SCRIPTNAME' was
executed in an attempt to install the shell commands required
to automatically start up all defined PrintServer Software
Management Client daemons every time '$LOCALHOST' is started.

The installation of these critical commands was NOT performed.

Reason installation was not performed:  $REASON

As a result, all PrintServer Software Management Client
daemons will not be automatically started whenever
'$LOCALHOST' is started.

`$CAT $HELPFILE`
			[end of message]
ENDOFINPUT

    $CAT << ENDOFINPUT 1>&2
Instructions for manually installing the startup
commands have been mailed to the '$MAILACCT' account.
ENDOFINPUT

    return 0
}

#----------------------------------------------------------------------

# Phase 2 - CHECK
#
# Check to see if the startup commands already exist; if so, then quit.
#
# All platforms have the same requirement:  to search for a specific,
# common string containing key LPS path components.  If the search
# fails, then immediately processing is done on a platform-specific basis.
#
# If the search succeeds, then we're done and can go home...successfully.
# Yeah, we should probably fall thru to the final CLEANUP phase, but
# that's a bit ridiculous in this situation.  Just zap our temporary files
# and exit.
#
# Note the special handling required when a symbolic link is necessary.

$ECHO
$ECHO "Checking for automatic startup of Management Clients at boot time..." 
$ECHO

found=false

SEARCHSTR="${LPSODB}.*${LPSODBLIST}"	# Common LPS search string

if $GREP "$SEARCHSTR" $STARTUPFILE > /dev/null 2>&1
then
    if [ "$LINKFILE" ]				    # Symbolic link required?
    then
	if ls $LINKFILE > /dev/null 2>&1	    # Link file exist?
	then
	    if ls -L $LINKFILE > /dev/null 2>&1	    # Linked to a real file?
	    then
		if diff $STARTUPFILE $LINKFILE 2>&1 # Link points to our file?
		then
		    found=true
		fi
	    fi
	fi
    else
	found=true
    fi
fi

if $found
then
    $ECHO
    $ECHO "All required LPS startup commands are already installed."
    $ECHO

    cleanup

    exit 0
fi

# If we get here, the search failed.  Some SVR3 & SVR4 implementations
# require further testing.

if [ $OSNAME = "SCO" -o $OSNAME = "Solaris" ]
then
    PRESERVE=false		# We should exclusively own the startup file

    if [ -f $STARTUPFILE ]	# A file already exists?!?!?
    then
	# The search string could not be found, any yet there is a file
	# with our name on it.  This should be EXTREMELY RARE!

	PRESERVE=true     # Important state setting for these system types
	QUERY=true        # Force query mode

	case $OSNAME in
	    "SCO" ) MORETEXT="
    If renaming the existing file is acceptable, then if the file is
    currently set so as to be executed upon system startup, you will be
    asked if the file should continue to be executed when your system is
    restarted, or if the file should be disabled (but preserved).

    If you do not want the existing file to be executed at system
    startup time, then answer 'n' to this question.  If the file is not
    currently set for execution at system startup, then you will not be
    asked this question."
		    ;;
	"Solaris" ) MORETEXT="" ;;
		* ) MORETEXT="" ;;
	esac

	$PAGER << END_OF_INPUT

    It appears you already have a startup file named "$STARTUPFILE"
    although its contents are unknown.  The installation of automatic
    startup of LPS Management Clients can be declined at this point,
    or you can have this script preserve (rename) the existing file
    and install the proper LPS automatic startup script.

    Before you are asked whether the LPS startup commands should be
    installed and the existing file renamed, you will first be given
    the opportunity to examine the existing file.
    $MORETEXT
END_OF_INPUT
	if yesno y "Do you want to examine the existing file"
	then
	    $PAGER $STARTUPFILE
	fi

	# If the existing file is set for execution at boot time,
	# then ask if it should remain enabled for execution.
	# This is done only for SCO (and similar) systems.

	if [ $OSNAME = "SCO" ]
	then
	    if [ -x $STARTUPFILE ]
	    then
		quest="Continue to execute this file at system startup"
		if yesno y "$quest"
		then
		    :
		else
		    chmod a-x $STARTUPFILE
		fi
	    else
		$ECHO "[This file is not executed at system startup]"
	    fi
	fi
    fi
fi

#----------------------------------------------------------------------

# Phase 3 - QUERY
#
# If $QUERY mode is set, ask the user if the installation should be
# performed.  If the user declines, mail a warning message and exit.

if $QUERY
then
    if $HELP
    then
	$PAGER $HELPFILE
    fi

    if yesno y "Install the required LPS startup commands"
    then
	:
    else
	REASON="User declined the installation."

	$ECHO
	$ECHO "The system startup file '$STARTUPFILE' will not be modified."
	$ECHO

	mailhelp

	cleanup

	exit 0
    fi
fi

#----------------------------------------------------------------------

# Phase 4 - BUILD
#
# Make a copy of the existing system startup file (if necessary), then
# insert the LPS startup commands at the proper location.
#
# All commands should redirect stderr to the $TROUBLE file to facilitate
# common error handling.

if $PRESERVE
then
    $ECHO "Preserving existing startup file '$STARTUPFILE'..."

    if savefile -V -p -s ".OLD" $STARTUPFILE 2> $TROUBLE
    then
	OLDSTARTUPFILE="${STARTUPFILE}.OLD.0" # Created by "savefile" utility
    else
	Error "Preserving the existing system startup file has failed:"
	$CAT $TROUBLE 1>&2

	if yesno x "Continue with the installation anyway"
	then
	    $ECHO "Continuing the installation..."
	else
	    REASON="While attempting to preserve
the existing system startup file '$STARTUPFILE'
the following errors were encountered:

    `$CAT $TROUBLE`
"
	    mailhelp
	    cleanup
	    exit 1
	fi
    fi
fi

rm -f $NEWSTARTUPFILE

$ECHO "Creating a working copy of the startup file in '$NEWSTARTUPFILE'..."

FAILURE=true	# Assume the worst up front

case $OSNAME in
    "AIX" ) # File building involves appending the LPS commands
	    # to the end of the system startup file.

	    if $CAT $STARTUPFILE $LPSCMDSFILE > $NEWSTARTUPFILE 2> $TROUBLE
	    then
		FAILURE=false
	    fi
	    ;;

  "HP-UX" ) # File building involves the inserting the LPS commands
	    # inside the system startup file at a very specific
	    # location based on the location a "magic cookie" line.
	    # The commands MUST follow this specially formatted line.

	    cmd="/$MAGICLINE/r $LPSCMDSFILE"

	    if $SED -e "$cmd" $STARTUPFILE > $NEWSTARTUPFILE 2> $TROUBLE
	    then
		FAILURE=false
	    fi
	    ;;

   "DYNIX" | "IRIX" | "OSF1" | "OSx" ) :
	    # File building involves the creation of an LPS-specific
	    # file in a known system startup directory.  The file
	    # simply contains all the LPS startup commands, plus a
	    # Bourne shell script header.

	    header="#!/bin/sh
"
	    if $ECHO "$header" > $NEWSTARTUPFILE 2> $TROUBLE
	    then
		if $CAT $LPSCMDSFILE >> $NEWSTARTUPFILE 2> $TROUBLE
		then
		    FAILURE=false
		fi
	    fi
	    ;;

    "SCO" ) # File building involves the creation of an LPS-specific
	    # file in a known system startup directory.  The file
	    # simply contains all the LPS startup commands, plus a
	    # Bourne shell script header.

	    header="
#! /bin/sh
"
	    if $ECHO "$header" > $NEWSTARTUPFILE 2> $TROUBLE
	    then
		if $CAT $LPSCMDSFILE >> $NEWSTARTUPFILE 2> $TROUBLE
		then
		    FAILURE=false
		fi
	    fi
	    ;;

"Solaris" ) # File building involves the creation of an LPS-specific
	    # file in a known system startup directory.  The file
	    # simply contains all the LPS startup commands, plus a
	    # Bourne shell script header.
	    #
	    # Note that this case is extremely similar to the group
	    # of SVR3/SVR4 platforms above, except that the header
	    # line calls out a slightly different path for the shell.

	    header="#!/sbin/sh
"
	    if $ECHO "$header" > $NEWSTARTUPFILE 2> $TROUBLE
	    then
		if $CAT $LPSCMDSFILE >> $NEWSTARTUPFILE 2> $TROUBLE
		then
		    FAILURE=false
		fi
	    fi
	    ;;

  "SunOS" ) # File building involves appending the LPS commands
	    # to the end of the system startup file.

	    if $CAT $STARTUPFILE $LPSCMDSFILE > $NEWSTARTUPFILE 2> $TROUBLE
	    then
		FAILURE=false
	    fi
	    ;;

        * ) $ECHO "Invalid operating system: \"$OSNAME\"" >> $TROUBLE
	    ;;
esac

if $FAILURE
then
    Error "The installation has failed due to the following errors:"
    $CAT $TROUBLE

    REASON="Failure to create the working copy of the
system startup file '$NEWSTARTUPFILE' due to:
    `$CAT $TROUBLE`
"
fi

#----------------------------------------------------------------------

# Phase 5 - INSTALL
#
# Perform the installation of the LPS automatic startup commands
# based on the operating system name.


if [ $OSNAME = "SCO" -o $OSNAME = "Solaris" ]
then
    hacking="Creating"
else
    hacking="Updating"
fi

$ECHO "$hacking system startup file '$STARTUPFILE'..."

FAILURE=true	# Failure flag, set false only when installation is successful
RESTORE=true	# Flag to restore the original startup file upon failure

# Copy the working file to the actual startup file, checking for errors
# along the way.
#
# Note the special handling for a required symbolic link.

if $CP $NEWSTARTUPFILE $STARTUPFILE 2> $TROUBLE
then
    if [ "$LINKFILE" ]
    then
	# We have yet to determine exactly how to handle the creation
	# of a required symbolic link in a generic fashion, since only
	# OSF/1 currently requires such a file.
	#
	# Hence, if we get here then automatically assume this is OSF/1,
	# and do some other OSF/1-specific things besides just the link.

	chown bin $STARTUPFILE
	chgrp bin $STARTUPFILE

	msg=""

	if ln -s $STARTUPFILE $LINKFILE 2>> $TROUBLE
	then
	    if chmod 755 $LINKFILE  &&  chgrp $GID $LINKFILE
	    then
		FAILURE=false
	    else
		msg="set protection/ownership of"
	    fi
	else
	    msg="create"
	fi

	if [ "$msg" ]
	then
	    msg="Failure to $msg symbolic link file \"$LINKFILE\""
	    $ECHO "$msg" >> $TROUBLE
	fi
    else
	FAILURE=false
    fi
else
    # Special check for certain SVR3/SVR4 systems:  if there was no
    # pre-existing file, then reset the restoration flag.  All others
    # will restore the file.

    if [ $OSNAME = "SCO" -o $OSNAME = "Solaris" ] && $PRESERVE
    then
	:
    else
	RESTORE=false
    fi
fi

# Here we check for a failure condition and possible restoration of the
# original file.  Whether the installation was successful or not, we still
# set the resulting startup file's mode to the proper value...no matter
# what.
#
# Since we're very near the end of the script, we do NOT exit upon
# failure; rather, we set the final exit value (and any other variables
# if we've failed), then fall thru to the final CLEANUP section.

if $FAILURE
then
    Error "The installation has failed due to the following errors:"
    $CAT $TROUBLE

    EXITVALUE=1
    SENDHELP=true
    REASON="Failure to copy the new version of the
system startup file '$NEWSTARTUPFILE' to '$STARTUPFILE'
due to:
    `$CAT $TROUBLE`
"
    # Restore the original startup file, if necessary

    if $RESTORE
    then
	$ECHO
	$ECHO "Restoring the original system startup file..."

	if $CP $OLDSTARTUPFILE $STARTUPFILE
	then
	    $ECHO "Original system startup file restored."
	    $ECHO
	else
	    $PAGER << ENDOFINPUT
    WARNING!  The original system startup file could not be restored.
              That file was previously saved as '$OLDSTARTUPFILE'.
ENDOFINPUT
	    pause
	    EXITVALUE=1
	fi
    fi
else
    $ECHO
    $ECHO "The installation of the LPS startup commands was successful."
    $ECHO
    SENDHELP=false
    EXITVALUE=0
fi

# Whatever the ultimate outcome (success or failure), ensure that the
# final version of the startup file is set to the proper mode.  On some
# systems (such as HP-UX), if the file is not set as executable, the
# system will NOT COME UP, at least in a useful multi-user mode.  Grrr...

chmod $FILEMODE $STARTUPFILE

#----------------------------------------------------------------------

# Phase 6 - CLEANUP
#
# Send an informative mail message if required

if $SENDHELP
then
    mailhelp
fi

# Zap all temporary files and exit with the resolved value

cleanup

exit $EXITVALUE

#----------------------------------------------------------------------

# Emacs editing parameters
# Local Variables:
# page-delimiter:"^#---"
# fill-column:75
# End:
