home *** CD-ROM | disk | FTP | other *** search
- #!/bin/csh -f
- # installsample
- #
- # pjs 5/8/90
- #
- # This script installs a 16M sample dataserver for use in running the DBLib
- # sample programs. The sample database includes the 'pubs' database and
- # enough space to create the 'test' database created by example2.c. This
- # script creates a server login with the user's UNIX login name and password
- # 'server_password' which is used by the samples. The user is granted all
- # permissions which is required for running the samples. The remote procedure
- # 'rpctest' used in example8.c is created in the database with the user as the
- # owner. The script assumes that you have set the SYBASE environment variable
- # to the sybase root directory and that is where the interfaces file is located.
- # This can be accomplished by running 'source /usr/sybase/SetVars' before running
- # installsample.
- #
- # Usage:
- # installsample <db_device_name> [<server_name>]
- #
- # where db_device_name is the full pathname for the database device to be
- # installed. We recommend that you name database devices with a .sdb extension.
- # The optional argument server_name is the name of the server when it is
- # started. The default for server_name is SYBASE.
- #
- # e.g. installsample ~/your_dir/dbs/practice_db.sdb PRACTICE
- # will install a 16M database device '~/your_dir/dbs/practice_db.sdb'
- # that has a login with your UNIX login name and password 'server_password'.
- # The script also starts a dataserver named PRACTICE for this device.
- #
- # Script internals:
- #
- # Arguments and environment variables used:
- # $1 - the full pathname for the database device
- # $2 - server name for server that's going to be started
- # $SYBASE - SYBASE root directory, interfaces file location
- # $DSLISTEN - server name in interfaces file that server "listens to"
- # $DSQUERY - server name in interfaces file that client "speaks to"
- #
- # Internal variables used:
- # $db_device - the full pathname for the database device
- # $user - user's database login name, user's UNIX login name
- # $server_name - server name for server that's going to be started
- # $error - error flag
- # $root - root directory
- # $startserver - path name for starserver script
- # $isql - path name for isql
- #
-
- #
- # Check to see that the SYBASE, DSLISTEN, and DSQUERY environment variables have
- # been set.
- #
- set error = 0
- if !($?SYBASE && $?DSLISTEN && $?DSQUERY) then
- set error = 1
- echo "installsample: Installation failed."
- echo " You must set the SYBASE, DSLISTEN, and DSQUERY environment variables"
- echo " before running installsample. You can most easily do this by running"
- echo " the command:"
- #
- # Use SYBASE path if it's set, else default to /usr/sybase for error messages.
- #
- if !($?SYBASE) then
- set SYBASE = /usr/sybase
- endif
- echo " source $SYBASE/scripts/SetVars"
- endif
-
- #
- # Check for database device.
- #
- if ($#argv < 1) then
- set error = 1
- echo ""
- echo "usage: installsample <database_device> [<server_name>]"
- echo " For complete instructions on using installsample,"
- echo " see $SYBASE/sample/dblibrary/README."
- endif
-
- #
- # Bailout if any errors at this point.
- #
- if ($error == 1) then
- exit 1
- endif
-
- #
- # Set db_device, server_name, and user.
- #
- set db_device = $1
- if ($#argv == 2) then
- set server_name = $2
- else
- set server_name = SYBASE
- endif
- set user = `whoami`
-
- #
- # Configuration
- #
- set root = $SYBASE
- set startserver = $root/install/startserver
- set isql = $root/bin/isql
- set installPubs = $root/scripts/installpubs
-
- #
- # Use startserver to build a database device with pathname $2 having
- # default size of 16M.
- #
- echo "Installing database device $db_device"
- echo "with database login $user..."
- echo ""
- echo "y\n" | $startserver -s$server_name -d$db_device
- if ($status == 1) then
- echo ""
- echo "installsample: Installation failed."
- echo " Could not start server '$server_name'."
- echo " See startserver error messages."
- exit 1
- endif
-
- #
- # Install the 'pubs' database.
- #
- echo ""
- echo "Installing the 'pubs' database..."
- $isql -Usa -P -S$server_name < $installPubs
-
- #
- # Create a database login with user name $user having password 'server_password'.
- #
- echo ""
- echo "Creating database login $user..."
- $isql -Usa -P -S$server_name << EOF
- sp_addlogin $user, server_password
- go
- sp_adduser $user
- go
- grant all to $user
- go
- exit
- EOF
-
- #
- # Create remote procedure 'rpctest' used by example8.c with $user as owner.
- #
- echo ""
- echo "Creating remote procedure 'rpctest'..."
- $isql -U$user -Pserver_password -S$server_name << EOF
- create procedure rpctest
- (@param1 int out,
- @param2 int out,
- @param3 int out,
- @param4 int)
- as
- begin
- select "rpctest is running."
- select @param1 = 11
- select @param2 = 22
- select @param3 = 33
- select @param1
-
- return 123
- end
- go
- exit
- EOF
-
- #
- # Parting message.
- #
- echo ""
- echo "Installation completed."
- echo " You can now run $SYBASE/sample/dblibrary/exam1-9"
- echo " or run isql using the command:"
- echo " $SYBASE/bin/isql -U$user -Pserver_password -S$server_name"
-
-