#!/bin/sh
#
#pragma ident	"@(#)sdm.script 1.8	02/07/19 SMI"
#
# Copyright (c) 2001-2002 by Sun Microsystems, Inc.
# All rights reserved.
#

# The script starts Sun (TM) Download Manager

echo "Sun (TM) Download Manager"
echo "Copyright (c) 2001-2002 by Sun Microsystems, Inc."
echo "All rights reserved."

# Setup SDM_HOME environment variable if it isn't set
if [ -z "$SDM_HOME" ]
then
	SDM_HOME=.
fi
export SDM_HOME

# Setup SDM_PROP environment variable if it isn't set
if [ -z "$SDM_PROP" ]
then
	SDM_PROP=$SDM_HOME
fi
export SDM_PROP

# Check that Java classes for the Sun (TM) Download Manager are available
if [ ! -f $SDM_HOME/sdm.jar ]
then
	echo "ERROR: Unable to find Java classes for the Sun (TM) Download"
	echo "ERROR: Manager. Please, setup the SDM_HOME environment variable,"
	echo "ERROR: or run the script in the home directory of the utility."
	exit 1
fi

# Update CLASSPATH environment variable
CLASSPATH=$CLASSPATH:$SDM_HOME/sdm.jar:
export CLASSPATH

echo Starting Java interpreter...

# Show version of Java interpreter
java -version
if [ "$?" != 0 ]
then
	echo "ERROR: Java interpreter reported a problem. Please, check the"
	echo "ERROR: output log."
	exit 1
fi

# Run the Sun (TM) Download Manager in Java interpreter
java -Dhomedir=$SDM_HOME -Dpropdir=$SDM_PROP com.sun.sdm.SunDownloadManager $*
if [ "$?" != 0 ]
then
	echo "ERROR: Java interpreter reported a problem. Please, check the"
	echo "ERROR: output log."
	exit 1
fi
exit 0
