#!/bin/ksh
##########################################################################
# COPYRIGHT:
#    5765-273 (C) COPYRIGHT IBM CORPORATION 1995.
#    All Rights Reserved.
#    Licenced Materials - Property of IBM
#
#    US Government Users Restricted Rights - Use, duplication, or
#    disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
#
##########################################################################
#######################################################################
#
#  Migrate an AIX print queue to a Palladium physical printer
#
#######################################################################
if [ $# -ne 4 ]
then
   pddmsg 597 "pdmigpp"
   exit 1
fi

#set -x
#----------------------------------------------------------------------
# Parse out the command line options
#----------------------------------------------------------------------
AIX_Q_NAME=$1
SUV_NAME=$2
PP_NAME=$3
ASSOC_Q_NAME=$4

PP_ATTR_FILE=/tmp/$PP_NAME

#----------------------------------------------------------------------
# See if user is logged into DCE.  klist returns 0 if logged on.
#----------------------------------------------------------------------
klist >/dev/null 2>&1
KL_RC=$?

if [ $KL_RC -ne 0 ]
then
   pddmsg 290
   exit 1
fi

#----------------------------------------------------------------------
# Run pdgenatt to map the AIX queue characteristics into Pd attributes
#----------------------------------------------------------------------
pdgenatt $AIX_Q_NAME $ASSOC_Q_NAME >$PP_ATTR_FILE
if [[ $? -ne 0 ]] ; then
   exit 1
fi

#----------------------------------------------------------------------
# Create prerequisite aux sheet objects, if any needed
#----------------------------------------------------------------------
ACC_FILE=/tmp/${AIX_Q_NAME}_accounting
if test -f $ACC_FILE
then
   ACC_OBJ=${SUV_NAME}:${AIX_Q_NAME}_accounting
   pdcreate -c aux-sheet -X $ACC_FILE $ACC_OBJ
fi

AUD_FILE=/tmp/${AIX_Q_NAME}_audit
if test -f $AUD_FILE
then
   AUD_OBJ=${SUV_NAME}:${AIX_Q_NAME}_audit
   pdcreate -c aux-sheet -X $AUD_FILE $AUD_OBJ
fi

STA_FILE=/tmp/${AIX_Q_NAME}_start
if test -f $STA_FILE
then
   STA_OBJ=${SUV_NAME}:${AIX_Q_NAME}_start
   pdcreate -c aux-sheet -X $STA_FILE $STA_OBJ
fi

SEP_FILE=/tmp/${AIX_Q_NAME}_separator
if test -f $SEP_FILE
then
   SEP_OBJ=${SUV_NAME}:${AIX_Q_NAME}_separator
   pdcreate -c aux-sheet -X $SEP_FILE $SEP_OBJ
fi

END_FILE=/tmp/${AIX_Q_NAME}_end
if test -f $END_FILE
then
   END_OBJ=${SUV_NAME}:${AIX_Q_NAME}_end
   pdcreate -c aux-sheet -X $END_FILE $END_OBJ
fi

#----------------------------------------------------------------------
# Create the physical printer
#----------------------------------------------------------------------
pdcreate -c printer -X $PP_ATTR_FILE ${SUV_NAME}:${PP_NAME}
exit $?
