start move to dbconfig-common based idb configuration
authorJeremy Laine <jeremy.laine@m4x.org>
Sun, 5 Nov 2006 12:36:52 +0000 (12:36 +0000)
committerJeremy Laine <jeremy.laine@m4x.org>
Sun, 5 Nov 2006 12:36:52 +0000 (12:36 +0000)
debian/changelog
debian/control
debian/diogenes.config
debian/diogenes.dbc-upgrade [new file with mode: 0644]
debian/diogenes.postinst
debian/diogenes.postrm
debian/diogenes.prerm
debian/prefix.sql [deleted file]
debian/rules

index 667c202..03cda1a 100644 (file)
@@ -1,3 +1,9 @@
+diogenes (0.9.20-2) unstable; urgency=low
+
+  * Switch to dbconfig-common for database setup. 
+
+ -- Jeremy Lainé <jeremy.laine@m4x.org>  Sun,  5 Nov 2006 12:03:28 +0100
+
 diogenes (0.9.20-1) unstable; urgency=low
 
   * New upstream release.
index 7e39e83..a6dd0d4 100644 (file)
@@ -8,7 +8,7 @@ Build-Depends-Indep: po-debconf
 
 Package: diogenes
 Architecture: all
-Depends: ${misc:Depends}, libphp-diogenes (= ${Source-Version}), gettext, wwwconfig-common (>=0.0.41), apache | apache2 | httpd, php4-cli | php5-cli, php-pear | php4-pear, cvs, rcs, perl-modules, ucf (>=0.28)
+Depends: ${misc:Depends}, libphp-diogenes (= ${Source-Version}), gettext, dbconfig-common, apache | apache2 | httpd, php4-cli | php5-cli, php-pear | php4-pear, cvs, rcs, perl-modules, ucf (>=0.28)
 Recommends: mysql-server
 Suggests: wv
 Description: web content management system
index 08221cb..6cf127f 100644 (file)
@@ -1,34 +1,5 @@
 #!/bin/bash -e
 
