[Dbconfig-common-devel] dbconfig-common/internal pgsql,1.4,1.5

seanius@haydn.debian.org seanius@haydn.debian.org


Update of /cvsroot/dbconfig-common/dbconfig-common/internal
In directory haydn:/org/alioth.debian.org/chroot/home/users/seanius/tmp/cvs-serv5705/internal

Modified Files:
	pgsql 
Log Message:
  * various fixes for postgresql remote connections
  * don't allow empty admin passwords in pgsql, since they don't work anyway.
  * don't repeat asking for the admin password.


Index: pgsql
===================================================================
RCS file: /cvsroot/dbconfig-common/dbconfig-common/internal/pgsql,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pgsql	18 Apr 2005 03:48:42 -0000	1.4
+++ pgsql	1 May 2005 06:13:06 -0000	1.5
@@ -49,6 +49,7 @@
 	if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi
 	if [ "$dbc_dbserver" ]; then extra="$extra -h '$dbc_dbserver'"; fi
 	if [ "$dbc_dbport" ]; then extra="$extra -p '$dbc_dbport'"; fi
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
 	dbc_error=`su - postgres -c "env HOME='$_dbc_pgsql_tmpdir' PGSSLMODE='$PGSSLMODE' createdb -q -O $dbc_dbuser $extra $*" 2>&1` || retval=$?
 	_dbc_psql_cmd_cleanup
 	return $retval
@@ -62,6 +63,7 @@
 	if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi
 	if [ "$dbc_dbserver" ]; then extra="$extra -h '$dbc_dbserver'"; fi
 	if [ "$dbc_dbport" ]; then extra="$extra -p '$dbc_dbport'"; fi
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
 	dbc_error=`su - postgres -c "env HOME='$_dbc_pgsql_tmpdir' PGSSLMODE='$PGSSLMODE' dropdb -q $extra $*" 2>&1` || retval=$?
 	_dbc_psql_cmd_cleanup
 	return $retval
@@ -75,8 +77,9 @@
 	if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi
 	if [ "$dbc_dbserver" ]; then extra="$extra -h '$dbc_dbserver'"; fi
 	if [ "$dbc_dbport" ]; then extra="$extra -p '$dbc_dbport'"; fi
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
 	if [ "$dbc_authmethod_user" != "ident" ]; then 
-		dbc_dbname="template1" _dbc_pgsql_exec_command "CREATE USER \"$dbc_dbuser\" WITH PASSWORD '$dbc_dbpass'"
+		extra="$extra" dbc_dbname="template1" _dbc_pgsql_exec_command "CREATE USER \"$dbc_dbuser\" WITH PASSWORD '$dbc_dbpass'"
 		retval=$?
 	else
 		dbc_error=`su - postgres -c "env HOME='$_dbc_pgsql_tmpdir' PGSSLMODE='$PGSSLMODE' createuser -A -D -q $extra $dbc_dbuser" 2>&1` || retval=$?
@@ -93,6 +96,7 @@
 	if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi
 	if [ "$dbc_dbserver" ]; then extra="$extra -h '$dbc_dbserver'"; fi
 	if [ "$dbc_dbport" ]; then extra="$extra -p '$dbc_dbport'"; fi
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
 	dbc_error=`su - postgres -c "env HOME='$_dbc_pgsql_tmpdir' PGSSLMODE='$PGSSLMODE' dropuser -q $extra $*" 2>&1` || retval=$?
 	_dbc_psql_cmd_cleanup
 	return $retval
@@ -106,6 +110,7 @@
 	if [ "$dbc_ssl" ]; then PGSSLMODE="require"; fi
 	if [ "$dbc_dbserver" ]; then extra="$extra -h '$dbc_dbserver'"; fi
 	if [ "$dbc_dbport" ]; then extra="$extra -p '$dbc_dbport'"; fi
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
 	dbc_error=`su - postgres -c "env HOME='$_dbc_pgsql_tmpdir' PGSSLMODE='$PGSSLMODE' pg_dump $extra $*" 2>&1` || retval=$?
 	_dbc_psql_cmd_cleanup
 	return $retval
@@ -115,9 +120,10 @@
 ## check that we can actually connect to the specified postgres server
 ##
 _dbc_pgsql_check_connect(){
-	local constat
+	local constat extra
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
 	constat="bad"
-	if ! _dbc_psql template1 < /dev/null; then
+	if ! _dbc_psql $extra template1 < /dev/null; then
 		dbc_logline "unable to connect to postgresql server"
 		return 1
 	fi
@@ -138,7 +144,7 @@
 		return 1
 	fi
 
-	_dbc_psql $dbc_dbname < "$l_sqlfile"
+	_dbc_psql $extra $dbc_dbname < "$l_sqlfile"
 }
 
 ##
@@ -154,7 +160,7 @@
 	cat << EOF > $l_sqlfile
 $statement
 EOF
-	_dbc_psql $dbc_dbname < $l_sqlfile || retval=$?
+	_dbc_psql $extra $dbc_dbname < $l_sqlfile || retval=$?
 	rm -f $l_sqlfile
 	return $retval
 }
@@ -165,7 +171,8 @@
 _dbc_pgsql_check_database(){
 	local dbc_dbname
 	dbc_dbname=$1
-	_dbc_psql $dbc_dbname </dev/null 2>/dev/null
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
+	_dbc_psql $extra $dbc_dbname </dev/null 2>/dev/null
 	return $?
 }
 
@@ -177,7 +184,8 @@
 ##
 _dbc_pgsql_check_user(){
 	local dbc_dbname l_retval
-	dbc_dbname=template1 _dbc_pgsql_exec_command "ALTER USER \"$dbc_dbuser\""
+	if [ "$dbc_dbadmin" ]; then extra="$extra -U '$dbc_dbadmin'"; fi
+	extra="$extra" dbc_dbname=template1 _dbc_pgsql_exec_command "ALTER USER \"$dbc_dbuser\""
 	l_retval=$?
 	return $l_retval
 }