home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
-
- # Shell script configures the EOF2.x examples
- # This shell script allows the user to enter the necessary information for
- # configuring the EOF 2.x model files for the users preferred database type.
- # The script either accepts as arguments or prompts the user for the name of
- # the adaptor to use in the examples and information to connect to the user's
- # example database. The script quires the adaptorName and connection
- # information and validates the connection information by attempting to
- # connect to the database before actually reconfiguring the model files.
-
- # Although the script will configure the model files without being able to
- # connect to the database, it is preferable that a both the Movie and
- # Rental databases are created before running this script. The tables and
- # data can be loaded into the databases after running this script by
- # executing the install_database program in the DatabaseSetUp directory. Of
- # course, the data only needs to be installed once while the eoexamples may
- # be installed several times by different users.
-
- cat << FOOBAR
-
- This script handles the configuration of the EOF 2.0 examples. The
- examples are designed to work with data managed by Informix, Oracle,
- Sybase, or any adaptor that is fully compliant with EOF 2.0. The
- script will ask the user which DBMS to use for the Movies data and
- the Rentals data. Based on the users response, the script will ask
- for the information necessary to connect with that DBMS.
-
- We suggest that you allocate the necesary DBMS resources before
- installing the examples. For Sybase and Informix, this means
- creating two databases: one for the Movies data and one for the
- Rentals. For Oracle, this means creating two users.
-
- This script prompts the user for information to connect to the DBMS
- for each of these two sets of data and attempts to ensure that the
- connection information is correct before setting that information in
- the EOModels used by the example applications.
-
- When this script has finished executing, you can 'cd' to the
- 'DatabaseSetUp' directory and execute the install_database script.
- That script will create all of the tables and load the data necessary
- for the EOF 2.0 examples.
-
- FOOBAR
-
- #
- # Initialize variables
- #
- Usage="configure_examples [-movie <adaptorName> <connectionDictionary>] [-rental <adaptorName> <connectionDictionary>]"
-
- movieAdaptorName=
- movieConnectionDictionary=
- rentalAdaptorName=
- rentalConnectionDictionary=
-
- #
- # NEXT_EOUTIL_PATH should only be set for debugging purposes by Next
- # Developers. Setting this environment variable in customer sites will
- # cause this script to fail.
- #
- masterDir=${NEXT_ROOT}/NextDeveloper/Examples/EnterpriseObjects
- EOUTIL=${NEXT_EOUTIL_PATH-${masterDir}/DatabaseSetUp/eoutil}
- export EOUTIL
- ECHO=echo
-
- #
- # Get the current working directory and verify that we're in the right place
- #
- exepath=`echo $0`
- basename=`basename $exepath`
- currDir=`echo $exepath | sed -e s,$basename\$,, | sed -e s,/\$,,`
- if test ! -z "$currDir"; then
- cd $currDir
- fi
- currDir=`pwd`
-
- if test ! -d $currDir/Movie/Movies.eomodeld -o ! -w $currDir/Movie; then
- echo ""
- echo "You must be in the top directory of the *installed* examples in order"
- echo "to run this script. Please cd to that directory and execute this script again."
- exit 1
- fi
-
- if test $"currDir" = $"masterDir"; then
- echo ""
- echo "Cannot drop data from $currDir. Please copy the examples and cd to"
- echo "the copied directory and execute this script again."
- exit 1
- fi
-
- #
- # Loop through arguments and set initial values
- #
- while test $# -gt 0 ; do
- case $1 in
- -#)
- set -x;;
- -[mM]*)
- shift; movieAdaptorName=$1;
- shift; movieConnectionDictionary=$1;;
- -[iI]*)
- shift; rentalAdaptorName=$1;
- shift; rentalConnectionDictionary=$1;;
- *)
- echo Unrecognized argument $1;
- echo $Usage;
- exit 1;;
- esac
- shift
- done
-
- echo -n "Hit the return key when ready to continue:"
- read response
-
- #
- # Get connection information and adaptor name for each of the example
- # databases.
- #
- for example in Movie Rental ; do
- if test "$example" = "Movie"; then
- adaptorName=$movieAdaptorName
- connectionDictionary=$movieConnectionDictionary
- else
- adaptorName=$rentalAdaptorName
- connectionDictionary=$rentalConnectionDictionary
- fi
-
- #
- # Ask the user for the name of the adaptor to be used when connecting to
- # the example database
- #
- while test -z "$adaptorName" ; do
- echo ""
- echo 'Enter the name of the adaptor to use when connecting to'
- echo -n "the $example database (Oracle, Sybase, Informix, ODBC, FlatFile ...): "
- read adaptorName
- done
-
- #
- # Make sure the case is used properly in the adaptor name, we can't do
- # this for 3rd Party adaptors that we don't know about.
- #
- case $adaptorName in
- [Oo][Rr][Aa][Cc][Ll][Ee]) adaptorName=Oracle;;
- [Ss][Yy][Bb][Aa][Ss][Ee]) adaptorName=Sybase;;
- [Ii][Nn][Ff][Oo][Rr][Mm][Ii][Xx]) adaptorName=Informix;;
- [Ff][Ll][Aa][Tt][Fi][Ii][Ll][Ee]) adaptorName=FlatFile;;
- [Oo][dD][Bb][Cc]) adaptorName=ODBC;;
- esac
-
- #
- # Based on the adaptor name, prompt the user to enter the necessary
- # information to connect to the Movie database and the Rental
- # database.
- #
- while test -z "$connectionDictionary" ; do
- case $adaptorName in
- Oracle) words="serverId hostMachine userName password";;
- Sybase) words="userName hostName databaseName password";;
- Informix) words="dbName userName password";;
- FlatFile) words="path";;
- ODBC) words="dataSource userName password";;
- *) echo "You must enter a connectionDictionary argument when not"
- echo "using one of the NeXT supplied adaptors."
- echo "exiting ....."
- exit 1;;
- esac
-
- echo ""
- echo ""
- echo "Enter the connection information for the $adaptorName $example database"
- connectionDictionary="{ "
-
- for i in $words ; do
- val=
- echo -n "Enter value for $i: "
- read val
- if test -z "$val"; then
- val=\"\"
- else
- val=`echo $val | sed -e 's/"/\\\"/'`
- val=\"$val\"
- fi
-
- connectionDictionary=`echo $connectionDictionary | sed -e 's/"/\\"/g'`
- connectionDictionary="$connectionDictionary $i = $val;"
- done
-
- connectionDictionary="$connectionDictionary }"
-
- echo ""
- echo Please wait while I attempt to connect to database...
- if eval ${EOUTIL} connect $adaptorName \'$connectionDictionary\'; then
- echo ""
- echo ""
- echo "Attempt to connect succeeded -- continuing with installation"
- else
- echo -n "Attempt to connect with database failed do you want to reenter the connection dictionary? (y/n)"
- read response
- if test "$response" != "y" ; then
- echo -n "Continue with the installation without connecting to the database? (y/n)"
- read response
- if test "$response" != "y" ; then
- exit 1
- fi
- else
- connectionDictionary=
- fi
- fi
- done
-
- if test "$example" = "Movie"; then
- movieAdaptorName=$adaptorName;
- movieConnectionDictionary=$connectionDictionary
- else
- rentalAdaptorName=$adaptorName;
- rentalConnectionDictionary=$connectionDictionary;
- fi
- done
-
- echo ""
- echo "Converting Movie model in $currDir/BusinessLogic to $movieAdaptorName model"
- cd $currDir/BusinessLogic
- eval ${EOUTIL} convert Movies.eomodeld $movieAdaptorName \'$movieConnectionDictionary\' tmp.eomodeld
- if test $? -eq 0; then
- rm -rf Movies.eomodeld
- mv tmp.eomodeld Movies.eomodeld
- else
- echo ""
- echo "ERROR: an error occurred while attempting to convert model -- exiting"
- echo ""
- echo ""
- exit 1
- fi
-
- echo "Copying converted movie model into $currDir/Movie and $currDir/Studios"
- rm -rf $currDir/Movie/Movies.eomodeld
- cp -r Movies.eomodeld $currDir/Movie
- rm -rf $currDir/Studios/Movies.eomodeld
- cp -r Movies.eomodeld $currDir/Studios
-
- echo ""
- echo "Converting Rental model in $currDir/BusinessLogic to $rentalAdaptorName model"
- cd $currDir/BusinessLogic
- eval ${EOUTIL} convert Rentals.eomodeld $rentalAdaptorName \'$rentalConnectionDictionary\' tmp.eomodeld
- if test $? -eq 0; then
- rm -rf Rentals.eomodeld
- mv tmp.eomodeld Rentals.eomodeld
- else
- echo ""
- echo "ERROR: an error occurred while attempting to convert model -- exiting"
- echo ""
- echo ""
- exit 1
- fi
-
- echo ""
- echo "Finished configuring eoexamples."
- echo Do "make all" to build everything.
-
-