sql works testing
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Wed, 31 Aug 2011 16:50:58 +0200
branchtesting
changeset 7 c34f5210c656
parent 6 e9d06ed052d3
child 8 be5b25357026
sql works
debian/changelog
debian/littlebird-tc-common.config
debian/littlebird-tc-common.templates
debian/littlebird-tc-sql.config
debian/littlebird-tc-sql.postinst
debian/littlebird-tc-sql.templates
--- a/debian/changelog	Wed Aug 31 14:13:15 2011 +0200
+++ b/debian/changelog	Wed Aug 31 16:50:58 2011 +0200
@@ -1,44 +1,8 @@
-littlebird (2011072500-9) stable; urgency=low
-
-  * next stop config script 
-
- -- Heiko Schlittermann <hs@schlittermann.de>  Wed, 31 Aug 2011 13:56:32 +0200
-
-littlebird (2011072500-8) stable; urgency=low
-
-  * fixed db installation script 
-
- -- Heiko Schlittermann <hs@schlittermann.de>  Wed, 31 Aug 2011 11:43:35 +0200
-
-littlebird (2011072500-7) stable; urgency=low
-
-  * improved dependencies 
-
- -- Heiko Schlittermann <hs@schlittermann.de>  Tue, 30 Aug 2011 16:59:56 +0200
-
-littlebird (2011072500-6) stable; urgency=low
+littlebird (2011072500-13) stable; urgency=low
 
-  * new "meta" littlebird-tc
-
- -- Heiko Schlittermann <hs@schlittermann.de>  Tue, 30 Aug 2011 16:49:25 +0200
-
-littlebird (2011072500-5) stable; urgency=low
-
-  * provide littlebird 
-
- -- Heiko Schlittermann <hs@schlittermann.de>  Tue, 30 Aug 2011 16:29:41 +0200
+  * create the database if not already existing 
 
-littlebird (2011072500-4) stable; urgency=low
-
-  * moved to stable
-
- -- Heiko Schlittermann <hs@schlittermann.de>  Tue, 30 Aug 2011 16:22:50 +0200
-
-littlebird (2011072500-3) unstable; urgency=low
-
-  * autoupdate control file 
-
- -- Heiko Schlittermann <hs@schlittermann.de>  Tue, 30 Aug 2011 15:34:15 +0200
+ -- Heiko Schlittermann <hs@schlittermann.de>  Wed, 31 Aug 2011 16:20:13 +0200
 
 littlebird (2011072500-2) unstable; urgency=low
 
--- a/debian/littlebird-tc-common.config	Wed Aug 31 14:13:15 2011 +0200
+++ b/debian/littlebird-tc-common.config	Wed Aug 31 16:50:58 2011 +0200
@@ -1,25 +1,27 @@
 #! /bin/sh
-
-PKG=littlebird-tc-common
 set -e
-
 . /usr/share/debconf/confmodule
 db_version 2.0
 
+prefix=littlebird-tc
+
+
 # used for testing
 if test "$1" = "clear"; then
-    db_reset $PKG/db/host
-    db_reset $PKG/db/user
-    db_reset $PKG/db/pass
-    db_reset $PKG/db/name
+    db_reset $prefix/db/host
+    db_reset $prefix/db/user
+    db_reset $prefix/db/pass
+    db_reset $prefix/db/name
 fi
 
+db_settitle $prefix-common/TITLE
+
 db_beginblock
-    db_settitle $PKG/TITLE
-    db_input high $PKG/db/host
-    db_input high $PKG/db/user
-    db_input high $PKG/db/pass
-    db_input medium $PKG/db/name
+    db_input medium $prefix/db/name	|| true
+    db_input medium $prefix/db/host	|| true
+    db_input high $prefix/db/user	|| true
+    db_input high $prefix/db/pass	|| true
 db_endblock
 
 db_go || true
+
--- a/debian/littlebird-tc-common.templates	Wed Aug 31 14:13:15 2011 +0200
+++ b/debian/littlebird-tc-common.templates	Wed Aug 31 16:50:58 2011 +0200
@@ -2,25 +2,30 @@
 Type: title
 Description: This is the littlebird trust center package.
 
-Template: littlebird-tc-common/db/host
+Template: littlebird-tc/db/host
 Type: string
 Default: localhost
-Description: The name or IP address of the MySQL server.
- Optionally you may append a port number (default port
- used is 3306), separated by a colon ":".
+Description: The name or address of the MySQL server (hostname[:port]).
+ We need to know how to connect to your database server. Please note,
+ that some mysql clients use a local UNIX socket connection if you enter
+ "localhost", but use a local TCP connection, if you enter "127.0.0.1".
+ .
+ You may append (separeted by a colon (":")) a port number, if your
+ server does not listen on the default (currently 3306) port.
 
-Template: littlebird-tc-common/db/user
+Template: littlebird-tc/db/user
 Type: string
 Default: littlebird
-Description: The user to be used for the database connection.
- This user is used for all normal operations.
+Description: The database user to be used for the database connection.
+ This is the user to be used for all normal operations. If this is a
+ fresh installation, we will create the account.
 
