diff -Nuar dbconfig-common-1.8.44ubuntu1.orig/dpkg/common dbconfig-common-1.8.44ubuntu1/dpkg/common --- dbconfig-common-1.8.44ubuntu1.orig/dpkg/common 2010-01-24 02:15:45.000000000 +0100 +++ dbconfig-common-1.8.44ubuntu1/dpkg/common 2010-09-21 13:33:36.685274949 +0200 @@ -106,6 +106,7 @@ dbc_dbvendor="MySQL" dbc_dbpackage="mysql-server" dbc_dbclientpackage="mysql-client" + dbc_check_empty_db_cmd='dbc_check_database_empty' ;; pgsql) . /usr/share/dbconfig-common/internal/pgsql @@ -124,6 +125,7 @@ dbc_dbvendor="PostgreSQL" dbc_dbpackage="postgresql" dbc_dbclientpackage="postgresql-client" + dbc_check_empty_db_cmd='dbc_check_database_empty' ;; sqlite|sqlite3) . /usr/share/dbconfig-common/internal/sqlite @@ -144,6 +146,7 @@ dbc_sqlite_cmd="/usr/bin/$dbc_dbtype" dbc_dbpackage="$dbc_dbtype" dbc_dbclientpackage="$dbc_dbtype" + dbc_check_empty_db_cmd='dbc_check_database_empty' ;; *) dbc_register_templates="$dbc_standard_templates $dbc_mysql_templates $dbc_pgsql_templates $dbc_sqlite_templates" @@ -755,7 +758,10 @@ if [ "$RET" = "true" ]; then have_admin_pass="yes" fi - + + if [ "$dbc_dbtype" = "mysql" ]; then + have_admin_pass="yes" + fi # make sure the passwords are the same, safely while [ ! "$have_admin_pass" ]; do # get the administrative password @@ -774,8 +780,12 @@ fi done - db_get $dbc_package/$dbc_dbtype/admin-pass - dbc_dbadmpass="$RET" + if [ "$dbc_dbtype" != "mysql" ]; then + db_get $dbc_package/$dbc_dbtype/admin-pass + dbc_dbadmpass="$RET" + else + dbc_dbadmpass=`sed -ne "/^\[mysql\]/,/^\[/s%^password[^=]\+=[[:space:]]\+%%p" /root/.my.cnf` + fi } ## diff -Nuar dbconfig-common-1.8.44ubuntu1.orig/dpkg/postinst dbconfig-common-1.8.44ubuntu1/dpkg/postinst --- dbconfig-common-1.8.44ubuntu1.orig/dpkg/postinst 2010-01-23 14:08:29.000000000 +0100 +++ dbconfig-common-1.8.44ubuntu1/dpkg/postinst 2010-09-21 13:37:12.000000000 +0200 @@ -92,6 +92,20 @@ ### $dbc_createdb_cmd || dbc_install_error "creating database" [ "$dbc_tried_again" ] && return 0 + + # get the admin password if it's needed + if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then + if [ ! "$dbc_frontend" ]; then + if [ ! "$dbc_dbtype" = "pgsql" ] || [ ! "$dbc_authmethod_admin" = "ident" ]; then + dbc_get_admin_pass + fi + fi + fi + dbc_dumpfile=/var/cache/dbconfig-common/backups/${dbc_package}_${dbc_oldversion}_$(date +%d-%m-%y-%H:%M:%S).$dbc_dbtype + dbc_logline "creating database backup in $dbc_dumpfile" + # backup before we upgrade + #_dbc_asuser="" + $dbc_dump_cmd $dbc_dumpfile || dbc_upgrade_error "backing up the old database" ### ### populate the database @@ -100,7 +114,17 @@ dbc_sqlfile=$dbc_share/data/$dbc_basepackage/install/$dbc_dbtype dbc_sqlfile_adm=$dbc_share/data/$dbc_basepackage/install-dbadmin/$dbc_dbtype dbc_scriptfile=$dbc_share/scripts/$dbc_basepackage/install/$dbc_dbtype - if [ -f "$dbc_scriptfile" ]; then + if [ ! -z $dbc_check_table ]; then + dbc_check=$($dbc_check_empty_db_cmd $dbc_check_table) + if [ "$dbc_check" = "1" ]; then + dbc_logline "Database is empty..." + else + dbc_logline "Database is not empty..." + fi + else + dbc_check=1 + fi + if [ -f "$dbc_scriptfile" ] && [ "$dbc_check" = "1" ]; then dbc_logpart "populating database via scriptfile... " if ! sh -c "$dbc_scriptfile $*"; then dbc_error="$dbc_scriptfile exited with non-zero status" @@ -110,7 +134,7 @@ dbc_logline "done" fi - if [ -f "$dbc_sqlfile_adm" ]; then + if [ -f "$dbc_sqlfile_adm" ] && [ "$dbc_check" = "1" ]; then dbc_logpart "populating database via administrative sql... " if [ ! "$dbc_sql_substitutions" ]; then $dbc_sqlfile_cmd $dbc_sqlfile_adm || dbc_install_error "populating database with administrative sql" @@ -124,7 +148,7 @@ dbc_logline "done" fi - if [ -f "$dbc_sqlfile" ]; then + if [ -f "$dbc_sqlfile" ] && [ "$dbc_check" = "1" ]; then dbc_logpart "populating database via sql... " _dbc_asuser="yes" if [ ! "$dbc_sql_substitutions" ]; then @@ -156,6 +180,10 @@ fi # begin upgrade section + if [ ! -z $dbc_check_upgrade ] && [ "$dbc_check_upgrade" = "true" ]; then + upgrading="yes" + dbc_upgrade="yes" + fi if [ "$upgrading" ]; then @@ -165,25 +193,31 @@ if [ "$upgrades_pending" ]; then # ask if they want our help in the process at all db_set $dbc_package/dbconfig-upgrade $dbc_upgrade - db_fset $dbc_package/dbconfig-upgrade seen false + if [ "$dbc_check_upgrade" = "true" ]; then + db_fset $dbc_package/dbconfig-upgrade seen true + else + db_fset $dbc_package/dbconfig-upgrade seen false + fi db_input high $dbc_package/dbconfig-upgrade || true db_go || true db_get $dbc_package/dbconfig-upgrade && dbc_upgrade="$RET" # and if they don't want our help, we'll go away - if [ "$dbc_upgrade" != "true" ]; then return 0; fi + if [ "$dbc_check_upgrade" != "true" ]; then + if [ "$dbc_upgrade" != "true" ]; then return 0; fi - # get the admin password if it's needed - if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then - if [ ! "$dbc_frontend" ]; then - if [ ! "$dbc_dbtype" = "pgsql" ] || [ ! "$dbc_authmethod_admin" = "ident" ]; then - dbc_get_admin_pass + # get the admin password if it's needed + if echo "$dbc_authenticated_dbtypes" | grep -q "$dbc_dbtype"; then + if [ ! "$dbc_frontend" ]; then + if [ ! "$dbc_dbtype" = "pgsql" ] || [ ! "$dbc_authmethod_admin" = "ident" ]; then + dbc_get_admin_pass + fi fi fi fi # this is the file into which upgrade backups go - dbc_dumpfile=/var/cache/dbconfig-common/backups/${dbc_package}_${dbc_oldversion}.$dbc_dbtype + dbc_dumpfile=/var/cache/dbconfig-common/backups/${dbc_package}_${dbc_oldversion}_$(date +%d-%m-%y-%H:%M:%S).$dbc_dbtype dbc_logline "creating database backup in $dbc_dumpfile" # backup before we upgrade _dbc_asuser="" diff -Nuar dbconfig-common-1.8.44ubuntu1.orig/dpkg/prerm dbconfig-common-1.8.44ubuntu1/dpkg/prerm --- dbconfig-common-1.8.44ubuntu1.orig/dpkg/prerm 2009-02-17 23:05:34.000000000 +0100 +++ dbconfig-common-1.8.44ubuntu1/dpkg/prerm 2010-09-21 13:33:36.692774715 +0200 @@ -86,12 +86,18 @@ need_admin_pw="" fi - if [ "$dbc_purge" = "true" ]; then - # get the admin user password - if [ "$need_admin_pw" ]; then - dbc_get_admin_pass - fi + # get the admin user password + if [ "$need_admin_pw" ]; then + dbc_get_admin_pass + fi + dbc_dumpfile=/var/cache/dbconfig-common/backups/${dbc_package}_${dbc_oldversion}_$(date +%d-%m-%y-%H:%M:%S).$dbc_dbtype + dbc_logline "creating database backup in $dbc_dumpfile" + # backup before we upgrade + #_dbc_asuser="" + $dbc_dump_cmd $dbc_dumpfile || dbc_upgrade_error "backing up the old database" + + if [ "$dbc_purge" = "true" ]; then # dump the database into a temporary file nowtime=`date +%Y-%m-%d-%H.%M` if [ ! `dirname /var/tmp/$dbc_package` = /var/tmp ]; then diff -Nuar dbconfig-common-1.8.44ubuntu1.orig/internal/mysql dbconfig-common-1.8.44ubuntu1/internal/mysql --- dbconfig-common-1.8.44ubuntu1.orig/internal/mysql 2010-01-23 14:06:30.000000000 +0100 +++ dbconfig-common-1.8.44ubuntu1/internal/mysql 2010-09-21 13:33:36.692774715 +0200 @@ -37,7 +37,17 @@ socket = '/var/run/mysqld/mysqld.sock' EOF - echo $mycnf + if [ ! -f "/root/.my.cnf" ]; then + #llxcfg-dbs init || llxcfg-dbs generate || true + if [ mysql_root_passwd ] ; then + echo "Config DB [OK]" + else + echo "Config DB [FAIL]" + fi + fi + cat /root/.my.cnf >> $mycnf + echo $mycnf + } ## @@ -125,6 +135,21 @@ return $? } +dbc_check_database_empty(){ + local dbc_dbname local _dbc_nodb + if _dbc_mysql_check_database "$dbc_dbname"; then + dbc_table=$1 + #_dbc_nodb="yes" + dbc_logline "Checking if database is empty..." + dbc_mysql_exec_command "SELECT 1 FROM ${dbc_dbname}.$dbc_table LIMIT 1" 2>/dev/null | grep -q "1" + echo $? + else + echo 0 + fi + + +} + ## ## check for access for a specific user ##