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

Sean Finney seanius at alioth.debian.org
Mon Jun 18 20:21:38 UTC 2007


Author: seanius
Date: 2007-06-18 20:21:38 +0000 (Mon, 18 Jun 2007)
New Revision: 405

Modified:
   trunk/debian/changelog
   trunk/debian/dbconfig-common.templates
   trunk/dpkg/common
   trunk/dpkg/postinst
   trunk/internal/mysql
   trunk/internal/pgsql
   trunk/internal/sqlite
Log:
first stab at better handling of when the database package needed
for configuration isn't installed


Modified: trunk/debian/changelog
===================================================================
--- trunk/debian/changelog	2007-06-18 16:15:27 UTC (rev 404)
+++ trunk/debian/changelog	2007-06-18 20:21:38 UTC (rev 405)
@@ -3,6 +3,8 @@
   * New Mayalalam debconf translations from Praveen A (closes: #426220).
   * Updated Vietnamese debconf translations from Clytie Siddall 
     (closes: #426841).
+  * initial attempt at handling more gracefully situations where a
+    database was not installed before the package was installed
 
  -- sean finney <seanius at debian.org>  Mon, 18 Jun 2007 18:15:29 +0100
 

Modified: trunk/debian/dbconfig-common.templates
===================================================================
--- trunk/debian/dbconfig-common.templates	2007-06-18 16:15:27 UTC (rev 404)
+++ trunk/debian/dbconfig-common.templates	2007-06-18 20:21:38 UTC (rev 405)
@@ -194,6 +194,21 @@
  fail and you will need to downgrade, reinstall, reconfigure this package,
  or otherwise manually intervene to continue using it.
 
+Template: dbconfig-common/missing-db-package-error
+Type: select
+__Choices: abort, retry, ignore
+Default: abort
+_Description: Database package required.
+ To properly configure the database for ${pkg}, it is necessary
+ that you also have ${dbpackage} installed.  Unfortunately, this can
+ not be done automatically.
+ .
+ If in doubt, you should choose "abort", and install ${dbpackage} before
+ continuing with the configuration of this package.  If you choose "retry",
+ you will be allowed to choose different answers (in case you chose the
+ wrong database type by mistake).  If you choose "ignore", then installation
+ will continue as normal.
+
 Template: dbconfig-common/remote/host
 Type: select
 Choices: ${hosts}

Modified: trunk/dpkg/common
===================================================================
--- trunk/dpkg/common	2007-06-18 16:15:27 UTC (rev 404)
+++ trunk/dpkg/common	2007-06-18 20:21:38 UTC (rev 405)
@@ -31,7 +31,7 @@
 	### some internal variables
 	###
 	# templates common to all database types
-	dbc_standard_templates="database-type dbconfig-install dbconfig-upgrade dbconfig-remove dbconfig-reinstall password-confirm app-password-confirm purge upgrade-backup passwords-do-not-match install-error upgrade-error remove-error internal/reconfiguring internal/skip-preseed"
+	dbc_standard_templates="database-type dbconfig-install dbconfig-upgrade dbconfig-remove dbconfig-reinstall password-confirm app-password-confirm purge upgrade-backup passwords-do-not-match install-error upgrade-error remove-error internal/reconfiguring internal/skip-preseed missing-db-package-error"
 
 	# templates common to mysql database types
 	dbc_mysql_templates="mysql/method remote/host remote/newhost mysql/app-pass mysql/admin-user mysql/admin-pass remote/port db/dbname db/app-user"
@@ -85,6 +85,7 @@
 	dbc_default_basepath=""
 
 	# now set some variables based on the dbtype
+	dbc_db_installed_cmd="dbc_${dbc_dbtype}_db_installed"
 	case $dbc_dbtype in
 	mysql)
 		. /usr/share/dbconfig-common/internal/mysql
@@ -100,6 +101,7 @@
 		dbc_default_admin="root"
 		dbc_default_dbuser=`echo $dbc_package | tr -d +. | cut -c -16`;
 		dbc_dbvendor="MySQL"
+		dbc_dbpackage="mysql-server"
 	;;
 	pgsql)
 		. /usr/share/dbconfig-common/internal/pgsql
@@ -116,6 +118,7 @@
 		dbc_default_dbuser=`echo $dbc_package | tr -d +-.`;
 		dbc_use_dbuser="false"
 		dbc_dbvendor="PostgreSQL"
+		dbc_dbpackage="postgresql"
 	;;
 	sqlite|sqlite3)
 		. /usr/share/dbconfig-common/internal/sqlite
@@ -134,6 +137,7 @@
 		dbc_use_dbuser="false"
 		dbc_dbvendor="SQLite"
 		dbc_sqlite_cmd="/usr/bin/$dbc_dbtype"
+		dbc_dbpackage="$dbc_dbtype"
 	;;
 	*)
 		dbc_register_templates="$dbc_standard_templates $dbc_mysql_templates $dbc_pgsql_templates $dbc_sqlite_templates"
