Hi,
Adding a few checks in the post{inst,rm} scripts would prevent
the package of failing to install.
Something like this:

 >is_mysql_running()
 >{
 >      if [ -f /usr/bin/mysql ]; then
 >              if [ "$(echo exit|LANG=C mysql -h ${mysql_server} -P 
 > ${mysql_port} -u${root_mysql} ${mysqlpwd} 2>&1|grep ^ERROR)" != "" ]; 
 >              then
 >                      echo "WARNING: Can't connect to MySQL.";
 >                      echo "Perhaps you might want to use it other host?";
 >              fi
 >      fi
 >}
[...]
 >      IMR=$(is_mysql_running)
 >      if [ "$IMR" != "" ]; then
 >          echo $IMR;
 >      else
 >          mysqlcmd="mysql -h ${mysql_server} -P ${mysql_port} -u${root_mysql} 
 > ${mysqlpwd}"
 >          if ${mysqlcmd} -B -e 'select user from user' mysql | grep -q 
 > "^mysqltop$"
 >          then
 >              echo "User already exists";
 >          else
 >              create_user
 >          fi
 >      fi

I believe this could work since you can might have you DB in another
computer and not running locally. Otherwise, mtop should depend on 
mysql-server.

Also, I added dbconfig-common as a dependency to manage the DB, but
can be removed to solve this particular bug.

Anyway, I attached the diff hoping that it will explain the idea better
than me :-)

Saludos,
Mauro

--
JID: [email protected] | http://lizaur.github.com/
2B82 A38D 1BA5 847A A74D 6C34 6AB7 9ED6 C8FD F9C1
diff -urNad mtop/mtop-0.6.6/debian/control mtop-modified/mtop-0.6.6/debian/control
--- mtop/mtop-0.6.6/debian/control	2010-09-07 01:07:54.000000000 +0000
+++ mtop-modified/mtop-0.6.6/debian/control	2010-09-07 00:41:16.000000000 +0000
@@ -8,7 +8,7 @@
 
 Package: mtop
 Architecture: all
-Depends: ${perl:Depends}, ${misc:Depends}, libcurses-perl, libdbd-mysql-perl, libnet-perl, mysql-client
+Depends: ${perl:Depends}, ${misc:Depends}, libcurses-perl, libdbd-mysql-perl, libnet-perl, mysql-client, dbconfig-common
 Recommends: mysql-server
 Description: MySQL terminal based query monitor
  mtop (MySQL top) monitors a MySQL database showing the queries which
diff -urNad mtop/mtop-0.6.6/debian/mtop.postinst mtop-modified/mtop-0.6.6/debian/mtop.postinst
--- mtop/mtop-0.6.6/debian/mtop.postinst	2010-09-07 01:07:54.000000000 +0000
+++ mtop-modified/mtop-0.6.6/debian/mtop.postinst	2010-09-07 01:05:13.000000000 +0000
@@ -5,6 +5,17 @@
 
 set -e
 
+is_mysql_running()
+{
+	if [ -f /usr/bin/mysql ]; then
+		if [ "$(echo exit|LANG=C mysql -h ${mysql_server} -P ${mysql_port} -u${root_mysql} ${mysqlpwd} 2>&1|grep ^ERROR)" != "" ]; 
+		then
+			echo "WARNING: Can't connect to MySQL.";
+			echo "Perhaps you might want to use it other host?";
+		fi
+	fi
+}
+
 get_config()
 {
 	db_get mtop/mysql_server
@@ -49,6 +60,10 @@
     configure)
 	# Source debconf library
 	. /usr/share/debconf/confmodule
+	. /usr/share/dbconfig-common/dpkg/postinst.mysql
+	if ! dbc_go mtop $@ ; then
+	    echo 'Automatic configuration using dbconfig-common failed!'
+	fi
 	db_version 2.0
 
 	get_config
@@ -56,12 +71,17 @@
 	if [ "$root_passwd" != 'none' ]; then
                 mysqlpwd="-p${root_passwd}"
         fi
-        mysqlcmd="mysql -h ${mysql_server} -P ${mysql_port} -u${root_mysql} ${mysqlpwd}"
-	if ${mysqlcmd} -B -e 'select user from user' mysql | grep -q "^mysqltop$"
-	then
-		echo "User already exists";
+	IMR=$(is_mysql_running)
+	if [ "$IMR" != "" ]; then
+	    echo $IMR;
 	else
+            mysqlcmd="mysql -h ${mysql_server} -P ${mysql_port} -u${root_mysql} ${mysqlpwd}"
+	    if ${mysqlcmd} -B -e 'select user from user' mysql | grep -q "^mysqltop$"
+	    then
+		echo "User already exists";
+	    else
 		create_user
+	    fi
 	fi
     ;;
 
diff -urNad mtop/mtop-0.6.6/debian/mtop.postrm mtop-modified/mtop-0.6.6/debian/mtop.postrm
--- mtop/mtop-0.6.6/debian/mtop.postrm	2010-09-07 01:07:54.000000000 +0000
+++ mtop-modified/mtop-0.6.6/debian/mtop.postrm	2010-09-07 01:06:26.000000000 +0000
@@ -5,6 +5,17 @@
 
 set -e
 
+is_mysql_running()
+{
+	if [ -f /usr/bin/mysql ]; then
+		if [ "$(echo exit|LANG=C mysql -h ${mysql_server} -P ${mysql_port} -u${root_mysql} ${mysqlpwd} 2>&1|grep ^ERROR)" != "" ]; 
+		then
+			echo "WARNING: Can't connect to MySQL.";
+			echo "Perhaps you might want to use it other host?";
+		fi
+	fi
+}
+
 get_config()
 {
 	db_get mtop/mysql_server
@@ -45,6 +56,10 @@
 
 	if [ -f /usr/share/debconf/confmodule ] && [ -f /usr/bin/mysql ]; then
 		. /usr/share/debconf/confmodule
+		if [ -f /usr/share/dbconfig-common/dpkg/postrm.mysql ]; then
+		    . /usr/share/dbconfig-common/dpkg/postrm.mysql
+		    dbc_go mtop $@
+		fi
 		db_version 2.0
 
 		get_config
@@ -52,10 +67,15 @@
 		if [ "$root_passwd" != 'none' ]; then
 			mysqlpwd="-p${root_passwd}"
 		fi
-		mysqlcmd="mysql -h ${mysql_server} -P ${mysql_port} -u${root_mysql} ${mysqlpwd}"
-		if ${mysqlcmd} -B -e 'select user from user' mysql | grep -q "^mysqltop$"
-		then
+		IMR=$(is_mysql_running)
+		if [ "$IMR" != "" ]; then
+		    echo $IMR;
+		else
+		    mysqlcmd="mysql -h ${mysql_server} -P ${mysql_port} -u${root_mysql} ${mysqlpwd}"
+		    if ${mysqlcmd} -B -e 'select user from user' mysql | grep -q "^mysqltop$"
+		    then
 			remove_user;
+		    fi
 		fi
 	fi
       

Reply via email to