#!/bin/ksh -p
#
# ident "@(#)utcompatlinksctl.ksh	1.7 10/12/14 Oracle"
#
# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
#

set -u

########################################################################
#
# Creates compatibility library symlinks in /opt/SUNWuttsc/lib
# 
# Checks the availability of the required library SRSS depends on
# If the required library is not available
# then checks the availability of the compatible library
# If the compatible library is present then creates a symlink.
#
########################################################################


########################################################################
#
# Operation entry points, one for each keyword.
# This is where the specific work for this feature happens.
#
########################################################################


disable() {
    
    for LINK in     $COMPATLINK_LIBSSL \
		    $COMPATLINK_LIBCRYPTO
	do
		if [ -L $LINK ] ; then
			rm -rf $LINK
			if $VERB; then
				print "$LINK link disabled"
			fi
		fi
	done
	return 0

}


createLink() {

	typeset LIB=$1
	typeset COMPATLIB=$2
	typeset COMPATLINK=$3
	
	if [ ! -f $LIB ] ; then
		if [ -f $COMPATLIB ]; then
			rm -rf $COMPATLINK
			ln -fs $COMPATLIB $COMPATLINK
			if $VERB; then
				print "$COMPATLINK -> $COMPATLIB link enabled"
			fi
		else
			print -u2 "[${PROG}] Warning: Failed to create $COMPATLINK -> $COMPATLIB link"
			print -u2 "[${PROG}]          $COMPATLIB does not exist."
		fi
	fi

}


enable() {
	createLink $LIBSSL $COMPATLIB_LIBSSL $COMPATLINK_LIBSSL
	createLink $LIBCRYPTO $COMPATLIB_LIBCRYPTO $COMPATLINK_LIBCRYPTO
}


########################################################################
# Local Variables
# They must defined here to resolve the some of parameter resolution
# problem
########################################################################
local_variables() {

 	SRWC_LIB_COMPATLINKS=/opt/SUNWuttsc/lib/
 	LIBSSL=/usr/sfw/lib/libssl.so.0.9.7
 	LIBCRYPTO=/usr/sfw//lib/libcrypto.so.0.9.7
 	COMPATLIB_LIBSSL=/lib/libssl.so.0.9.*
 	COMPATLIB_LIBCRYPTO=/lib/libcrypto.so.0.9.*
 	COMPATLINK_LIBSSL=$SRWC_LIB_COMPATLINKS/${LIBSSL##*/}
 	COMPATLINK_LIBCRYPTO=$SRWC_LIB_COMPATLINKS/${LIBCRYPTO##*/}

}


########################################################################
#
# Configurable parameter
#
########################################################################
# NONE


########################################################################
#
# Variables used in the shared script utctl-shlib
#
########################################################################
DESCR="Sets up compatible library links for Sun Ray programs"


########################################################################
#
# Execution starts here
#
PROGPATH=`dirname $0`
. $PROGPATH/utctl-shlib
