#!/bin/ksh
#!/usr/bin/ksh
# @(#) $Revision: 76.3 $

OLIBLIST=/usr/tmp/cplib$$
return_value=0

typeset ERROR=0

trap "rm -f $OLIBLIST; exit" 0 1 2 3 15

# A shared command linking with shared libraries (*.sl) may prevent the
# subsequent "cp" from working (get a "Text file busy" error message).
# This function is to rename the file first.  
# HISTORY:  /etc/rename is supposed to link to /etc/link that can
#           also perform this task.
rename()
{
	typeset -r BASE=$(basename $1)
	typeset -r DIR=$(dirname $1)
	[ -f "$DIR/#$BASE" ] && /sbin/unlink "$DIR/#$BASE"
	/sbin/link "$DIR/$BASE" "$DIR/#$BASE"
	/sbin/unlink "$DIR/$BASE"
}

#
# After careful analysis, it was determined linking the following 
# shared libraries bought us nearly nothing in the disk savings area 
# while it provides the capacity to affect performance in a negative 
# fashiion.  So... they're outta here!
#
rm -f /usr/lib/libcurses.sl /usr/lib/libM.sl /usr/lib/libm.sl

#
# These shared libraries (linked together) were added to the s300/s700
# BE during IF3/9.00.  Having them in the BE causes a dependency between
# filesets (IND's sendmail and our vacation and uupath were linking
# against it).  The problem is that lib[n]dbm.sl is in PROG-AUX and may
# not always be loaded.  The archived versions can remain.
#
rm -f /usr/lib/libndbm.sl /usr/lib/libdbm.sl /usr/lib/libdbm.1

typeset SRC=/Commands/src/lib
typeset DEST=/usr/lib

[ -f /Commands/src/lib/libc/shared_pa1/libc.1 ]     && rename /usr/lib/libc.1
[ -f /Commands/src/lib/libsec/libsec.1 ] && rename /usr/lib/libsec.1

while read LIB; do
	cpset $SRC/$LIB $DEST 0555 bin bin || ERROR=1
done << EOF
libBSD/libBSD.a
libBUILD/libBUILD.a
libPW/libPW.a
libV3/libV3.a
libc/archive_pa1/libc.a
libc/shared_pa1/libpicc.a
libdbm/libdbm.a
libempty/libempty.a
libscmd/libscmd.a
libsec/libsec.a
libfs/libfs.a
libc/shared_pa1/libc.1
libsec/libsec.1
curses-xopen/libxcurses.1
EOF

SRC=/Commands/src/lib/loc/methods
DEST=/usr/lib/nls/loc/methods.1

mkdir -p $DEST

cpset $SRC/HP15/libHP15.sl $DEST 555 bin bin || ERROR=1
cpset $SRC/SJIS/libSJIS.sl $DEST 555 bin bin || ERROR=1
cpset $SRC/eucJP/libeucJP.sl $DEST 555 bin bin || ERROR=1
cpset $SRC/eucTW/libeucTW.sl $DEST 555 bin bin || ERROR=1

#
# THIS IS A KLUDGE FOR Walnut Creek as is much of the libxcurses build.
#
/usr/bin/ln -s /usr/lib/libxcurses.1 /usr/lib/libcurses.sl || ERROR=1

exit $ERROR
