#!/sbin/sh
#------------------------------------------------------------------#
#
# HPUX_ID: @(#) $Revision: 17.3 $ generated on Mon Mar  5 08:20:36 EST 2001
#
# (c)Copyright 1983-2001 Hewlett-Packard Co.,  All Rights Reserved.
#
#------------------------------------------------------------------#
# SD postinstall script template for 11.X patches.                 #
#------------------------------------------------------------------#
# This file is optional for all 11.X patches.  The purpose of this #
# script is to prepare for a kernel build when required by the     #
# install conditions.  The script can also drive events that must  #
# occur before a system reboot occurs.                             #
#------------------------------------------------------------------#

_PATCHID=PHNE_22159

UTILS="/usr/lbin/sw/control_utils"

if [ ! -f $UTILS ]; then
    echo "ERROR:   Cannot find $UTILS"
    exit 1
fi

. $UTILS
exitval=$SUCCESS

#####
##### Insert any code you may require at this point in the script.
##### Pay attention to the exitval variable and set appropriately
##### in your code.  If you are unsure as to what types of operations
##### are legal in this file and what types aren't, consult the 
##### "Guidelines for SD Control Scripts" document.
#####
##### START_CUSTOMIZATION_HERE

SAVE_DIR="${SW_ROOT_DIRECTORY}var/adm/sw/save_custom"
DEST_DIR="${SAVE_DIR}/$_PATCHID/backup"

if [ -f ${SW_ROOT_DIRECTORY}usr/share/man/cat1m.Z/telnetd.1m ]
then
  rm -f ${SW_ROOT_DIRECTORY}usr/share/man/cat1m.Z/telnetd.1m 1>/dev/null 2>&1
fi

 ls /dev/pts/t* 1>/dev/null 2>&1                # Get telnet tty files if any.

 if [  $? -eq 0  ]				# Telnet tty files available.
 then

   if [ ! -d ${DEST_DIR} ]			# No backup directory ?
   then

     echo "NOTE:    Creating a backup directory to save telnet ptys from /dev/pts"  

     mkdir -p	${DEST_DIR} 1>/dev/null 2>&1

     if [ $? -ne 0 ]				# mkdir failed ?
     then

       echo "WARNING: Directory couldn't be created for backing up files"
       exit $WARNING				# Get Out, Get Out.

     fi        					# end of $? error check. 

     chmod -R 500 ${SAVE_DIR} 1>/dev/null 2>&1  # Set proper permissions.

   fi						# end of DEST_DIR check


   for i in /dev/pts/t*				# For each tty file
     do

       if [ -c $i ]				# Telnet related tty files ?
       then
     
         mv $i $DEST_DIR 1>/dev/null 2>&1

         if [ $? -ne 0 ]			# Move fails ?
         then

           echo "WARNING: Failed to backup the telnet pty  : $i"
           exitval=$WARNING

         fi					# end of mv check

       fi 					# end of -c $i if condition. 

   done		        			# end of the for loop.

 fi						# end of outermost if check.

exit $exitval