-RANDOMDEVICE=/dev/urandom
-allowed=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./
-declare -a RVAL
-
-second () {
-       echo $2
-}
-
-create-random-pw() {
-       if ! read -n 0 < $RANDOMDEVICE ; then
-               echo 1>&2 "Warning, no random device found, password might be insecure"
-               for i in 0 1 2 3 4 5 6 7; do
-                       RVAL[i]=$RANDOM
-               done
-       else
-               for i in 0 1 2 3 4 5 6 7; do
-                       RVAL[i]=$(second $(od -N 1 -t d $RANDOMDEVICE))
-               done
-       fi
-
-       PW=""
-       for i in 0 1 2 3 4 5 6 7; do
-               idx=$((${RVAL[i]} & 0x3F))
-               PW="${PW}${allowed:$idx:1}"
-       done
-
-       printf "%s" $PW
-}
-
 # this function comes from wwwconfig-common's apache.func script
 getwwwoption() {
     getwwwoption=""
@@ -84,31 +55,10 @@ else
     db_set "diogenes/webgroup" "$webgroup"
 fi
 
-db_input "high" "diogenes/databasemgr_type" || true
-db_go
-db_get "diogenes/databasemgr_type"
-dbtype="$RET"
+# source dbconfig-common shell library, and call the hook function
+if [ -f /usr/share/dbconfig-common/dpkg/config.mysql ]; then
+    . /usr/share/dbconfig-common/dpkg/config.mysql 
+    dbc_go diogenes $@
+fi
 
-if [ "$dbtype" = "Automatic" ] ; then
-    db_input "high" "diogenes/databasemgr_server" || true
-    db_go
-    db_input "high" "diogenes/dbmyadmin" || true
-    db_go
-    db_input "critical" "diogenes/dbadmpass" || true
-    db_go
-    db_input "medium" "diogenes/database_name" || true
-    db_go
-    db_input "medium" "diogenes/database_user" || true
-    db_go
-    db_input "medium" "diogenes/database_pass" || true
-    db_go
-    db_get "diogenes/database_pass"
-    dbpass="$RET"
-    if [ "$dbpass" = "auto" ]; then
-       dbpass=$(create-random-pw)
-    elif [ "$dbpass" = "none" ]; then
-       dbpass=""
-    fi
-    db_set "diogenes/database_pass" "$dbpass"
 
-fi
diff --git a/debian/diogenes.dbc-upgrade b/debian/diogenes.dbc-upgrade
new file mode 100644 (file)
index 0000000..3d459ed
--- /dev/null
@@ -0,0 +1,18 @@
+#!/bin/sh -e
+
+updatedb=/usr/share/diogenes/scripts/updatedb.php
+dbconfig=/etc/dbconfig-common/diogenes.conf
+
+if [ ! -f "$dbconfig" ]; then
+    echo "Could not find config file : $dbconfig"
+    exit 0
+fi
+
+. $dbconfig
+if [ -z "$dbc_dbserver" ]; then
+    dbc_dbserver="localhost"
+fi
+
+if [ -x "$updatedb" ]; then
+    $updatedb -q -s "$dbc_dbserver" -d "$dbc_dbname" -u "$dbc_dbuser" -p "$dbc_dbpass"
+fi
index 49db604..889b65d 100644 (file)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Horde postinst script using debconf
+# Diogenes postinst script using debconf and dbconfig-common
 # Written by Ola Lundqvist <opal@debian.org>
 # Adapted for Horde2 by Nils Rennebarth <nils@debian.org>
 # Adapted for Diogenes by Jeremy Lainé <jeremy.laine@m4x.org>
@@ -30,9 +30,16 @@ set -e
 create_file_from_template() {
   infile=$1
   outfile=$2
+  if [ -f /etc/dbconfig-common/diogenes.conf ]; then
+    . /etc/dbconfig-common/diogenes.conf
+  fi
+  # If dbc_dbserver is empty, use localhost
+  if [ -z "$dbc_dbserver" ]; then
+      dbc_dbserver="localhost"
+  fi
   # Password may contain anything, so we need to descend to quoting
   # hell.
-  safepass="$dbpass"
+  safepass="$dbc_dbpass"
   # quote normal quote and final backslash because we need to write
   # a single quoted PHP string
   safepass=$(echo "$safepass" | sed -e "s/'/\\\\'/g" -e 's/\\$/\\\\'/)
@@ -42,13 +49,22 @@ create_file_from_template() {
   # we use the hash sign as a delimiter
   safepass=$(echo "$safepass" | sed -e 's/#/\\#/g')
   sed -e "                             \
-    s#@dbname@#$dbname#;               \
-    s#@dbserver@#$dbserver#;   \
-    s#@dbuser@#$dbuser#;               \
+    s#@dbname@#$dbc_dbname#;           \
+    s#@dbserver@#$dbc_dbserver#;       \
+    s#@dbuser@#$dbc_dbuser#;           \
     s#@dbpass@#$safepass#;             \
     " <$infile >$outfile
 }
 
+# get debconf started
+. /usr/share/debconf/confmodule
+db_version 2.0
+
+# source dbconfig-common shell library, and call the hook function
+if [ -f /usr/share/dbconfig-common/dpkg/postinst.mysql ]; then
+    . /usr/share/dbconfig-common/dpkg/postinst.mysql 
+    dbc_go diogenes $@
+fi
 
 case "$1" in
     configure)
@@ -57,67 +73,6 @@ case "$1" in
 ucf --debconf-ok /usr/share/diogenes/config/diogenes.debian.inc.php /etc/diogenes/diogenes.debian.inc.php
 ucf --debconf-ok /usr/share/diogenes/config/apache.conf /etc/diogenes/apache.conf
 
-# get debconf started
-. /usr/share/debconf/confmodule
-db_version 2.0
-
-###############################################################################
-############################### Configure database ############################
-###############################################################################
-
-# Type of the databasemgr to use.
-db_get "diogenes/databasemgr_type"
-dbtype="$RET"
-if [ "$dbtype" = "Automatic" ] ; then
-  # Where it is located.
-  db_get "diogenes/databasemgr_server"
-  dbserver="$RET"
-  # Name of the database
-  db_get "diogenes/database_name"
-  dbname="$RET"
-  # Name of the user to have access.
-  db_get "diogenes/database_user"
-  dbuser="$RET"
-  # Its password.
-  db_get "diogenes/database_pass"
-  dbpass="$RET"
-
-  if [ ! -z $(which mysql) ]; then
-
-    # retrieve admin user and password
-    db_get "diogenes/dbmyadmin"
-    dbadmin="$RET"
-    db_get "diogenes/dbadmpass"
-    dbadmpass="$RET"
-    db_reset "diogenes/dbadmpass"
-
-    . /usr/share/wwwconfig-common/mysql-createdb.sh
-    if [ "$status" = "create" ] ; then
-      sqlfile=/usr/share/diogenes/scripts/diogenes.tables.sql
-      create_file_from_template $sqlfile.in $sqlfile
-      . /usr/share/wwwconfig-common/mysql-exec.sh
-      rm $sqlfile
-      sqlfile=/usr/share/diogenes/scripts/diogenes.logactions.sql
-      create_file_from_template $sqlfile.in $sqlfile
-      . /usr/share/wwwconfig-common/mysql-exec.sh
-      rm $sqlfile
-    elif [ "$status" = "nothing" ] ; then
-      if ! /usr/share/diogenes/scripts/updatedb.php -q -s "$dbserver" -d "$dbname" -u "$dbadmin" -p "$dbadmpass" ; then
-        echo "There was an error while upgrading the Diogenes database."
-      fi
-    else
-      echo $error
-    fi
-    . /usr/share/wwwconfig-common/mysql-createuser.sh
-  else
-    echo "Not configuring MySQL database because we cannot locate"
-    echo "the mysql client executable (mysql-client package missing)."
-  fi
-else
-    echo "Not configuring MySQL database at your request."
-fi
-
-
 ###############################################################################
 ########################## Configure web servers ##############################
 ###############################################################################
@@ -133,7 +88,7 @@ for server in $webservers; do
     # If necessary, add a symlink to our apache.conf
     if [ -d /etc/$server/conf.d ] && [ ! -e /etc/$server/conf.d/diogenes ] ; then
         ln -s $includefile /etc/$server/conf.d/diogenes
-       restart="$server $restart"
+        restart_servers="$server $restart_servers"
     fi
 done
 
@@ -163,10 +118,18 @@ chown -R $webuser /var/spool/diogenes
 ###############################################################################
 ############################# Servers restart #################################
 ###############################################################################
-if ! eval . /usr/share/wwwconfig-common/restart.sh ; then
-  echo "There was a problem restarting web server(s)."
-fi
 
+if [ -n "$restart_servers" ]; then
+    for server in $restart_servers; do
+        if [ -x /etc/init.d/$server ]; then
+            if which invoke-rc.d >/dev/null 2>&1; then
+                invoke-rc.d $server reload
+            else
+                /etc/init.d/$server reload
+            fi
+        fi
+    done
+fi
     ;;
 
     abort-upgrade|abort-remove|abort-deconfigure)