@@ -519,7 +523,53 @@
 	fi
 }
 
+
+dbc_abort(){
+	# forget that we've seen all the debconf questions
+	for f in $dbc_register_templates; do
+		db_fset $dbc_package/$f seen false
+	done
+
+	echo "dbconfig-common: $dbc_package $dbc_command: aborted." >&2
+	dbc_postinst_cleanup
+	return 1
+}
+
+
 ##
+## what to do if mysql-server etc are not installed
+##
+dbc_missing_db_package_error(){
+	local question
+	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_input critical $question || true
+	db_go || true
+	db_get $question
+	_dbc_on_error_option="$RET"
+	
+	if [ "$_dbc_on_error_option" = "abort" ]; then
+		dbc_abort
+	fi
+	
+	if [ "$_dbc_on_error_option" = "retry" ]; then
+		# forget that we've seen all the debconf questions
+		for f in $dbc_register_templates; do
+			db_fset $dbc_package/$f seen false
+		done
+		
+		echo "dbconfig-common: $dbc_package $dbc_command: trying again." >&2
+                . /usr/share/dbconfig-common/dpkg/config
+                dbc_go $dbc_package configure $dbc_oldversion
+                . /usr/share/dbconfig-common/dpkg/postinst
+		dbc_go $dbc_package $dbc_command $dbc_oldversion 
+		dbc_tried_again="yes"
+	fi
+}
+
+##
 ## what to do when something goes wrong during install
 ##
 dbc_install_error(){
@@ -536,14 +586,7 @@
 	_dbc_on_error_option="$RET"
 	
 	if [ "$_dbc_on_error_option" = "abort" ]; then
-		# forget that we've seen all the debconf questions
-		for f in $dbc_register_templates; do
-			db_fset $dbc_package/$f seen false
-		done
-		
-		echo "dbconfig-common: $dbc_package $dbc_command: aborted." >&2
-		dbc_postinst_cleanup
-		return 1
+		dbc_abort
 	fi
 	
 	if [ "$_dbc_on_error_option" = "retry" ]; then
@@ -603,13 +646,7 @@
         _dbc_on_error_option="$RET"
 
         if [ "$_dbc_on_error_option" = "abort" ]; then
-        	# forget that we've seen all the debconf questions
-        	for f in $dbc_register_templates; do
-               		db_fset $dbc_package/$f seen false
-        	done
-		echo "dbconfig-common: $dbc_package $dbc_command: aborted." >&2
-		dbc_postinst_cleanup
-		return 1
+			dbc_abort
         fi
 
         if [ "$_dbc_on_error_option" = "retry" ]; then
@@ -648,27 +685,21 @@
         _dbc_on_error_option="$RET"
 
 	if [ "$_dbc_on_error_option" = "abort" ]; then
-        	# forget that we've seen all the debconf questions
-        	for f in $dbc_register_templates; do
-               		db_fset $dbc_package/$f seen false
-        	done
-		echo "dbconfig-common: $dbc_package $dbc_command: aborted." >&2
-		dbc_postinst_cleanup
-		return 1
-        fi
+		dbc_abort
+	fi
 
-        if [ "$_dbc_on_error_option" = "retry" ]; then
-        	# forget that we've seen all the debconf questions
-        	for f in $dbc_register_templates; do
-               		db_fset $dbc_package/$f seen false
-        	done
+	if [ "$_dbc_on_error_option" = "retry" ]; then
+		# forget that we've seen all the debconf questions
+		for f in $dbc_register_templates; do
+			db_fset $dbc_package/$f seen false
+		done
 		echo "dbconfig-common: $dbc_package $dbc_command: retrying." >&2
 		. /usr/share/dbconfig-common/dpkg/config
 		dbc_go $dbc_package configure $dbc_oldversion
 		. /usr/share/dbconfig-common/dpkg/postinst
 		dbc_go $dbc_package $dbc_command $dbc_oldversion
 		dbc_tried_again="yes"
-        fi
+	fi
 }
 
 ##

Modified: trunk/dpkg/postinst
===================================================================
--- trunk/dpkg/postinst	2007-06-18 16:15:27 UTC (rev 404)
+++ trunk/dpkg/postinst	2007-06-18 20:21:38 UTC (rev 405)
@@ -62,6 +62,13 @@
 		# don't perform the following block of code during upgrades
 		if [ ! "$upgrading" ]; then
 			###
+			### first things first, see if the database package is installed,
+			### and in case of failure provide a more sensible error message.
+			###
+			$dbc_db_installed_cmd || dbc_missing_db_package_error
+			[ "$dbc_tried_again" ] && return 0
+
+			###
 			### now, create the app user account
 			###
 			$dbc_createuser_cmd || dbc_install_error "creating user"

