#!/bin/ksh 
#
#   @(#)svc_install_xil13.sunw	1.6 99/01/28 
# 
# Create SunVideo Compatibility Hierarchy  
# 
# Copyright (c) 1998 MultiMedia Access Corporation - Osprey Technologies Inc. 
# 600 Airport Blvd. Suite 900, Morrisville NC, 27560 USA. All Rights Reserved.
# 
# This product and related documentation is protected by copyright laws and 
# international treaties. No part of this product or related documentation  
# may be reproduced, distributed, or decompiled in any form by any means 
# without prior written authorization of MultiMedia Access Corporation. 
# Unauthorized reproduction or distribution of this program, or any part of 
# it, may result in severe civil and criminal penalties, and will be 
# prosecuted to the maximum extent possible under the law.
# 
# MMAC reserves the right to change any products herein at any time and 
# without notice. MMAC does not assume any liability arising from the 
# application or use of this product, except as expressly agreed to in 
# writing by MMAC. Use and purchase of this product does not convey a license
# under any patent rights, copyrights, trademark rights, or any other 
# intellectual property rights of MMAC, Sun Microsystems, or others. 
# 
 
progname=${0##*/}

XILDIR=/usr/openwin/lib/xil
DEVDIR=$XILDIR/devhandlers
DEVDIR_ORIG=$XILDIR/devhandlers_orig
NEWDEVDIR=$XILDIR/devhandlers_svc_o1k

verbose=""

USAGE=\
"usage: $progname [ opts ] 
        -v              -- verbose
"

fatal() {
    if [ "$1" ]
    then
        echo $* >&2
    fi
    echo "$USAGE" 1>&2
    exit 1
}    

#
# process options
#

while getopts vt:x:s: OPT
do
    case "$OPT" in
    	v) verbose="yes";;
        *)  echo $OPTARG
            fatal
    esac
done

[ "$verbose" ] && echo xil directory is $DEVDIR
[ "$verbose" ] && echo dest directory is $NEWDEVDIR


#
# check to make sure we are on correct os
#
if [ ! -f /usr/openwin/lib/xil/config ]
then
   echo "XIL 1.3 is not on this system"
   echo "This script is applicable for Solaris 2.6 or greater"
   OS=`uname -r`
   echo "Current OS detected as SunOS $OS"
   exit 2
fi
 
#
# check to make sure required pkgs installed
#
 
if [ ! -f $DEVDIR/xilCompress_Cell.so.2 ]
then
    echo "XIL libraries not found in $DEVDIR"
    exit 2
fi
 
if [ ! -f $DEVDIR/xilIO_MMACo1k.so.2 ] 
then
    echo "SunVideo-Plus libraries not found in $DEVDIR"
    exit 2
fi

#
# check to make sure devhandlers is original
#
if [ -L $DEVDIR ]
then
    echo "$DEVDIR is a symbolic link."
    echo "Is svc mode already installed?"
    echo "If so, run svc_uninstall_xil1.3 before running svc_install_xil1.3."
    exit 2
fi    
  
#
# create SunVideo Compatibility dir if it doesn't exist
#

if [ ! -d $NEWDEVDIR ]
then
    mkdir $NEWDEVDIR
fi
   
#
# routine to create sym links 
#

create_link()
{
    if [ -h $2 ]
    then
        echo "Removing previous symlink for $2"
        rm -f $2
    fi
    if [ -f $2 ] || [ -h $2 ]
    then
        echo "$2 already exists, no link done"
    else
        ln -s $1 $2
    fi
}


#
# create neccessary sym links
#

cd $DEVDIR || fatal "$DEVDIR does not exist"
find * -type f -print >/tmp/fxil.$$

#
# move devhandler dir
#

mv $DEVDIR $DEVDIR_ORIG

cd $NEWDEVDIR

for i in `cat /tmp/fxil.$$`
do
   create_link $DEVDIR_ORIG/$i ./$i
done

#
# If rtvc pkgs installed, move rtvc xil libs to new names
#
if [ -f $NEWDEVDIR/xilIO_SUNWrtvc.so.2 ]
then

  cd $NEWDEVDIR

  mv xilCompute_CellBSUNWrtvc.so.2  xilsvcCompute_CellBSUNWrtvc.so.2  
  mv xilCompute_JpegSUNWrtvc.so.2   xilsvcCompute_JpegSUNWrtvc.so.2
  mv xilCompute_Mpeg1SUNWrtvc.so.2  xilsvcCompute_Mpeg1SUNWrtvc.so.2
  mv xilCompute_UYVYSUNWrtvc.so.2   xilsvcCompute_UYVYSUNWrtvc.so.2
  mv xilIO_SUNWrtvc.so.2            xilsvcIO_SUNWrtvc.so.2

# create links for H261 in svc mode 
# (note that rtvc versions do not really exist)

# TODO
# ln -s xilcomputeH261_MMACo1k.so.1   xilsvccomputeH261_SUNWrtvc.so.1
# ln -s xilcomputeH261gx_MMACo1k.so.1 xilsvccomputeH261gx_SUNWrtvc.so.1

fi

#
# set up compatibility links
#

cd $NEWDEVDIR

ln -s xilCompute_CellBMMACo1k.so.2  xilCompute_CellBSUNWrtvc.so.2  
ln -s xilCompute_JpegMMACo1k.so.2   xilCompute_JpegSUNWrtvc.so.2
ln -s xilCompute_Mpeg1MMACo1k.so.2  xilCompute_Mpeg1SUNWrtvc.so.2
ln -s xilCompute_UYVYMMACo1k.so.2   xilCompute_UYVYSUNWrtvc.so.2
ln -s xilIO_MMACo1k.so.2            xilIO_SUNWrtvc.so.2

rm /tmp/fxil.$$

ln -s $NEWDEVDIR $DEVDIR

#
# leave marker for uninstall
#
touch $NEWDEVDIR/svc_o1k_marker

echo "SVC XIL 1.3 hierarchy creation complete."
echo " - If you have not already setup pseudo svc devices, run: svc_devices install"