index 3e394d2..4d82e3f 100644 (file)
@@ -1,5 +1,5 @@
 #!/bin/sh -e
-# Horde postrm script using debconf
+# Diogenes postrm script using debconf
 # Originally written for horde by Ola Lundqvist <opal@debian.org>
 # Adapted for horde2 by Nils Rennebarth <nils@debian.org>
 # Adapted for Diogenes by Jeremy Lainé <jeremy.laine@m4x.org>
@@ -13,24 +13,35 @@ remove_from_webconfig () {
         servers="$server $servers"
         if [ -s /etc/$server/conf.d/diogenes ] ; then
             rm -f /etc/$server/conf.d/diogenes
-            restart="$server $restart"
+            restart_servers="$server $restart_servers"
         fi
     done
 
     # Restart servers
-    if [ -e /usr/share/wwwconfig-common/restart.sh ] ; then
-        . /usr/share/wwwconfig-common/restart.sh
+    if [ -n "$restart_servers" ]; then
+        for server in $restart_servers; do
+            if [ -x /etc/init.d/$server ]; then
+                if which invoke-rc.d >/dev/null 2>&1; then
+                    invoke-rc.d $server reload
+                else
+                    /etc/init.d/$server reload
+                fi
+            fi
+        done
     fi
 }
 
