#! /bin/sh
#
# @(#)setPASSWORD	1.4	LPS_UNX_COM	02/19/95
#
# Copyright 1993   Digital Equipment Corporation, Maynard, MA
#
# setPASSWORD
#
# A script that produces a value for attribute PASSWORD.
#
# Parameters:
#    $1 - LPS class identifier, one of {PC, MC, PS, ENV}
#    $2 - Operating system type identifier (eg: SV2, BSD, etc)
#    $3 - Print client type identifier (eg: AIX, BSD, SV3, etc)
#    $4 - PrintServer printer model (eg: LPS17, LPS20)
#    $5 - Default value for the attribute
#    $6 - Path of the output file to receive the final attribute value
#
# Global variables:
#    ECHON
#    FUNCS
#    PAGER
#    TMPDIR
#    TR    (for the checknumrange() function)
#
# Exit values:
#    0 - Success, output file contains newly set attribute value.
#    1 - Error or interruption occurred, error messages go to stderr,
#	 contents of the output file are undefined.
###

CLASS=$1
OSTYPE=$2
PCTYPE=$3
PSMODEL=$4
DEFVAL=$5
OUTFILE=$6

MAXPWLEN=23		# Maximum PrintServer printer password length

showhelp true "
What password do you want to give the printer?

The printer password is used as the PostScript 
privileged password, as well as the password
for the PrintServer's remote console.  If
you think you have PostScript files that 
have the password embedded in them, you may want to 
choose a password that is compatible with those files. 

The password must be a string not longer than 23
characters.
"

while true
do
    echo
    $ECHON "Printer password [$DEFVAL]: "
    read RESPONSE
    if [ -z "$RESPONSE" ]
    then
	if [ -z "$DEFVAL" ]
	then
	    echo
	    echo "    Sorry, but no default password has been set."
	    continue
	else
	    RESPONSE="$DEFVAL"
	fi
    fi

    if [ `expr "$RESPONSE" : '.*'` -le $MAXPWLEN ]
    then
	break	# Success, break out of while() loop
    fi

    echo
    echo "    Sorry, a printer password may consist of no more"
    echo "    than $MAXPWLEN characters."
done

echo "$RESPONSE" > $OUTFILE

exit 0