-Template: littlebird-tc-common/db/pass
+Template: littlebird-tc/db/pass
 Type: password
 Default:
 Description: The password to be used for the database connection.
 
-Template: littlebird-tc-common/db/name
+Template: littlebird-tc/db/name
 Type: string
 Default: littlebird
 Description: The name of the database we should use.
--- a/debian/littlebird-tc-sql.config	Wed Aug 31 14:13:15 2011 +0200
+++ b/debian/littlebird-tc-sql.config	Wed Aug 31 16:50:58 2011 +0200
@@ -3,38 +3,28 @@
 . /usr/share/debconf/confmodule
 db_version 2.0
 
+
 prefix=littlebird-tc
-
-myaccess() { mysql -h"$1" -u"$2" -p"$3" -e ""; }
+myaccess_ok() { mysql -h"$1" -u"$2" -p"$3" -e ""; }
 
 
 if test "$1" = "clear"; then
-	db_reset $prefix/db/adminuser
-	db_reset $prefix/db/adminpass
+    for key in db/adminuser db/adminpass
+    do db_reset $prefix/$key; done
 fi
 
-db_settitle littlebird-tc-sql/TITLE
-
+db_settitle $prefix-sql/TITLE
 db_beginblock
-
-	if false; then
-	db_get $prefix/db/host      && host="${RET}"
-	db_get $prefix/db/adminuser && user="${RET}" 
-	db_get $prefix/db/adminpass && pass="${RET}" 
-
-	if test "$user" && test "$pass" \
-		&& myaccess "$host" "$user" "$pass"
-	then
-		echo "DB access as admin is ok" >&2
-	else
-		db_input medium $prefix/db/adminuser
-		db_input medium $prefix/db/adminpass
-	fi
-	fi
-
-	db_input medium $prefix/db/adminuser
-	db_input high   $prefix/db/adminpass
+	db_input medium   $prefix/db/adminuser || true
+	db_input critical $prefix/db/adminpass || true
 db_endblock
 
 db_go || true
-	
+
+db_get $prefix/db/adminpass || true
+if test -z "$RET" ; then
+    db_fset $prefix/db/noadminpass seen false
+    db_input critical $prefix/db/noadminpass || true
+    db_go || true
+    exit 1
+fi
--- a/debian/littlebird-tc-sql.postinst	Wed Aug 31 14:13:15 2011 +0200
+++ b/debian/littlebird-tc-sql.postinst	Wed Aug 31 16:50:58 2011 +0200
@@ -20,21 +20,39 @@
 
 case "$1" in
     configure)
-	db_get mysql-server/root_password && adminpass="$RET" || true
-
+	db_get littlebird-tc/db/adminuser && adminuser="$RET" || true
+	db_get littlebird-tc/db/adminpass && adminpass="$RET" || true
 	db_get littlebird-tc/db/user && user="$RET" || true
 	db_get littlebird-tc/db/pass && pass="$RET" || true
 	db_get littlebird-tc/db/host && host="$RET" || true
 	db_get littlebird-tc/db/name && name="$RET" || true
 
-	cat <<EOF
-adminpass: $adminpass
-user: $user
-pass: $pass
-host: $host
-name: $name
+#	cat <<EOF
+#$@
+#adminuser/pass: $adminuser/$adminpass
+#user/pass: $user/$pass
+#db@host: $name@$host
+#EOF
+	# only init the db if there is no previous version
+	if test -z "$2" && test -n "$adminpass"; then
+
+	    if test "$host" = "localhost"; then client="localhost"
+	    else client="%"
+	    fi
+
+	    mysql -h"$host" -u"$adminuser" -p"$adminpass" <<EOF
+		CREATE DATABASE IF NOT EXISTS $name;
+		GRANT ALL ON $name.* TO '$user'@'$client' IDENTIFIED BY '$pass';
+		FLUSH PRIVILEGES;
 EOF
-	
+	    (	set -e
+		cd /usr/share/littlebird/tc-sql
+		./install_test_iteration_2011-06.sh \
+		    "$host" "$name" \
+		    "$adminuser" "$adminpass" \
+		    "$user" "$pass"
+	    )
+	fi
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
--- a/debian/littlebird-tc-sql.templates	Wed Aug 31 14:13:15 2011 +0200
+++ b/debian/littlebird-tc-sql.templates	Wed Aug 31 16:50:58 2011 +0200
@@ -17,3 +17,16 @@
  the password for the user who is empowered enough. (The password will be securly kept
  in the debconf database.)
 
+Template: littlebird-tc/db/noadminpass
+Type: note
+Description: No password given!
+ You didn't tell us a admin password for accessing the database. Since
+ we refuse to use any database without any password, you're left
+ alone with an unconfigured package. Please, later, run the following
+ command: 
+ .
+ dpkg-reconfigure littlebird-tc-sql
+ .
+ Sorry for the inconvenience.
+ .
+ HINT: Maybe you want to install a mysql server?