#!/bin/sh

# this script needs to be run to use the ora_ts script
# it creates an ops user for the bcnu id. If using this then it would
# be best to create a specific user/group for bcnu rather than using the
# default which is normally nobody or adm as these id's can be used for 
# other things

# Contributed by Wulf Dietrich - w_dietrich@hotmail.com 10/2/2000
# developed on AIX

# set -x

SID=$1
BCNUUSER=$2
ORACLE_OWNER=$3

if ! [ $# -eq 2 -o $# -eq 3 ] ; then
  echo "`basename $0`: <ORACLE_SID> <BCNU DB-User> [
<Oracle owner> ]"
  exit 1
fi

if [ -z "$SID" -o -z "$BCNUUSER" ] ; then
  echo "`basename $0`: <ORACLE_SID> <BCNU DB-User> [
<Oracle owner> ]"
  exit 1
fi

ORACLE_HOME=`grep "^$SID:" /etc/oratab | cut -d: -f2`
if [ -z "$ORACLE_HOME" ] ; then
  echo "ORACLE_SID $SID not found in /etc/oratab"
  exit 1
fi


if [ -z "$ORACLE_OWNER" ] ; then
  ORACLE_OWNER=`grep ":$ORACLE_HOME:" /etc/passwd | cut -d: -f1`
  if [ -z "$ORACLE_OWNER" ] ; then
    echo "ORACLE_OWNER not found in /etc/passwd"
    exit 1
  fi
fi

BCNUDBUSER='ops\$'"${BCNUUSER}"

echo | su - $ORACLE_OWNER -c "ORACLE_SID=$SID; \
ORACLE_HOME=$ORACLE_HOME; export ORACLE_SID ORACLE_HOME; \
sqlplus / <<EOF
create user $BCNUDBUSER
  identified by externally
  default tablespace tools
  temporary tablespace temp
;
grant create session to $BCNUDBUSER;
grant select any table to $BCNUDBUSER;
exit
EOF
