[Dbconfig-common-changes] dbconfig-common/internal common, 1.5,
1.5.2.1 oracle, NONE, 1.1.2.1
xerakko-guest at haydn.debian.org
xerakko-guest at haydn.debian.org
Fri Dec 30 09:57:48 CET 2005
- Previous message: [Dbconfig-common-changes] dbconfig-common/debian/po ca.po, 1.11,
1.11.2.1 cs.po, 1.13, 1.13.2.1 da.po, 1.18, 1.18.2.1 de.po,
1.25, 1.25.2.1 es.po, 1.14, 1.14.2.1 eu.po, 1.15,
1.15.2.1 fr.po, 1.21, 1.21.2.1 it.po, 1.27, 1.27.2.1 nl.po,
1.16, 1.16.2.1 pt.po, 1.16, 1.16.2.1 pt_BR.po, 1.13,
1.13.2.1 sv.po, 1.2, 1.2.2.1 templates.pot, 1.21,
1.21.2.1 vi.po, 1.13, 1.13.2.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Update of /cvsroot/dbconfig-common/dbconfig-common/internal
In directory haydn:/tmp/cvs-serv5136/internal
Modified Files:
Tag: ORACLE
common
Added Files:
Tag: ORACLE
oracle
Log Message:
more files for initial support for oracle
Index: common
===================================================================
RCS file: /cvsroot/dbconfig-common/dbconfig-common/internal/common,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -d -r1.5 -r1.5.2.1
--- common 18 May 2005 19:49:38 -0000 1.5
+++ common 30 Dec 2005 08:57:42 -0000 1.5.2.1
@@ -166,6 +166,31 @@
return 1
fi
;;
+ "dbca")
+ if ! which dbca >/dev/null; then
+ dbc_error="No dbca to execute. (have
+ you installed oracle?"
+ dbc_logline "sanity check failed for dbca"
+ return 1
+ fi
+ ;;
+ "sqlplus")
+ if ! which sqlplus >/dev/null; then
+ dbc_error="No sqlplus to execute. (have
+ you installed oracle?"
+ dbc_logline "sanity check failed for sqlplus"
+ return 1
+ fi
+ ;;
+
+ "exp")
+ if ! which exp >/dev/null; then
+ dbc_error="No exp to execute. (have
+ you installed oracle?"
+ dbc_logline "sanity check failed for exp"
+ return 1
+ fi
+ ;;
*)
dbc_error="don't know how to sanity check for $1"
dbc_logline "don't know how to sanity check for $1"
--- NEW FILE: oracle ---
###
### postgresql bindings for dbconfig-common
###
### all variables and functions fall under the namespace "dbc_foo" and
### "_dbc_foo", depending on whether or not they are "external"
###
# get some common functions
. /usr/share/dbconfig-common/internal/common
# _dbc_oracle_local_username(){
# echo $dbc_dbadmin
# }
_dbc_oracle_connect_username(){
# determine proper remote user for connection requests
# - if _dbc_asuser set: $dbc_dbuser
# - else: $dbc_dbadmin
if [ "$_dbc_asuser" ]; then
echo $dbc_dbuser
else
echo "sys"
fi
}
_dbc_oracle_environment(){
local oenv
#oenv="ORACLE_BASE=/home/oracle/oracle"
oenv="ORACLE_SID=$dbc_dbname"
oenv="$oenv ORACLE_HOME=$dbc_oracle_home"
oenv="$oenv LD_LIBRARY_PATH=$dbc_oracle_home/lib"
oenv="$oenv DISABLE_HUGETLBFS=1"
oenv="$oenv PATH=$PATH:$dbc_oracle_home/bin"
oenv="$oenv TEMP=/tmp"
oenv="$oenv TMP=/tmp"
echo $oenv
}
_dbc_sqlplus(){
local oenv ouser opass extra extra2
oenv=`_dbc_oracle_environment`
if [ ! "$ouser" ]; then
ouser=`_dbc_oracle_connect_username`
fi
if [ "$ouser" != "sys" ]; then
opass="$dbc_dbpass"
else
opass="$dbc_sys_pass"
fi
extra2="$ouser/$opass"
#if [ "$dbc_dbserver" ]; then
# extra="$ouser/$opass@$dbc_dbname.$dbc_dbserver $extra"
#else
# extra="$ouser/$opass@$dbc_dbname $extra"
#fi
if [ "$ouser" = "sys" ]; then
extra2="$extra2 as sysdba"
fi
extra="$extra2 $extra"
retval=0
dbc_error=`su -s /bin/sh $dbc_dbadmin -c "env $oenv sqlplus -S $extra $*" 2>&1 `|| retval=$?
return $retval
}
_dbc_dbca_createdb(){
local retval localuser _dbc_asuser extra
localuser=`_dbc_oracle_connect_username`
oenv=`_dbc_oracle_environment`
retval=0
extra="$extra -createDatabase -templateName $dbc_database_template.dbc"
if [ "$dbc_dbserver" ]; then
extra="$extra -gdbName $dbc_dbname.$dbc_dbserver -sid $dbc_dbname.$dbc_dbserver"
else
extra="$extra -gdbName $dbc_dbname -sid $dbc_dbname"
fi
extra="$extra -sysPassword $dbc_sys_pass -systemPassword $dbc_system_pass -silent"
dbc_error=`su -s /bin/sh $dbc_dbadmin -c "env $oenv dbca $extra " 2>&1` || retval=$?
return $retval
}
_dbc_dbca_dropdb(){
local extra retval localuser _dbc_asuser
localuser=`_dbc_oracle_connect_username`
oenv=`_dbc_oracle_environment`
retval=0
extra="$extra -deleteDatabase"
if [ "$dbc_dbserver" ]; then
extra="$extra -sourceDB $dbc_dbname.$dbc_dbserver -silent"
else
extra="$extra -sourceDB $dbc_dbname -silent"
fi
dbc_error=`su -s /bin/sh $dbc_dbadmin -c "env $oenv dbca $extra" 2>&1` || retval=$?
return $retval
}
_dbc_createuser(){
local extra retval localuser _dbc_asuser ouser l_sqlfile l_auth
ouser=`_dbc_oracle_connect_username`
l_sqlfile=`mktemp -t dbconfig-common_sqlfile.XXXXXX`
chown $dbc_dbadmin $l_sqlfile
if [ "$dbc_authmethod_app_user" = "local" ]; then
l_auth=" by $dbc_dbpass"
fi
if [ "$dbc_authmethod_app_user" = "external" ]; then
l_auth="externally"
fi
# incomplet
#if [ "$dbc_authmethod_app_user" = "global" ]; then
# l_auth=" globally as by $dbc_dbpass"
#fi
cat << EOF > $l_sqlfile
CREATE USER $dbc_dbuser IDENTIFIED $l_auth;
GRANT CONNECT,RESOURCE TO $dbc_dbuser;
ALTER USER $dbc_dbuser ACCOUNT unlock;
QUIT
EOF
dbc_oracle_exec_file "$l_sqlfile"
retval=$?
return $retval
}
_dbc_reset_pwd_user(){
local extra retval localuser _dbc_asuser ouser l_sqlfile l_auth
localuser=`_dbc_oracle_connect_username`
l_sqlfile=`mktemp -t dbconfig-common_sqlfile.XXXXXX`
chown $dbc_dbadmin $l_sqlfile
if [ "$dbc_authmethod_app_user" = "local" ]; then
l_auth=" by $dbc_dbpass"
fi
if [ "$dbc_authmethod_app_user" = "external" ]; then
l_auth="externally"
fi
# incomplet
#if [ "$dbc_authmethod_app_user" = "global" ]; then
# l_auth=" globally as by $dbc_dbpass"
#fi
cat << EOF > $l_sqlfile
GRANT CONNECT,RESOURCE TO $dbc_dbuser;
ALTER USER $dbc_dbuser ACCOUNT unlock;
QUIT
EOF
dbc_oracle_exec_file "$l_sqlfile"
retval=$?
return $retval
}
_dbc_dropuser(){
local extra retval localuser _dbc_asuser ouser l_sqlfile l_auth
localuser=`_dbc_oracle_connect_username`
l_sqlfile=`mktemp -t dbconfig-common_sqlfile.XXXXXX`
chown $dbc_dbadmin $l_sqlfile
if [ "$dbc_authmethod_app_user" = "local" ]; then
l_auth=" by $dbc_dbpass"
fi
if [ "$dbc_authmethod_app_user" = "external" ]; then
l_auth="externally"
fi
# incomplet
#if [ "$dbc_authmethod_app_user" = "global" ]; then
# l_auth=" globally as by $dbc_dbpass"
#fi
cat << EOF > $l_sqlfile
DROP USER $localuser ;
quit
EOF
dbc_oracle_exec_file "$l_sqlfile"
retval=$?
return $retval
}
_dbc_oracle_dump(){
local oenv ouser opass extra dump_file
oenv=`_dbc_oracle_environment`
dump_file=`mktemp -t dbconfig-common_dump_sqlfile.XXXXXX`
chown $dbc_dbadmin $dump_file
dbc_error=`su -s /bin/sh $dbc_dbadmin -c "env $oenv exp userid=system/$dbc_system_pass full=y inctype=complete constraints=Y file=$dump_file $extra" 2>&1` || retval=$?
return $retval
}
##
## check that we can actually connect to the specified oracle listener
##
_dbc_oracle_check_connect(){
local oenv extra _dbc_asuser
oenv=`_dbc_oracle_environment`
if [ "$dbc_dbserver" ]; then
extra="$dbc_dbserver $extra"
else
extra="127.0.0.1 $extra"
fi
dbc_error=`su -s /bin/sh $dbc_dbadmin -c "env $oenv tnsping $extra" 2>&1`
retval=$?
if [ "$retval" != "0" ]; then
dbc_logline "unable to connect to oracle listener"
fi
return $retval
}
##
## execute a file with oracle commands
##
## note this is done without passing any sensitive info on the cmdline
##
dbc_oracle_exec_file(){
local l_sqlfile retval s_sqlfile
s_sqlfile=$1
l_sqlfile=`mktemp -t dbconfig-common_ec_sqlfile.XXXXXX`
cat $s_sqlfile > $l_sqlfile
echo quit >> $l_sqlfile
chown $dbc_dbadmin $l_sqlfile
cat $l_sqlfile >> /tmp/executat
echo ===== >> /tmp/executat
if [ ! "$l_sqlfile" ]; then
dbc_error="no file supplied to execute"
dbc_log="no file supplied to execute"
return 1
fi
_dbc_sqlplus "@$l_sqlfile"
retval=$?
return $retval
}
##
## execute a specific oracle command
##
## note this is done without passing any sensitive info on the cmdline,
## including the sql command itself
##
_dbc_oracle_exec_command(){
local statement l_sqlfile retval ouser localuser
ouser=`_dbc_oracle_connect_username`
statement=$@
l_sqlfile=`mktemp -t dbconfig-common_ec_sqlfile.XXXXXX`
chown $dbc_dbadmin $l_sqlfile
cat << EOF > $l_sqlfile
$statement
quit
EOF
cat $l_sqlfile >>/tmp/executat
echo ======== >>/tmp/executat
ouser="$ouser" extra="$extra" _dbc_sqlplus "@$l_sqlfile" || retval=$?
rm -f $l_sqlfile
return $retval
}
##
## check for the existance of a specified database
##
_dbc_oracle_check_database(){
local dbc_dbname _dbc_asuser retval
retval=1
dbc_dbname=$1
for i in `cat /etc/oratab|grep -v '#'| grep '\w' | cut -f1 -d':'` ; do
if [ "$i" = "$dbc_dbname" ]; then
retval=0
fi
done
return $retval
}
##
## check for access for a specific user
##
## this works by checking the grants for the user, so we can verify that
## not only does the user exist, but that it should be able to connect
##
dbc_oracle_check_user(){
local l_retval _dbc_asuser ouser
ouser="$dbc_dbuser" _dbc_oracle_exec_command "quit"
l_retval=$?
return $l_retval
}
###
### externally supplied functions
###
### included inline are some slightly modified / corrected comments from
### the respective original functions provided by wwwconfig-common, and
### comments of similar style for now functions
###
### all functions return non-zero on error
###
# File: pgsql-createdb.sh
# Description: Creates a database.
# Needs: $dbc_dbname
# $dbc_dbadmin
# Sets: $dbc_status = {error, nothing, create}
# $dbc_error = error message (if $dbc_status = error)
dbc_oracle_createdb(){
dbc_status=error
_dbc_sanity_check dbname dbadmin dbuser createdb || return 1
_dbc_oracle_check_connect || return 1
dbc_logpart "creating database $dbc_dbname:"
if _dbc_oracle_check_database "$dbc_dbname"; then
dbc_logline "already exists"
dbc_status=nothing
else
if _dbc_dbca_createdb $dbc_dbname ; then
dbc_logline "success"
dbc_logpart "verifying database $dbc_dbname exists:"
if ! _dbc_oracle_check_database "$dbc_dbname"; then
dbc_logline "failed"
else
dbc_status=create
dbc_logline "success"
fi
else
dbc_logline "failed"
fi
fi
}
# File: pgsql-dropdb.sh
# Needs: $dbc_dbname - the database that user should have access to.
# $dbc_dbserver - the server to connect to.
# $dbc_dbadmin - the administrator name.
# $dbc_dbadmpass - the administrator password.
# Description: drops a database.
# Sets: $dbc_status = {error, nothing, drop}
# $dbc_error = error message (if dbc_status = error).
dbc_oracle_dropdb(){
dbc_status=error
_dbc_sanity_check dbname dbadmin dropdb || return 1
_dbc_oracle_check_connect || return 1
dbc_logpart "dropping database $dbc_dbname:"
if _dbc_oracle_check_database "$dbc_dbname"; then
if _dbc_dbca_dropdb "$dbc_dbname"; then
dbc_logline "success"
dbc_logpart "verifying database $dbc_dbname was dropped:"
if _dbc_oracle_check_database "$dbc_dbname"; then
dbc_logline "failed"
else
dbc_logline "success"
dbc_status=drop
fi
else
dbc_logline "does not exist"
fi
else
dbc_status=nothing
dbc_logline "database does not exist"
fi
}
# File: pgsql-createuser.sh
# Description: Creates or replaces a database user.
# Needs: $dbc_dbuser - the user name to create (or replace).
# $dbc_dballow - what hosts to allow. defaults to localhost/hostname
# $dbc_dbname - the database that user should have access to.
# $dbc_dbpass - the password to use.
# $dbc_dbserver - the server to connect to (defaults to localhost).
# $dbc_dbadmin - the administrator name.
# $dbc_dbadmpass - the administrator password.
# Sets: $dbc_status = {error, create, nothing}
# $dbc_error = error message (if $dbc_status = error)
dbc_oracle_createuser(){
local l_dballow valid_user
dbc_status=error
_dbc_sanity_check dbuser dbadmin createuser || return 1
_dbc_oracle_check_connect || return 1
dbc_logpart "creating oracle user $dbc_dbuser: "
ouser="$dbc_dbuser" dbc_oracle_check_user
valid_user=$?
if $valid_user; then
dbc_status=nothing
dbc_logline "already exists"
if [ "$dbc_dbpass" ]; then
dbc_logpart "resetting password: "
if _dbc_reset_pwd_user; then
dbc_logline "success"
else
dbc_logline "failed"
return 1
fi
fi
elif _dbc_createuser; then
dbc_logline "success"
dbc_logpart "verifying creation of user:"
if ! dbc_oracle_check_user ; then
dbc_logline "failed"
return 1
else
dbc_status=create
dbc_logline "success"
fi
else
dbc_logline "failed"
return 1
fi
}
# File: pgsql-dropuser.sh
# Needs: $dbc_dbuser - the user name to create (or replace).
# $dbc_dballow - what hosts to allow (defaults to %).
# $dbc_dbname - the database that user should have access to.
# $dbc_dbserver - the server to connect to.
# $dbc_dbadmin - the administrator name.
# $dbc_dbadmpass - the administrator password.
# Description: drops a database user.
# Sets: $dbc_status = {error, nothing, drop }
# $dbc_error = error message (if dbc_status = error).
dbc_oracle_dropuser(){
local l_dballow
dbc_status=error
_dbc_sanity_check dbuser dbname dbadmin dropuser || return 1
_dbc_oracle_check_connect || return 1
dbc_logpart "revoking access to database $dbc_dbname $dbc_dbuser:"
if ! dbc_oracle_check_user; then
dbc_status="nothing"
dbc_logline "access does not exist"
else
if _dbc_dropuser $dbc_dbuser 2>/dev/null; then
dbc_status=drop
dbc_logline "success"
else
dbc_logline "failed"
fi
fi
}
##
## perform oracle_dump
##
dbc_oracle_dump(){
local dump_file localuser
_dbc_sanity_check dbuser dbname dbadmin || return 1
_dbc_oracle_check_connect || return 1
localuser=`_dbc_oracle_connect_username`
dump_file=`mktemp -t dbconfig-common_oracle_dump.XXXXXX`
chown $dbc_dbadmin $dump_file
_dbc_oracle_dump $dump_file
cat $dump_file
rm -f $dump_file
}
# To create users, the database instance must be up.
dbc_oracle_startupdb(){
local extra retval _dbc_asuser ouser
s_sqlfile=`mktemp -t dbconfig-common_startupdb.XXXXXX`
chown $dbc_dbadmin $s_sqlfile
cat << EOF > $s_sqlfile
STARTUP
QUIT
EOF
ouser="sys" dbc_oracle_exec_file "$s_sqlfile"
retval=$?
extra=""
return $retval
}
- Previous message: [Dbconfig-common-changes] dbconfig-common/debian/po ca.po, 1.11,
1.11.2.1 cs.po, 1.13, 1.13.2.1 da.po, 1.18, 1.18.2.1 de.po,
1.25, 1.25.2.1 es.po, 1.14, 1.14.2.1 eu.po, 1.15,
1.15.2.1 fr.po, 1.21, 1.21.2.1 it.po, 1.27, 1.27.2.1 nl.po,
1.16, 1.16.2.1 pt.po, 1.16, 1.16.2.1 pt_BR.po, 1.13,
1.13.2.1 sv.po, 1.2, 1.2.2.1 templates.pot, 1.21,
1.21.2.1 vi.po, 1.13, 1.13.2.1
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the Dbconfig-common-changes
mailing list