home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / configure_examples < prev    next >
Encoding:
Text File  |  1996-08-17  |  8.8 KB  |  261 lines

  1. #!/bin/sh
  2.  
  3. # Shell script configures the EOF2.x examples
  4. # This shell script allows the user to enter the necessary information for 
  5. # configuring the EOF 2.x model files for the users preferred database type. 
  6. # The script either accepts as arguments or prompts the user for the name of 
  7. # the adaptor to use in the examples and information to connect to the user's 
  8. # example database. The script quires the adaptorName and connection 
  9. # information and validates the connection information by attempting to
  10. # connect to the database before actually reconfiguring the model files.
  11.  
  12. # Although the script will configure the model files without being able to 
  13. # connect to the database, it is preferable that a both the Movie and 
  14. # Rental databases are created before running this script. The tables and 
  15. # data can be loaded into the databases after running this script by 
  16. # executing the install_database program in the DatabaseSetUp directory. Of 
  17. # course, the data only needs to be installed once while the eoexamples may 
  18. # be installed several times by different users.
  19.  
  20. cat << FOOBAR
  21.  
  22. This script handles the configuration of the EOF 2.0 examples. The
  23. examples are designed to work with data managed by Informix, Oracle,
  24. Sybase, or any adaptor that is fully compliant with EOF 2.0. The
  25. script will ask the user which DBMS to use for the Movies data and
  26. the Rentals data. Based on the users response, the script will ask
  27. for the information necessary to connect with that DBMS.
  28.  
  29. We suggest that you allocate the necesary DBMS resources before
  30. installing the examples. For Sybase and Informix, this means
  31. creating two databases: one for the Movies data and one for the
  32. Rentals. For Oracle, this means creating two users.
  33.  
  34. This script prompts the user for information to connect to the DBMS
  35. for each of these two sets of data and attempts to ensure that the
  36. connection information is correct before setting that information in
  37. the EOModels used by the example applications.
  38.  
  39. When this script has finished executing, you can 'cd' to the
  40. 'DatabaseSetUp' directory and execute the install_database script.
  41. That script will create all of the tables and load the data necessary
  42. for the EOF 2.0 examples.
  43.  
  44. FOOBAR
  45.  
  46. #
  47. # Initialize variables
  48. #
  49. Usage="configure_examples  [-movie <adaptorName> <connectionDictionary>] [-rental <adaptorName> <connectionDictionary>]"
  50.  
  51. movieAdaptorName=
  52. movieConnectionDictionary=
  53. rentalAdaptorName=
  54. rentalConnectionDictionary=
  55.  
  56. #
  57. # NEXT_EOUTIL_PATH should only be set for debugging purposes by Next
  58. # Developers. Setting this environment variable in customer sites will
  59. # cause this script to fail.
  60. #
  61. masterDir=${NEXT_ROOT}/NextDeveloper/Examples/EnterpriseObjects
  62. EOUTIL=${NEXT_EOUTIL_PATH-${masterDir}/DatabaseSetUp/eoutil}
  63. export EOUTIL
  64. ECHO=echo
  65.  
  66. #
  67. # Get the current working directory and verify that we're in the right place
  68. #
  69. exepath=`echo $0`
  70. basename=`basename $exepath`
  71. currDir=`echo $exepath | sed -e s,$basename\$,, | sed -e s,/\$,,`
  72. if test ! -z "$currDir"; then
  73.     cd $currDir
  74. fi
  75. currDir=`pwd`
  76.  
  77. if test ! -d $currDir/Movie/Movies.eomodeld -o ! -w $currDir/Movie; then
  78.     echo ""
  79.     echo "You must be in the top directory of the *installed* examples in order"
  80.     echo "to run this script. Please cd to that directory and execute this script again."
  81.     exit 1
  82. fi
  83.  
  84. if test $"currDir" = $"masterDir"; then
  85.     echo ""
  86.     echo "Cannot drop data from $currDir. Please copy the examples and cd to"
  87.     echo "the copied directory and execute this script again."
  88.     exit 1
  89. fi
  90.  
  91. #
  92. # Loop through arguments and set initial values
  93. #
  94. while test $# -gt 0 ; do
  95.     case $1 in
  96.     -#)
  97.         set -x;;
  98.     -[mM]*)
  99.         shift; movieAdaptorName=$1;
  100.         shift; movieConnectionDictionary=$1;;
  101.     -[iI]*)
  102.         shift; rentalAdaptorName=$1;
  103.         shift; rentalConnectionDictionary=$1;;
  104.     *)
  105.         echo Unrecognized argument $1;
  106.         echo $Usage;
  107.         exit 1;;
  108.     esac
  109.     shift
  110. done    
  111.  
  112. echo -n "Hit the return key when ready to continue:"
  113. read response
  114.  
  115. #
  116. # Get connection information and adaptor name for each of the example
  117. # databases.
  118. #
  119. for example in Movie Rental ; do
  120.         if test "$example" = "Movie"; then
  121.             adaptorName=$movieAdaptorName
  122.             connectionDictionary=$movieConnectionDictionary
  123.         else
  124.             adaptorName=$rentalAdaptorName
  125.             connectionDictionary=$rentalConnectionDictionary
  126.         fi
  127.     
  128.         #
  129.         # Ask the user for the name of the adaptor to be used when connecting to
  130.         # the example database
  131.         #
  132.         while test -z "$adaptorName" ; do
  133.             echo ""
  134.             echo 'Enter the name of the adaptor to use when connecting to'
  135.             echo -n "the $example database (Oracle, Sybase, Informix, ODBC, FlatFile ...): "
  136.             read adaptorName
  137.         done
  138.     
  139.         #
  140.         # Make sure the case is used properly in the adaptor name, we can't do
  141.         # this for 3rd Party adaptors that we don't know about.
  142.         #
  143.         case $adaptorName in
  144.             [Oo][Rr][Aa][Cc][Ll][Ee]) adaptorName=Oracle;;
  145.             [Ss][Yy][Bb][Aa][Ss][Ee]) adaptorName=Sybase;;
  146.             [Ii][Nn][Ff][Oo][Rr][Mm][Ii][Xx]) adaptorName=Informix;;
  147.             [Ff][Ll][Aa][Tt][Fi][Ii][Ll][Ee]) adaptorName=FlatFile;;
  148.             [Oo][dD][Bb][Cc]) adaptorName=ODBC;;
  149.         esac
  150.     
  151.         #
  152.         # Based on the adaptor name, prompt the user to enter the necessary 
  153.         # information to connect to the Movie database and the Rental
  154.         # database.
  155.         #
  156.         while test -z "$connectionDictionary" ; do
  157.             case $adaptorName in
  158.             Oracle) words="serverId hostMachine userName password";;
  159.         Sybase) words="userName hostName databaseName password";;
  160.         Informix) words="dbName userName password";;
  161.         FlatFile) words="path";;
  162.             ODBC) words="dataSource userName password";;
  163.         *)  echo "You must enter a connectionDictionary argument when not"
  164.         echo "using one of the NeXT supplied adaptors."
  165.         echo "exiting ....."
  166.         exit 1;;
  167.             esac
  168.     
  169.             echo ""
  170.             echo ""
  171.             echo "Enter the connection information for the $adaptorName $example database"
  172.             connectionDictionary="{ "
  173.     
  174.             for i in $words ; do
  175.                 val=
  176.                 echo -n "Enter value for $i: "
  177.                 read val
  178.                 if test -z "$val"; then
  179.                     val=\"\"
  180.         else
  181.             val=`echo $val | sed -e 's/"/\\\"/'`
  182.             val=\"$val\"
  183.                 fi
  184.         
  185.         connectionDictionary=`echo $connectionDictionary | sed -e 's/"/\\"/g'`
  186.                 connectionDictionary="$connectionDictionary $i = $val;"
  187.             done
  188.     
  189.             connectionDictionary="$connectionDictionary }"
  190.     
  191.             echo ""
  192.             echo Please wait while I attempt to connect to database...
  193.             if eval ${EOUTIL} connect $adaptorName \'$connectionDictionary\'; then
  194.                 echo ""
  195.                 echo ""
  196.                 echo "Attempt to connect succeeded -- continuing with installation"
  197.             else
  198.                 echo -n "Attempt to connect with database failed do you want to reenter the connection dictionary? (y/n)"
  199.                 read response
  200.                 if test "$response" != "y" ; then
  201.                     echo -n "Continue with the installation without connecting to the database? (y/n)"
  202.                     read response
  203.                     if test "$response" != "y" ; then
  204.                         exit 1
  205.                     fi
  206.                 else
  207.                     connectionDictionary=
  208.                 fi
  209.             fi
  210.         done
  211.     
  212.         if test "$example" = "Movie"; then
  213.             movieAdaptorName=$adaptorName;
  214.             movieConnectionDictionary=$connectionDictionary
  215.         else
  216.             rentalAdaptorName=$adaptorName;
  217.             rentalConnectionDictionary=$connectionDictionary;
  218.         fi
  219. done
  220.     
  221. echo ""
  222. echo "Converting Movie model in $currDir/BusinessLogic to $movieAdaptorName model"
  223. cd $currDir/BusinessLogic
  224. eval ${EOUTIL} convert Movies.eomodeld $movieAdaptorName \'$movieConnectionDictionary\' tmp.eomodeld
  225. if test $? -eq 0; then
  226.     rm -rf Movies.eomodeld
  227.     mv tmp.eomodeld Movies.eomodeld
  228. else
  229. echo ""
  230.     echo "ERROR: an error occurred while attempting to convert model -- exiting"
  231. echo ""
  232. echo ""
  233.     exit 1
  234. fi
  235.  
  236. echo "Copying converted movie model into $currDir/Movie and $currDir/Studios"
  237.     rm -rf $currDir/Movie/Movies.eomodeld
  238.     cp -r Movies.eomodeld $currDir/Movie
  239.     rm -rf $currDir/Studios/Movies.eomodeld
  240.     cp -r Movies.eomodeld $currDir/Studios
  241.  
  242. echo ""
  243. echo "Converting Rental model in $currDir/BusinessLogic to $rentalAdaptorName model"
  244. cd $currDir/BusinessLogic
  245. eval ${EOUTIL} convert Rentals.eomodeld $rentalAdaptorName \'$rentalConnectionDictionary\' tmp.eomodeld
  246. if test $? -eq 0; then
  247.     rm -rf Rentals.eomodeld
  248.     mv tmp.eomodeld Rentals.eomodeld
  249. else
  250. echo ""
  251.     echo "ERROR: an error occurred while attempting to convert model -- exiting"
  252. echo ""
  253. echo ""
  254.     exit 1
  255. fi
  256.  
  257. echo ""
  258. echo "Finished configuring eoexamples."
  259. echo Do "make all" to build everything.
  260.  
  261.