[Dbconfig-common-changes] [dbconfig-common] r441 - in trunk: debian dpkg internal

Sean Finney seanius at alioth.debian.org
Thu Apr 10 17:00:23 UTC 2008


tags 448804 pending
thanks

Author: seanius
Date: 2008-04-10 17:00:23 +0000 (Thu, 10 Apr 2008)
New Revision: 441

Modified:
   trunk/debian/changelog
   trunk/dpkg/common
   trunk/dpkg/postinst
   trunk/internal/common
Log:
better db install status detection

Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2008-04-10 16:29:15 UTC (rev 440)
+++ trunk/debian/changelog	2008-04-10 17:00:23 UTC (rev 441)
@@ -6,6 +6,7 @@
     - fix for catching upgrade errors when calling dbc_dump (closes: #473026).
     - fix for empty dumps from postgres upgrades (closes: #473013).
     - fix for ucf/debconf/stdout redirection problems (closes: #435143).
+    - fix for db server/client installed status differences (closes: #448804).
   * centralize definition of dbc.log location
   * a test suite! now using shunit2 for unit tests, implemented some
     basic tests for logging as a proof-of-concept.

Modified: trunk/dpkg/common
===================================================================
--- trunk/dpkg/common	2008-04-10 16:29:15 UTC (rev 440)
+++ trunk/dpkg/common	2008-04-10 17:00:23 UTC (rev 441)
@@ -105,6 +105,7 @@
 		dbc_default_dbuser=`echo $dbc_package | tr -d +. | cut -c -16`;
 		dbc_dbvendor="MySQL"
 		dbc_dbpackage="mysql-server"
+		dbc_dbclientpackage="mysql-client"
 	;;
 	pgsql)
 		. /usr/share/dbconfig-common/internal/pgsql
@@ -122,6 +123,7 @@
 		dbc_use_dbuser="false"
 		dbc_dbvendor="PostgreSQL"
 		dbc_dbpackage="postgresql"
+		dbc_dbclientpackage="postgresql-client"
 	;;
 	sqlite|sqlite3)
 		. /usr/share/dbconfig-common/internal/sqlite
@@ -141,6 +143,7 @@
 		dbc_dbvendor="SQLite"
 		dbc_sqlite_cmd="/usr/bin/$dbc_dbtype"
 		dbc_dbpackage="$dbc_dbtype"
+		dbc_dbclientpackage="$dbc_dbtype"
 	;;
 	*)
 		dbc_register_templates="$dbc_standard_templates $dbc_mysql_templates $dbc_pgsql_templates $dbc_sqlite_templates"
@@ -549,7 +552,7 @@
 	echo "warning: database package not installed?" >&2
 	question="$dbc_package/missing-db-package-error"
 	db_fset $question seen false
-	db_subst $question dbpackage $dbc_dbpackage
+	db_subst $question dbpackage $1
 	db_input critical $question || true
 	db_go || true
 	db_get $question
@@ -856,26 +859,8 @@
 ## determine whether a db is installed on the system
 ##
 dbc_detect_installed_dbtype(){
-	local query_dbtype testfile
 	_dbc_debug "dbc_detect_installed_dbtype() $@"
-	query_dbtype=$1
-
-	# see if the dbtype is already installed.  this is not 100% accurate
-	case $query_dbtype in 
-	"mysql") testfile='/usr/bin/mysql'
-	;;
-	"pgsql") testfile='/usr/bin/psql'
-	;;
-	"sqlite") testfile='/usr/bin/sqlite'
-	;;
-	"sqlite3") testfile='/usr/bin/sqlite3'
-	;;
-	"")
-	;;
-	esac
-
-	[ "$testfile" ] && test -f $testfile && return 0
-	return 1
+	_dbc_detect_installed_dbtype $@
 }
 
 ###

Modified: trunk/dpkg/postinst
===================================================================
--- trunk/dpkg/postinst	2008-04-10 16:29:15 UTC (rev 440)
+++ trunk/dpkg/postinst	2008-04-10 17:00:23 UTC (rev 441)
@@ -62,13 +62,23 @@
 		# don't perform the following block of code during upgrades
 		if [ ! "$upgrading" ]; then
 			###
-			### first things first, see if the database package is installed,
+			### first things first, see if the database client package is installed,
 			### and in case of failure provide a more sensible error message.
 			###
-			$dbc_db_installed_cmd || dbc_missing_db_package_error
+			dbc_detect_installed_dbtype $dbc_dbtype || dbc_missing_db_package_error $dbc_dbclientpackage
 			[ "$dbc_tried_again" ] && return 0
 
 			###
+			### next, if we're connecting to a local database,
+			### see if the database server package is installed,
+			### and in case of failure provide a more sensible error message.
+			###
+			if [ "$dbc_method" = "unix socket" ]; then
+				$dbc_db_installed_cmd || dbc_missing_db_package_error $dbc_dbpackage
+				[ "$dbc_tried_again" ] && return 0
+			fi
+
+			###
 			### now, create the app user account
 			###
 			$dbc_createuser_cmd || dbc_install_error "creating user"

Modified: trunk/internal/common
===================================================================
--- trunk/internal/common	2008-04-10 16:29:15 UTC (rev 440)
+++ trunk/internal/common	2008-04-10 17:00:23 UTC (rev 441)
@@ -33,6 +33,39 @@
 }
 
 ##
+## internal check for an installed db client package
+##
+_dbc_detect_installed_dbtype(){
+	_dbc_debug "_dbc_detect_installed_dbtype() $@"
+	# see if the dbtype is already installed.  this is still not 100% accurate
+	case "$1" in
+	mysql)
+		if ! which mysql >/dev/null; then
+			return 1
+		fi
+	;;
+	pgsql|psql)
+		# if postgresql-client-common is installed without postgresql-client-8.x,
+		# psql --version will exit with an error
+		if ! which psql >/dev/null 2>&1 || \
+		   ! psql --version >/dev/null 2>&1; then
+			return 1
+		fi
+	;;
+	"sqlite"|"sqlite3")
+		if ! which $1 >/dev/null 2>&1; then
+			return 1
+		fi
+	;;
+	*)
+		dbc_logline "_dbc_detect_installed_dbtype() called for unknown dbtype $@"
+		return 1
+	;;
+	esac
+	return 0
+}
+
+##
 ## internal sanity check for certain important variables
 ##
 _dbc_sanity_check(){
@@ -99,26 +132,10 @@
 				return 1
 				fi
 				;;
-		"mysql")
-			if ! which mysql >/dev/null; then
-				dbc_error="No mysql client to execute.  (have
-					you installed mysql-client?"
-				dbc_logline "sanity check failed for mysql"
-				return 1
-			fi
-		;;
-		"psql")
-			if ! which psql >/dev/null; then
-				dbc_error="No psql client to execute.  (have
-				       you installed postgresql-client?"
-				dbc_logline "sanity check failed for psql"
-				return 1
-			fi
-		;;
-		"sqlite"|"sqlite3")
-			if ! which $1 >/dev/null; then
+		"mysql"|"psql"|"sqlite"|"sqlite3")
+			if ! _dbc_detect_installed_dbtype $1; then
 				dbc_error="No $1 client to execute.  (have
-				       you installed the $1 package?"
+				       you installed the ${dbc_dbclientpackage:-$1} package?"
 				dbc_logline "sanity check failed for $1"
 				return 1
 			fi




More information about the Dbconfig-common-changes mailing list