#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident	"@(#)postinstall	1.9	07/06/04 SMI"

# install a domestic version of the libcrypt symlink
# in place of the international symlink.

PKGCOND=/usr/bin/pkgcond
is_srngz=99

if [ -x $PKGCOND ]; then
     $PKGCOND -v is_sparse_root_nonglobal_zone > /dev/null 2>&1
     is_srngz=$?
fi

##
## 'pkgcond' does not exist when you do live upgrade from S8/S9
## so in that case, use 'touch' instead for the testing
##

test_writable() {
        if [ $is_srngz -ne 99 ]; then
                $PKGCOND is_path_writable $1 && return $?
        else
                /usr/bin/touch $1/.test.$$ > /dev/null 2>&1
                if [ $? !=  0 ]; then
                        return 1
                else
                        rm -f  $1/.test.$$ > /dev/null 2>&1
                        return 0
                fi
        fi
} 

sparc_postinstall () {
	# remove the international link if it exists
	#
test_writable $BASEDIR/usr/lib/sparcv9 > /dev/null 2>&1
if [ $? = 0 ]; then
    if [ -h $BASEDIR/usr/lib/sparcv9/libcrypt.so ]; then
	    rm -f $BASEDIR/usr/lib/sparcv9/libcrypt.so
    fi
    if [ -h $BASEDIR/usr/lib/sparcv9/libcrypt.so.1 ]; then
	    rm -f $BASEDIR/usr/lib/sparcv9/libcrypt.so.1
    fi
    
    # make the symlink
    #
    ln -s libcrypt_d.so $BASEDIR/usr/lib/sparcv9/libcrypt.so || exit 2
    ln -s libcrypt_d.so.1 $BASEDIR/usr/lib/sparcv9/libcrypt.so.1 || exit 2
fi
}    
 
test_writable $BASEDIR/usr/lib > /dev/null 2>&1
if [ $? = 0 ]; then

# remove the international link if it exists
	if [ -h $BASEDIR/usr/lib/libcrypt.a ]; then
		rm -f $BASEDIR/usr/lib/libcrypt.a
	fi
	if [ -h $BASEDIR/usr/lib/libcrypt.so ]; then
		rm -f $BASEDIR/usr/lib/libcrypt.so
	fi
	if [ -h $BASEDIR/usr/lib/libcrypt.so.1 ]; then
		rm -f $BASEDIR/usr/lib/libcrypt.so.1
	fi

# make the symlink
#
	if [ -f $BASEDIR/usr/lib/libcrypt_d.a ]
	then
		ln -s libcrypt_d.a $BASEDIR/usr/lib/libcrypt.a || exit 2
	fi
	ln -s libcrypt_d.so $BASEDIR/usr/lib/libcrypt.so || exit 2
	ln -s libcrypt_d.so.1 $BASEDIR/usr/lib/libcrypt.so.1 || exit 2

fi
if [ "$ARCH" = "sparc" ]; then sparc_postinstall; fi;

exit 0
