home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wsgatsam.zip / install / WSGWinstallDB.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  2003-02-24  |  3KB  |  96 lines

  1. #!/bin/sh
  2. #
  3. # Database Creation - IBM WebServices Gateway
  4. #
  5. # The arguments are:
  6. # "1: WebSphere AppServer Directory"
  7. # "2: DB2 instance owner ID"
  8.  
  9. #---- Function definitions
  10.  
  11. # Function to do cleanup on temporary files
  12. fCleanup()
  13. {
  14.   rm -f "${tmpDBScript}"
  15.   rm -f "${tmpSqlFile}"
  16. }
  17.  
  18. # A function to terminate the execution of the script due to an error.
  19. # Arguments may be supplied, which will each be printed to a new line on
  20. # standard error.
  21. fErrorExit()
  22. {
  23.   while [ $# -gt 0 ]; do
  24.     echo "$1" >&2
  25.     shift
  26.   done
  27.   echo >&2
  28.   echo 'The WebServices Gateway database has NOT been created.' >&2
  29.   echo >&2
  30.  
  31.   fCleanup
  32.  
  33.   exit 1
  34. }
  35.  
  36. #---- Start of script execution
  37.  
  38. cd `dirname "$0"`
  39.  
  40. progName=`basename "$0"`
  41. progDir=`pwd`
  42.  
  43. # Check we are the root user or things may not work
  44. userName=`id | sed 's/[^(]*(\([^)]*\).*/\1/'`
  45. [ "${userName}" = 'root' ] || fErrorExit \
  46.   "You must be the 'root' user to run ${progName}." \
  47.   "You are currently logged in as ${userName}."
  48.  
  49. # Test there are the correct number of arguments (extra args are ignored)
  50. [ $# -ge 2 ] || fErrorExit \
  51.   "${progName} requires the following arguments:" \
  52.   '  1: WebSphere AppServer Directory (no trailing /)' \
  53.   '  2: DB2 instance owner ID' \
  54.   "Example: ./${progName} /opt/WebSphere/AppServer db2inst1"
  55.  
  56. wasDir="$1"
  57. db2user="$2"
  58. logFile="${wasDir}/logs/WSGWinstallDB.log"
  59. tmpDir="${TMP:-/tmp}"
  60. dbScript='installDB.sh'
  61. dbName='wsgwdb'
  62. sqlFile='WSGWDB.sql'
  63. tmpDBScript="${tmpDir}/${dbScript}"
  64. tmpSqlFile="${tmpDir}/${sqlFile}"
  65.  
  66. # Test the WAS directory exists
  67. [ -d "${wasDir}" ] || fErrorExit \
  68.   'The directory specified for WebSphere AppServer does not exist:' \
  69.   "  ${wasDir}"
  70.  
  71. # Copy the script to be run and it's associated SQL file into a location
  72. # where it can be accessed by the DB2 userid
  73. cp -f "${progDir}/${dbScript}" "${tmpDBScript}"
  74. chmod a+rx "${tmpDBScript}"
  75. cp -f "${progDir}/${sqlFile}" "${tmpSqlFile}"
  76. chmod a+r "${tmpSqlFile}"
  77.  
  78. echo 'Creating the WebServices Gateway database. This may take some time...'
  79.  
  80. # Invoke the database creation script as the DB2 instance ID
  81. su - ${db2user} -c "${tmpDBScript} ${dbName} ${tmpSqlFile}" \
  82.   > "${logFile}" 2>&1 || fErrorExit \
  83.   'Database creation failed. Try looking at the WSGWInstallDB.log file in the' \
  84.   '/logs subdirectory of the WebSphere AppServer dir to diagnose the problem.'
  85.  
  86. # Just in case the exit status from the 'su -c' command isn't the exit status
  87. # of the specified command, check the output log for the success message
  88. (tail -1 "${logFile}" | grep '^WSGW database creation successful$') \
  89.   > /dev/null 2>&1 || fErrorExit \
  90.   'Database creation failed. Try looking at the WSGWInstallDB.log file in the' \
  91.   '/logs subdirectory of the WebSphere AppServer dir to diagnose the problem.'
  92.  
  93. echo 'The WebServices Gateway database has been successfully created.'
  94. fCleanup
  95. exit 0
  96.