#!/bin/sh
#
# @(#)dbmi_config.sh 1.2 96/07/13 Copyright (c) 1996, Legato Systems, Inc.
#
# All rights reserved.
#
# dbmi_config: this program is used to create resources on your
# server for the Database Module for Informix (DBMI).
#
# Returns 0 on success; 1 on failure.
#

#
# usage(): display correct usage
#
usage()
{
	echo "usage: $0 [ -s server ]"
	exit 1
}

NSR_SERVER=localhost
DATANAME=DBMIData
LOGSNAME=DBMILogs

#
# Process arguments
#
processargs()
{
while [ $# -gt 0 ]; do
	case "$1" in
	-s )	# Specify server
		NSR_SERVER=$2
		shift
		shift
		;;
	*)
		;;
	esac
done
}

#
# Report failure
#
failure()
{
echo "Could not create the resources.  Make sure the server is" 
echo "running and you are executing this script to the appropriate"
echo "server (either run it on the server or use the '-s' option)."

	exit 1
}

#
# The main portion of this shell.
#
# Process arguments
# Run nsradmin to create the appropriate resources.

processargs $*

#
# Make sure the RAP server is up.
#
nsradmin -s $NSR_SERVER -i - << EOF > /dev/null
print type:nsr
EOF

if [ $? != 0 ]; then
	failure
fi

echo "Creating appropriate resources."

nsradmin -s $NSR_SERVER -i - << EOF > /dev/null
create type: nsr label;
name: $DATANAME;
fields: $DATANAME, 001-999;
separator: .;
next: $DATANAME.001
EOF

nsradmin -s $NSR_SERVER -i - << EOF > /dev/null
create type: nsr pool;
name: $DATANAME;
enabled: yes;
label template: $DATANAME;
save sets: $DATANAME
EOF

nsradmin -s $NSR_SERVER -i - << EOF > /dev/null
create type: nsr label;
name: $LOGSNAME;
fields: $LOGSNAME, 001-999;
separator: .;
next: $LOGSNAME.001
EOF

nsradmin -s $NSR_SERVER -i - << EOF > /dev/null
create type: nsr pool;
name: $LOGSNAME;
enabled: yes;
label template: $LOGSNAME;
save sets: $LOGSNAME
EOF

echo "Done creating resources."

exit 0

