:
#
#	@(#) 21.1 89/09/26  password
#
#	Copyright (C) The Santa Cruz Operation, 1988, 1989.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation, and should be treated as Confidential.
#
#	/inst6/password -  set the root passwd
#
PATH=/bin:/usr/bin:/etc

tmp=/tmp/$$

# Return code definitions
: ${OK=0} ${FAIL=1} ${STOP=10}

#
# intlecho()
# usage : intlecho key message_file
# Note  :  
#	  Absolute or relative pathname of the message file.
#         All the lines with the key will be displayed.

intlecho() {

echo "s!^$1\(.*\)\$!\1!p" > ${tmp}echo
sed -n -f ${tmp}echo $2
rm -f ${tmp}echo

}

# local_menu()
# Usage : local_menu key directory filename
# Dependencies : intlecho()
# Note :
#	The directory is the relative or absolute
#	pathname where the localised 
#	directories are kept.
#	The filename is the name of the message file
#	under the localised directories.
#	It will set up the global TRANSFILE on return
#	with the user chosen message file.

local_menu() {

	TRANSDIR=$2

	# if LANG variable defined use it.
	# LANG can be of "per language" as in LANG=english
	# The other fields will be taken from the defaults in
	# /etc/default/lang.
	# see - Intl OS System Guide, Administering International
	# Environment.

	[ "$LANG" ] && {
		# has LANG got a underscore
		echo $LANG | grep _ >/dev/null 2>&1 && {
			# yes
			lang=`echo $LANG | sed -n "s/^\(.*\)\..*$/\1/p"`
		} || {
			# no, fill in the field from /etc/default/lang
			lang=`sed -n "s/^LANG=\(${LANG}.*\)\..*$/\1/p" /etc/default/lang`
		}
		
		[ -f $TRANSDIR/$lang/$3 ] && {
			TRANSFILE=$TRANSDIR/$lang/$3
			return 0
		}
	}
	
	[ -f /etc/default/lang ] && {
		lang=`sed -n "s/^LANG=\(.*\)\..*$/\1/p" /etc/default/lang`
		for i in $lang
		do
			[ -f $TRANSDIR/$i/$3 ] && {
				TRANSFILE=$TRANSDIR/$i/$3
				return 0
			}
		done
	}

	count=0

	_curdir=`pwd`
	cd $TRANSDIR
	for i in *
	do
		[ -f $i/$3 ] || continue
		heading=`intlecho "$1" "$i/$3"`
		[ "$heading" ] || continue
		count=`expr $count + 1`
		eval language$count=\$heading
		eval option$count=$i
	done
	cd $_curdir

	# if count is equal to 0, then the message
	# files do not contain the key
	# or message file is missing
	[ $count -eq 0 ] && {
		# this message needs to be hard-coded because
		# message file is not there
		echo "\nError: Cannot find the right message files\n"
		return 1
	}

	num_lang=$count

	[ "$num_lang" -eq "1" ] && {
		TRANSFILE=$TRANSDIR/$option1/$3
		return 0
	}

	count=0

	while [ "$count" -lt "$num_lang" ]
	do
		count=`expr $count + 1`
		eval echo "$count.  \$language$count" >> /tmp/$$
	done

	while true
	do
		cat /tmp/$$
		echo -n "? "
		read answer

		case $answer in
		[1-9]|[1-9][0-9])
				  [ "$answer" -le "$num_lang" ] && {
					eval TRANSFILE=\$TRANSDIR/\$option$answer/\$3
					return 0 
				  }
					;;
		esac

	done

}

#

# don't allow del'ing out until password is set
  trap '' 1 2 3 15

local_menu "MENU=" "/inst6" "passwrd.msg"
. $TRANSFILE

#Create the super-user password
echo "$PASSW1"
su root -c "/bin/passwd root" && {
	echo "$PASSW2"
	exit $OK
}
