#!/bin/sh
#
# Password encryption utility.
#
# Copyright(c) Sybase, Inc.
#
# @usage:  passencrypt [-help] -[algorithm <encryption_algorithm>] [-provider <cipher_provider_class>] -text <clear_text>
#

ARGS=$@

if [ -z "${SYBASE_UA}" ]; then
    echo The environment variable SYBASE_UA must be defined.
    echo This directory contains the UAF bin, common, conf, ..etc. directories.
    exit 1
fi

if [ ! -d ${SYBASE_UA}/bin ]; then
    echo The directory defined by the environment variable SYBASE_UA = ${SYBASE_UA}.
    echo Does not contain a bin directory.  Please check and make sure the enviromnet
    echo has been set properly.
    exit 1;
fi

if [ ! -x ${SYBASE_UA}/bin/myenv ]; then
    echo The file "myenv" was not found in the ${SYBASE_UA}/bin directory.
    echo Please check the assignment of the SYBASE_UA environment variable.
    exit 1
fi

. ${SYBASE_UA}/bin/myenv

if [ ${UA_ENV_STATUS} -eq 1 ]; then
  echo Failed to properly initialize environment variables
  exit 1
fi

CP=${SYBASE_UA}/common/lib/uaf-server.jar:${SYBASE_UA}/common/lib/uaf-client.jar
CP=${CP}:${SYBASE_UA}/common/lib/commons-logging.jar
CP=${CP}:${SYBASE_UA}/common/lib/log4j-1.2.6.jar
CP=${CP}:${SYBASE_UA}/common/lib/commons-cli-1.0.jar
CP=${CP}:${SYBASE_UA}/common/lib/commons-codec-1.2.jar

${SYBASE_JRE}/bin/java $bitwidth \
    -classpath ${CP}:${CLASSPATH} \
    -Dcom.sybase.ua.home="${SYBASE_UA}" \
    com.sybase.ua.services.security.tool.PasswordEncrypt \
    $ARGS

exit 0
