#!/bin/bash
#
#
#

TEMP_PATH=$0
if test $(id -ur) != 0; then
        echo
        echo "You should login as root user!"
        echo
        exit -1
fi

TEMP_VAR=`whereis ldconfig | awk '{print $2}'`
if [ $TEMP_VAR ]; then
	`$TEMP_VAR`
	OPENSSL_LIB=`$TEMP_VAR -p | awk '{print $4}' | grep libcrypto | head -1`
	STDC_LIB=`$TEMP_VAR -p | awk '{print $4}' | grep libstdc++.so.5 | head -1`
	EXPAT0_LIB=`$TEMP_VAR -p | awk '{print $4}' | grep libexpat.so.0 | head -1`
	EXPAT_LIB=`$TEMP_VAR -p | awk '{print $4}' | grep libexpat.so | head -1`
	LANG_GB=`set | grep LANG |grep UTF-8 | head -1`
	if [ ! $LANG_GB ]; then
		cp ${TEMP_PATH%/*}/lang/pkimanager_2052.gb2312 ${TEMP_PATH%/*}/lang/pkimanager_2052.lng
	else
		cp ${TEMP_PATH%/*}/lang/pkimanager_2052.utf8 ${TEMP_PATH%/*}/lang/pkimanager_2052.lng
	fi
	if [ ! $EXPAT0_LIB ]; then
		if [ $EXPAT_LIB ]; then
			ln -sf $EXPAT_LIB ${EXPAT_LIB%/*}/libexpat.so.0
		else
			echo WAR: Manager cannot run!
		fi
	fi

	if [ ! $STDC_LIB ]; then
		cp -rf ${TEMP_PATH%/*}/libstdc++.so /usr/lib/libstdc++.so.5
	fi
	`$TEMP_VAR`
fi
if [ $OPENSSL_LIB == 0 ]; then
	echo Please install openssl.
else
	${TEMP_PATH%install}/install-bin libcrypto=$OPENSSL_LIB
fi

if [ $TEMP_VAR ]; then
	`$TEMP_VAR`
fi

TEMP_VAR=`whereis chcon | awk '{print $2}'`
TEMP_VAR2=`whereis selinux | awk '{print $2}'`
if [ $TEMP_VAR ] && [ $TEMP_VAR2 ]; then
	if [ -d /usr/local/ngsrv ]; then
		$TEMP_VAR -t texrel_shlib_t /usr/local/ngsrv/*.so.1 &>/dev/null
		$TEMP_VAR -t texrel_shlib_t /usr/local/ngsrv/tsp/*.so &>/dev/null
		$TEMP_VAR -t texrel_shlib_t /usr/local/ngsrv/slotmon/*.so &>/dev/null
	fi
fi
