#
# Never run any DBA or SA under for sybase as root
#
if [ `id -u` -eq 0 ]; then
    echo "This account should not be ran with uid = 0"
    exit 1
fi

# Have SYBASE set to the correct location
# SYBASE=`pwd`			; export SYBASE
export SYBASE=`rpm -q --queryformat '%{installprefix}' sybase-common`

export SYBPLATFORM="linux"
export LD_LIBRARY_PATH="$SYBASE/lib"
export LC_ALL="default"
export PATH="$SYBASE/bin:$PATH:."

unset LANG

if [ ! "${PAGER}" ]; then
    PAGER=cat			; export PAGER
fi

# Have the README and WARNINGS at least presented once.
if [ -f ${SYBASE}/.readme ]; then
    ${PAGER} ${SYBASE}/README
    rm -f ${SYBASE}/.readme
    if [ `id -u` = 0 ]; then
	cat <<\EOM

   WARNING: Before configuring this release of Sybase Adaptive Server
   Enterprise we strongly recommend you to run from an other login
   account then root.

   This because the SQL Server can be configured to operate on designated
   disk partitions resulting in data loss if the permissions are not
   setup properly.

EOM
	echo -n "Do you like to continue? [y/n]: "
	read ans
	case $ans in

		[Yy]*)	break ;;
		*)	exit ;;

	esac
    fi
fi

# Need to run srvbuild 1st time
if [ -x ${SYBASE}/bin/srvbuild -a -f ${SYBASE}/.srvbuild ]; then
    echo ; echo -n "Do you want to start 'srvbuild' now? [y/n]: "
    read ans
    case $ans in

	[Yy]*) if [ ! "${DISPLAY}" ]; then
			DISPLAY=":0.0"		; export DISPLAY
	       fi

	       if [ ! -x ${SYBASE}/bin/srvbuild ]; then
	       	   echo ; echo "The Package Sybase ASE is not found on your system"
		   echo "Please install the sybase-ase package before proceding"
    		   touch ${SYBASE}/.readme
	           exit 1
	       fi

	       ${SYBASE}/bin/srvbuild
	       rm -f ${SYBASE}/.srvbuild
	       exit 0
	       ;;

	*) echo ; echo "You can start it by hand later by executing"
	   echo "${SYBASE}/bin/srvbuild"

    esac
fi

