##
## Installation in Progress message
##
echo  -e "Beginning LP Plus installation. Please wait.\c"

##
##  Set off umask
##
umask 000;export umask

##
## Set up environment variables for default home directory
##
if [ x${RPM_INSTALL_PREFIX} = x ]
then
   if [ x${LPHOME} = x ]
   then
      LPHOME=/usr/lpplus
   fi
else
   LPHOME=$RPM_INSTALL_PREFIX
   export LPHOME
fi


##
## Modify default LPHOME directory in S80lp+ and K20lp+
##
sed s./usr/lpplus.${LPHOME}. ${LPHOME}/shells/S80lp+ >${LPHOME}/shells/tmp
mv ${LPHOME}/shells/tmp ${LPHOME}/shells/S80lp+
chmod 777 ${LPHOME}/shells/S80lp+
sed s./usr/lpplus.${LPHOME}. ${LPHOME}/shells/K20lp+ >${LPHOME}/shells/tmp
mv ${LPHOME}/shells/tmp ${LPHOME}/shells/K20lp+
chmod 777 ${LPHOME}/shells/K20lp+

##
## Modify default LPHOME directory in S80lpd+ and K20lpd+
##
sed s./usr/lpplus.${LPHOME}. ${LPHOME}/shells/S80lpd+ >${LPHOME}/shells/tmp
mv ${LPHOME}/shells/tmp ${LPHOME}/shells/S80lpd+
chmod 777 ${LPHOME}/shells/S80lpd+
sed s./usr/lpplus.${LPHOME}. ${LPHOME}/shells/K20lpd+ >${LPHOME}/shells/tmp
mv ${LPHOME}/shells/tmp ${LPHOME}/shells/K20lpd+
chmod 777 ${LPHOME}/shells/K20lpd+

## 
## Place LP Plus startup/shutdown scripts in rc directories
##

##
## Add new  /etc/profile.d/lpplus.sh for default home directory
##
echo "LPHOME=${LPHOME};export LPHOME" >/etc/profile.d/lpplus.sh
echo PATH='"$PATH:${LPHOME}/bin";export PATH' >>/etc/profile.d/lpplus.sh
chmod 755 /etc/profile.d/lpplus.sh

##
## Add dccbkst and dccwinnotify entries in /etc/services
##
grep "dccbkst" /etc/services >/tmp/LPDTMP
if [ ! -s /tmp/LPDTMP ]
then
   rm /tmp/LPDTMP
   grep "53971" /etc/services >/tmp/LPDTMP
   if [ ! -s /tmp/LPDTMP ]
   then
      echo "dccbkst         53971/tcp" >>/etc/services
   fi
fi
rm /tmp/LPDTMP
grep "dccwinnotify" /etc/services >/tmp/LPDTMP
if [ ! -s /tmp/LPDTMP ]
then
   rm /tmp/LPDTMP
   grep "53972" /etc/services >/tmp/LPDTMP
   if [ ! -s /tmp/LPDTMP ]
   then
      echo "dccwinnotify    53972/tcp">>/etc/services
   fi
fi
rm /tmp/LPDTMP

##
##  Create LP Plus message files
##
${LPHOME}/bin/makemsgs

##
##  If lp not installed, set up all links to LP Plus, else let
##    them know they will have to do it manually
##
if [ ! -f /usr/bin/lp ]
then
   ${LPHOME}/bin/dcclplink 
fi

ls ${LPHOME}/printers >/tmp/LPTMP 2>/dev/null
if [ ! -s /tmp/LPTMP ]
then
   clear
   echo -e "  If you are installing LP Plus for the first time and want to "
   echo -e "  quickly see the program, you can run a provided demo script. "
   echo -e "  This demo will add a demo (directory) printer called \"lppdemo\", "
   echo -e "  start the LP Plus scheduler, enable the lppdemo printer, submit "
   echo -e "  three print requests, and run the main status program. This demo "
   echo -e "  program will not affect your existing lp system. To run the demo "
   echo -e "  after package installation has finished:"
   echo -e ""
   echo -e "     1. Log out."
   echo -e "     2. Login."
   echo -e "     3. Run the demo script with the command \"lpplusdemo\""
   echo -e ""
fi
rm /tmp/LPTMP

##
##  If korn shell not in /usr/bin, create link to /bin
##
if [ ! -f /usr/bin/ksh ]
then
   if [ -f /bin/ksh ]
   then
      ln -s /bin/ksh /usr/bin/ksh
   fi
fi

##
##  If born shell not in /usr/bin, create link to /bin
##
if [ ! -f /usr/bin/sh ]
then
   if [ -f /bin/sh ]
   then
      ln -s /bin/sh /usr/bin/sh
   fi
fi

##
## Check file permissions
##
echo -e "\nConfirming successful LP Plus installation. Please wait.\c"
${LPHOME}/bin/dcchealth -f >/dev/null 2>&1
echo -e "\nLP Plus installation complete."

exit 0