+. /usr/share/debconf/confmodule
+db_version 2.0
+# source dbconfig-common shell library, and call the hook function
+if [ -f /usr/share/dbconfig-common/dpkg/postrm.mysql ]; then
+    . /usr/share/dbconfig-common/dpkg/postrm.mysql 
+    dbc_go diogenes $@
+fi
+
 ACTION=$1
 case "$ACTION" in
 remove)
-    #
-    # Remove Diogenes from the webserver configuration
-    #
-    . /usr/share/debconf/confmodule
-    db_version 2.0
 
     #
     # Only try to remove Diogenes from the webserver configs if the db key
@@ -43,8 +54,6 @@ remove)
     ;;
 
 purge)
-    . /usr/share/debconf/confmodule
-    db_version 2.0
        
     #
     # Remove ucf-managed files
@@ -61,26 +70,6 @@ purge)
     if [ "$RET" = "true" ]; then
         # remove files
         rm -rf /var/spool/diogenes /var/lib/diogenes
-
-        # drop the database if we are Automatic mode
-        db_get "diogenes/databasemgr_type"
-        if [ "$RET" = "Automatic" ] ; then
-            db_get "diogenes/databasemgr_server"
-            dbserver="$RET"
-            db_get "diogenes/database_name"
-            dbname="$RET"
-            # we use the Diogenes user as the "admin", as he is authorized to do a drop
-            db_get "diogenes/database_user"
-            dbadmin="$RET"
-            db_get "diogenes/database_pass"
-            dbadmpass="$RET"
-           if [ -f /usr/share/wwwconfig-common/mysql.get ] && [ -x $(which mysql) ] ; then
-               . /usr/share/wwwconfig-common/mysql.get
-                if eval $mysqlcmd -f -e "\"DROP DATABASE $dbname;\"" ; then
-                 status=dropped
-               fi
-           fi
-        fi
     fi
     ;;
 
index 8de7ce1..b9cb74a 100644 (file)
@@ -1,5 +1,13 @@
 #!/bin/sh -e
 
+. /usr/share/debconf/confmodule
+db_version 2.0
+# source dbconfig-common shell library, and call the hook function
+if [ -f /usr/share/dbconfig-common/dpkg/prerm.mysql ]; then
+    . /usr/share/dbconfig-common/dpkg/prerm.mysql 
+    dbc_go diogenes $@
+fi
+
 ACTION=$1
 case "$ACTION" in
 remove)
diff --git a/debian/prefix.sql b/debian/prefix.sql
deleted file mode 100644 (file)
index 76cf14d..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# establish connection to database
-
-connect @dbname@;
-
index b302d90..a9338da 100755 (executable)
@@ -13,7 +13,7 @@ DEB_INSTALL_CHANGELOGS_diogenes := ChangeLog
 DEB_INSTALL_CHANGELOGS_libphp-diogenes := include/diogenes/ChangeLog
 
 #directories
-DEB_INSTALL_DIRS_diogenes := etc/diogenes var/lib/diogenes var/spool/diogenes/templates_c var/spool/diogenes/diogenes_c
+DEB_INSTALL_DIRS_diogenes := etc/diogenes var/lib/diogenes var/spool/diogenes/templates_c var/spool/diogenes/diogenes_c usr/share/dbconfig-common/data/diogenes/install usr/share/dbconfig-common/scripts/diogenes/upgrade/mysql
 
 binary-install/diogenes::
        # config
@@ -29,10 +29,9 @@ binary-install/diogenes::
                usr/share/diogenes
        
        # files for db installation
-       cat debian/prefix.sql config/db/diogenes.sql \
-         > debian/diogenes/usr/share/diogenes/scripts/diogenes.tables.sql.in
-       cat debian/prefix.sql config/db/diogenes.logactions.sql \
-         > debian/diogenes/usr/share/diogenes/scripts/diogenes.logactions.sql.in
+       cat config/db/diogenes.sql config/db/diogenes.logactions.sql > debian/diogenes/usr/share/dbconfig-common/data/diogenes/install/mysql
+       #cp debian/diogenes.dbc-upgrade debian/diogenes/usr/share/dbconfig-common/scripts/diogenes/upgrade/mysql/0.9.20-2
+       #chmod +x debian/diogenes/usr/share/dbconfig-common/scripts/diogenes/upgrade/mysql/0.9.20-2
        
        # remove library files
        rm -rf debian/diogenes/usr/share/diogenes/include/diogenes