#!/bin/sh
# $Id: vea,v 1.8.2.5 2003/01/07 09:07:13 darell Exp $  - %Q%
#ident "%Z%isis:$RCSfile: vea,v $ $Revision: 1.8.2.5 $"

# Copyright (c) 2002 VERITAS Software Corporation.  ALL RIGHTS RESERVED.
# UNPUBLISHED -- RIGHTS RESERVED UNDER THE COPYRIGHT
# LAWS OF THE UNITED STATES.  USE OF A COPYRIGHT NOTICE
# IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
# OR DISCLOSURE.
#
# THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND
# TRADE SECRETS OF VERITAS SOFTWARE.  USE, DISCLOSURE,
# OR REPRODUCTION IS PROHIBITED WITHOUT THE PRIOR
# EXPRESS WRITTEN PERMISSION OF VERITAS SOFTWARE.
#
#              RESTRICTED RIGHTS LEGEND
# USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT IS
# SUBJECT TO RESTRICTIONS AS SET FORTH IN SUBPARAGRAPH
# (C) (1) (ii) OF THE RIGHTS IN TECHNICAL DATA AND
# COMPUTER SOFTWARE CLAUSE AT DFARS 252.227-7013.
#              VERITAS SOFTWARE
# 1600 PLYMOUTH STREET, MOUNTAIN VIEW, CA 94043

FIND=/usr/bin/find
XARGS=/usr/bin/xargs
GETOPTS=/usr/bin/getopts

USER_HOME=$HOME
if [ ! -d $HOME ]
then
    echo Cannot determine the home directory. It may not exist.
    exit 3
fi   

append_list()
{
    _list=$1
    shift
    eval "set -- \$$_list \$*"
    eval "$_list=\$*"
}

LIST_OF_DIRS=

append_list LIST_OF_DIRS $USER_HOME/.VRTSob
append_list LIST_OF_DIRS $USER_HOME/.VRTSob/extensions
append_list LIST_OF_DIRS $USER_HOME/.VRTSob/log
append_list LIST_OF_DIRS $USER_HOME/.VRTSob/msgCatalogs
append_list LIST_OF_DIRS $USER_HOME/.VRTSob/preference

PERMS=0700

for i in $LIST_OF_DIRS
do
        if [ ! -d $i ]
        then
                mkdir $i
		if [ $? != 0 ]
		then
			echo Cannot create directory $i
			exit 4;
		fi
        fi
done

THE_DIR=`pwd`

if [ -d $USER_HOME/.VRTSob ];
then
    cd $USER_HOME/.VRTSob
    $FIND . -type d -print | $XARGS chmod 0700 > /dev/null 2>/dev/null
    $FIND . -type f -print | $XARGS chmod 0600 > /dev/null 2>/dev/null
    cd $THE_DIR
fi

if [ -d $USER_HOME/.VERITAS ];
then
    cd $USER_HOME/.VERITAS
    $FIND . -type d -print | $XARGS chmod 0700 > /dev/null 2>/dev/null
    $FIND . -type f -print | $XARGS chmod 0600 > /dev/null 2>/dev/null
    cd $THE_DIR
fi

if [ ! "$DISPLAY" ];
then
    echo "Please set the DISPLAY environment variable.";
    exit 1;
fi

plat=`uname`
plat_ver=`uname -r`
BASEDIR="/opt/VRTSob"

if [ $plat = "SunOS" ]
then
    BASEDIR=`pkgparam VRTSobgui BASEDIR`
fi
if [ $plat = "HP-UX" ] >/dev/null 2>&1
then
#    if expr "$plat_ver" \>= "B.11.22" >/dev/null 2>&1
#    then
#        /opt/java1.3/jre/bin/java -XX:MaxPermSize=64m -classpath $BASEDIR/lib/cat/:$BASEDIR/lib/OBGUI.jar vrts.ob.gui.core.runtime.OBGUI_App $*
#    else
     $BASEDIR/jre/bin/java -XX:MaxPermSize=64m -classpath $BASEDIR/lib/cat/:$BASEDIR/lib/OBGUI.jar vrts.ob.gui.core.runtime.OBGUI_App $*
#    fi
else
    $BASEDIR/jre/bin/java -mx128m -ms32m -classpath $BASEDIR/lib/cat/:$BASEDIR/lib/OBGUI.jar vrts.ob.gui.core.runtime.OBGUI_App $*
fi

# Command line options
# -s: Used to launch a different skin
# -c: Specifies the configuration file

if [ $? != 0 ]
then
	while $GETOPTS :s:c: name
	do
		case $name in
		    s)  if [ $name = "s" ]
			then
				echo The skin specified $OPTARG may not exist or
				echo It may not be specified in the classpath
				exit 1
			fi
			;;
		    c)  if [ $name = "c" ]
			then
				echo Configuration file $OPTARG specified is incorrect
				exit 1
			fi 
		   	;;
	 	    ?)	echo Error in parsing command line
			exit 2
			;;
		esac
	done
fi

if [ -d $USER_HOME/.VRTSob ];
then
    cd $USER_HOME/.VRTSob
    $FIND . -type d -print | $XARGS chmod 0700 > /dev/null 2>/dev/null
    $FIND . -type f -print | $XARGS chmod 0600 > /dev/null 2>/dev/null
    cd $THE_DIR
fi

if [ -d $USER_HOME/.VERITAS ];
then
    cd $USER_HOME/.VERITAS
    $FIND . -type d -print | $XARGS chmod 0700 > /dev/null 2>/dev/null
    $FIND . -type f -print | $XARGS chmod 0600 > /dev/null 2>/dev/null
    cd $THE_DIR
fi

exit 0