Modified: trunk/internal/mysql
===================================================================
--- trunk/internal/mysql	2007-06-18 16:15:27 UTC (rev 404)
+++ trunk/internal/mysql	2007-06-18 20:21:38 UTC (rev 405)
@@ -51,7 +51,7 @@
 	dbc_error=`mysql --defaults-extra-file="$mycnf" </dev/null 2>&1` && constat=good
 	rm -f $mycnf
 	if [ "$constat" = "bad" ]; then
-		dbc_logline="unable to connect to mysql server"
+		dbc_logline "unable to connect to mysql server"
 		return 1
 	fi
 }
@@ -151,16 +151,8 @@
 ###	all functions return non-zero on error
 ###
 
-# File:         mysql-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_mysql_createdb(){
 	local ret l_dbname _dbc_nodb
-	dbc_status=error
 
 	_dbc_sanity_check dbname dbadmin mysql || return 1
 	_dbc_mysql_check_connect || return 1
@@ -169,7 +161,6 @@
 
 	if _dbc_mysql_check_database "$dbc_dbname"; then
 		dbc_logline "already exists"
-		dbc_status=nothing
 	else
 		_dbc_nodb="yes" dbc_mysql_exec_command "CREATE DATABASE $dbc_dbname"
 		ret=$?
@@ -181,7 +172,6 @@
 				dbc_logline "failed"
 			else
 				dbc_logline "success"
-				dbc_status=create
 			fi
 		else
 			dbc_logline "failed"
@@ -195,12 +185,8 @@
 #		$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_mysql_dropdb(){
-	dbc_status=error
-
 	_dbc_sanity_check dbname dbadmin mysql || return 1
 	_dbc_mysql_check_connect || return 1
 
@@ -214,13 +200,11 @@
 				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
 }
@@ -234,14 +218,10 @@
 #		$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_mysql_createuser(){
 	local l_dballow l_sqlfile l_dbname l_ret
 
-	dbc_status=error
-
 	_dbc_sanity_check dbuser dbname dbadmin mysql || return 1
 	_dbc_mysql_check_connect || return 1
 
@@ -265,7 +245,6 @@
 FLUSH PRIVILEGES;
 EOF
 	if dbc_mysql_check_user; then
-		dbc_status=nothing
 		dbc_logline "already exists"
 	else
 		l_dbname=$dbc_dbname
@@ -280,7 +259,6 @@
 				l_ret=1
 				dbc_logline "failed"
 			else
-				dbc_status=create
 				dbc_logline "success"
 			fi
 		else
@@ -299,14 +277,10 @@
 #		$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_mysql_dropuser(){
 	local l_sqlfile l_dballow
 
-	dbc_status=error
-
 	_dbc_sanity_check dbuser dbname dbadmin mysql || return 1
 	_dbc_mysql_check_connect || return 1
 
@@ -322,7 +296,6 @@
 
 	dbc_logpart "revoking access to database $dbc_dbname from $dbc_dbuser@$l_dballow:"
 	if ! dbc_mysql_check_user; then
-		dbc_status="nothing"
 		dbc_logline "access does not exist"
 	else
 		l_sqlfile=`mktemp -t dbconfig-common.sql.XXXXXX`
@@ -333,7 +306,6 @@
 FLUSH PRIVILEGES;
 EOF
 		if _dbc_nodb="yes" dbc_mysql_exec_file "$l_sqlfile" 2>/dev/null; then
-			dbc_status=drop
 			dbc_logline "success"
 		else
 			dbc_logline "failed"
@@ -358,6 +330,13 @@
 }
 
 ##
+## basic installation check
+##
+dbc_mysql_db_installed(){
+	which mysqld >/dev/null 2>&1
+}
+
+##
 ## dbc_mysql_escape_str: properly escape strings passed to mysql queries
 ##
 dbc_mysql_escape_str(){

Modified: trunk/internal/pgsql
===================================================================
--- trunk/internal/pgsql	2007-06-18 16:15:27 UTC (rev 404)
+++ trunk/internal/pgsql	2007-06-18 20:21:38 UTC (rev 405)
@@ -457,6 +457,13 @@
 }
 
 ##
+## basic installation check
+##
+dbc_pgsql_db_installed(){
+	test -n "`find /etc/init.d -name 'postgresql*'`"
+}
+
+##
 ## dbc_pgsql_escape_str: properly escape strings passed to pgsql queries
 ##
 dbc_pgsql_escape_str(){

Modified: trunk/internal/sqlite
===================================================================
--- trunk/internal/sqlite	2007-06-18 16:15:27 UTC (rev 404)
+++ trunk/internal/sqlite	2007-06-18 20:21:38 UTC (rev 405)
@@ -168,6 +168,17 @@
 }
 
 ##
+## basic installation check
+##
+dbc_sqlite_db_installed(){ 
+	which sqlite >/dev/null 2>&1 
+}
+
+dbc_sqlite3_db_installed(){ 
+	which sqlite3 >/dev/null 2>&1 
+}
+
+##
 ## dump a sqlite database 
 ##
 dbc_sqlite_dump(){




More information about the Dbconfig-common-changes mailing list