#!/sbin/sh 
#
# *****************************************************************
# *                                                               *
# *    Copyright (c) Digital Equipment Corporation, 1991, 1997    *
# *                                                               *
# *   All Rights Reserved.  Unpublished rights  reserved  under   *
# *   the copyright laws of the United States.                    *
# *                                                               *
# *   The software contained on this media  is  proprietary  to   *
# *   and  embodies  the  confidential  technology  of  Digital   *
# *   Equipment Corporation.  Possession, use,  duplication  or   *
# *   dissemination of the software and media is authorized only  *
# *   pursuant to a valid written license from Digital Equipment  *
# *   Corporation.                                                *
# *                                                               *
# *   RESTRICTED RIGHTS LEGEND   Use, duplication, or disclosure  *
# *   by the U.S. Government is subject to restrictions  as  set  *
# *   forth in Subparagraph (c)(1)(ii)  of  DFARS  252.227-7013,  *
# *   or  in  FAR 52.227-19, as applicable.                       *
# *                                                               *
# *****************************************************************
#
# @(#)$RCSfile$ $Revision$ (DEC) $Date$
# 
#   This software is furnished under a license and may be used and
#   copied  only  in accordance with the terms of such license and
#   with the  inclusion  of  the  above  copyright  notice.   This
#   software  or  any  other copies thereof may not be provided or
#   otherwise made available to any other person.  No title to and
#   ownership of the software is hereby transferred.
#
#   The information in this software is subject to change  without
#   notice  and should not be construed as a commitment by Digital
#   Equipment Corporation.
#
#   Digital assumes no responsibility for the use  or  reliability
#   of its software on equipment which is not supplied by Digital.
#

:	-DepCheck
#		Check the dependency and fails the SCP if the dependency
#		has not been met.
#	Given :	none
#	Global:	list of dependent subsets (DEPSETS)

DepCheck()
{
    SHELL_LIB=${SHELL_LIB:-/usr/share/lib/shell}
    . $SHELL_LIB/libscp
    STL_DepInit
    STL_DepEval $DEPSETS || {
		echo "
    Subset $SUBSET depends on the following subset(s).

	$DEPEXP

    Please install these subset(s) before installing $SUBSET.
" >&2
	exit 1
    }
}

:	-ModifyWhatis
#		Modify the whatis database
#	Given :	$1 - operation flag
#		     add : Add to whatis database
#		     del : Delete from whatis database
#		$2 - manpage path
#		$3 - prefix of source whatis database
#	Return:	none
#	Effect: The $2/whatis database is updated.
 	
ModifyWhatis()
{
    _FLAG=$1
    _WHATISDIR=$2
    _WHATISEXT=$3
    _WHATIS=./$_WHATISDIR/whatis
    _SRCWHATIS=./$_WHATISDIR/.${_WHATISEXT}.whatis
    _NOWHATISMSG="
    Cannot update the whatis database automatically.
    Run \"catman -M $_WHATISDIR -w\" to refresh the whatis database.
    "

    if [ ! -s $_SRCWHATIS ]; then
	return
    fi
    case "$_FLAG" in
	add)
	    #
	    # If $_WHATIS exists, concatenate it with this subset's 
	    # $_SRCWHATIS file, and sort unique the result.  If
	    # $_WHATIS does not exist, copy only this
	    # subset's $_SRCWHATIS file onto $_WHATIS.
	    #
	    if [ -s $_WHATIS ]; then
		sort -u $_WHATIS $_SRCWHATIS > $_WHATIS.tmp
		mv $_WHATIS.tmp $_WHATIS
	    else
		cp $_SRCWHATIS $_WHATIS
	    fi
	    ;;
	del)
	    #
	    # If this subset's $_SRCWHATIS file exists, concatenate it with
	    # $_WHATIS, then sort | unique to retain only the unique entries.
	    # If the $_SRCWHATIS file does not exist, just display an error
	    # message.
	    #
	    if [ -f $_SRCWHATIS ]; then
		sort $_SRCWHATIS $_WHATIS > $_WHATIS.tmp
		uniq -u $_WHATIS.tmp > $_WHATIS
		rm -f $_WHATIS.tmp
	    else
		echo "$_NOWHATISMSG"
	    fi
	    ;;
    esac
}

:	-InitVariables
#		Initialize constants and global variables
#	Given :	The input arguments of this SCP
#	Return:	None
#	Effect:	The constants and global variables are set

InitVariables()
{
    ARG1=$1
    SUBSET=`basename $0`
    SUBSET=`expr "$SUBSET" : '^\(.*\)\.scp'`
    NUL=/dev/null
    SHELL_LIB=${SHELL_LIB:-/usr/share/lib/shell}
    #
    # To be changed in every SCP file
    #
    DEPSETS="OSFDCMT4?? IOSJPBASE4?? and"
    DEPEXP="OSFDCMT4?? and IOSJPBASE4??"
    WWVARS="WWINSTALL_JP"
}

Main()
{
    #
    # Initialize variables
    #
    umask 022
    InitVariables $*

    case $ACT in 

    #
    # ACT = PRE_A | PRE_L
    #
    PRE_[AL])
	DepCheck
	;;
    #
    # ACT = POST_A | POST_L
    #
    POST_[AL])
	. $SHELL_LIB/libscp
	STL_LockInit
	STL_DepLock $SUBSET $DEPSETS
	ModifyWhatis add /usr/i18n/share/ja_JP.deckanji/man advfs
	;;
    #
    # ACT = PRE_D
    #
    PRE_D)
	ModifyWhatis del /usr/i18n/share/ja_JP.deckanji/man advfs
	;;
    #
    # ACT = POST_D
    #
    POST_D)
	. $SHELL_LIB/libscp
	STL_LockInit
	STL_DepUnLock $SUBSET $DEPSETS
	;;
    #
    # ACT = M
    #
    M)
	#
	# Don't list when this subset is not meant to be shown to the user
	#
	[ "$ARG1" = "-l" ] && {
	    [ -f /usr/.smdb./IOSJPBASE4??.lk ] && exit 0
	    exit 1
	}
	;;
    esac
    return 0
}

[ "$CHECK_SYNTAX" ] || Main $*
