#!/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
    }
}

:	-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="IOSJPBASE4?? AFAADVGUI436 and"
    DEPEXP="IOSJPBASE4?? and AFAADVGUI436"
    WWVARS="WWINSTALL_JP"
}

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

    case $ACT in 

    #
    # ACT = C
    #
    C)
	#
	# Configure routine - mandatory if $DEPSETS installed.
	#
	case "$1" in
	GETFLAG)
	    # Check for RIS setup
	    #    $CMDSW is a 'x' when creating a ris server and the
	    #    subset should be set as optional
	    [ "$CMDSW" = "x" ] &&
	    {
	        echo "2"
	        exit 0
	    }
	    #
	    # If AFA* subsets in $DEPSETS are installed, make it mandatory
	    # 
	    for sub in $DEPSETS
	    do
		case "$sub" in
		    AFA*)
			[ ! -f ./usr/.smdb./${sub}.lk ] &&
			{
			    echo "2"
			    exit 0
			}
			;;
		esac
	    done
	    echo "0"
	    exit 0
	    ;;
	esac
	;;
    #
    # ACT = PRE_A | PRE_L
    #
    PRE_[AL])
	DepCheck
	#
	# Remove old directory
	#
	DIRS="/usr/dt/appconfig/help/ja_JP.SJIS		\
	      /usr/dt/appconfig/help/ja_JP.deckanji	\
	      /usr/opt/dtadvfs/help/ja_JP.deckanji"
	for dir in $DIRS
	do
	    [ -d $dir -a ! -L $dir ] && find $dir -depth -type d -exec rmdir {} \;
	done
	DIRS="/usr/i18n/dt/appconfig/help/ja_JP.eucJP/ja_JP.deckanji \
	      /usr/i18n/dt/appconfig/help/ja_JP.eucJP/ja_JP.sdeckanji"
	/bin/rm -f $DIRS
	;;
    #
    # ACT = POST_A | POST_L
    #
    POST_[AL])
	. $SHELL_LIB/libscp
	STL_LockInit
	STL_DepLock $SUBSET $DEPSETS
	#
	# Add locale symlinks if not there yet
	#
	cd /usr/i18n/dt/appconfig/help
	[ ! -L ja_JP.deckanji  ] && ln -s ./ja_JP.eucJP ja_JP.deckanji
	[ ! -L ja_JP.sdeckanji ] && ln -s ./ja_JP.eucJP ja_JP.sdeckanji
	[ ! -L ja_JP           ] && ln -s ./ja_JP.eucJP ja_JP
	[ ! -d /usr/dt/appconfig/help ] && mkdir -p /usr/dt/appconfig/help
	cd /usr/dt/appconfig/help
	HELPDIR=../../../i18n/dt/appconfig/help
	[ ! -L ja_JP.deckanji  ] && ln -s ${HELPDIR}/ja_JP.deckanji
	[ ! -L ja_JP.sdeckanji ] && ln -s ${HELPDIR}/ja_JP.sdeckanji
	[ ! -L ja_JP.eucJP     ] && ln -s ${HELPDIR}/ja_JP.eucJP
	[ ! -L ja_JP.SJIS      ] && ln -s ${HELPDIR}/ja_JP.SJIS
	[ ! -L ja_JP           ] && ln -s ${HELPDIR}/ja_JP
	cd /usr/i18n/lib/nls/msg
	MSGDIR=../../../../../dt/lib/nls/msg
	[ ! -e ja_JP.deckanji/DtHelp  ] && \
	    ln -s ${MSGDIR}/ja_JP.deckanji/DtHelp.cat  ja_JP.deckanji/DtHelp 
	[ ! -e ja_JP.sdeckanji/DtHelp ] && \
	    ln -s ${MSGDIR}/ja_JP.sdeckanji/DtHelp.cat ja_JP.sdeckanji/DtHelp
	[ ! -e ja_JP.eucJP/DtHelp     ] && \
	    ln -s ${MSGDIR}/ja_JP.eucJP/DtHelp.cat     ja_JP.eucJP/DtHelp
	[ ! -e ja_JP.SJIS/DtHelp      ] && \
	    ln -s ${MSGDIR}/ja_JP.SJIS/DtHelp.cat      ja_JP.SJIS/DtHelp
	;;
    #
    # 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 $*
