From 2d7fae94cab8f45df4740a81eb808407700e7bd9 Mon Sep 17 00:00:00 2001 From: Robin Sheat Date: Thu, 16 Dec 2010 18:05:43 +1300 Subject: [PATCH] Bug 5509 - use an XML parser to get values from config Using sed and regex was causing issues when LDAP connection details were added. See http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 for more information. Signed-off-by: Chris Cormack (cherry picked from commit dfc1038931618a820942f8cb9456be72648ce0f4) Signed-off-by: Chris Nighswonger --- debian/control | 2 +- debian/control.in | 1 + debian/scripts/koha-dump | 8 ++++---- debian/scripts/koha-dump-defaults | 10 ++++++---- debian/scripts/koha-restore | 2 +- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/debian/control b/debian/control index 79fd89f6bf..add095f3fa 100644 --- a/debian/control +++ b/debian/control @@ -25,7 +25,6 @@ Build-Depends: libalgorithm-checkdigits-perl, libdbi-perl, libdigest-sha-perl | perl, libemail-date-perl, - libfile-temp-perl | perl-modules, libgd-barcode-perl, libgd-gd2-noxpm-perl | libgd-gd2-perl, libgraphics-magick-perl, @@ -93,6 +92,7 @@ Depends: ${misc:Depends}, ${koha:Depends}, mysql-client, pwgen, tinymce2, + xmlstarlet, yaz Suggests: mysql-server Homepage: http://koha-community.org/ diff --git a/debian/control.in b/debian/control.in index 44e144b072..090b7b338c 100644 --- a/debian/control.in +++ b/debian/control.in @@ -22,6 +22,7 @@ Depends: ${misc:Depends}, ${koha:Depends}, mysql-client, pwgen, tinymce2, + xmlstarlet, yaz Suggests: mysql-server Homepage: http://koha-community.org/ diff --git a/debian/scripts/koha-dump b/debian/scripts/koha-dump index ab2995e2d0..99c389415b 100755 --- a/debian/scripts/koha-dump +++ b/debian/scripts/koha-dump @@ -40,10 +40,10 @@ echo "Dumping Koha site $name:" # Dump database. -mysqlhost="$(sed -n '/.*\(.*\)<\/hostname>.*/s::\1:p' $kohaconfig)" -mysqldb="$(sed -n '/.*\(.*\)<\/database>.*/s::\1:p' $kohaconfig)" -mysqluser="$(sed -n '/.*\(.*\)<\/user>.*/s::\1:p' $kohaconfig | tail -n1)" -mysqlpass="$(sed -n '/.*\(.*\)<\/pass>.*/s::\1:p' $kohaconfig)" +mysqlhost="$( xmlstarlet sel -t -v 'yazgfs/config/hostname' $kohaconfig )" +mysqldb="$( xmlstarlet sel -t -v 'yazgfs/config/database' $kohaconfig )" +mysqluser="$( xmlstarlet sel -t -v 'yazgfs/config/user' $kohaconfig )" +mysqlpass="$( xmlstarlet sel -t -v 'yazgfs/config/pass' $kohaconfig )" dbdump="/var/spool/koha/$name/$name-$date.sql.gz" echo "* DB to $dbdump" mysqldump --databases --host="$mysqlhost" \ diff --git a/debian/scripts/koha-dump-defaults b/debian/scripts/koha-dump-defaults index 1de7ed8113..fb5e988067 100755 --- a/debian/scripts/koha-dump-defaults +++ b/debian/scripts/koha-dump-defaults @@ -27,8 +27,10 @@ kohaconfig="/etc/koha/sites/$name/koha-conf.xml" date="$(date +%Y-%m-%d)" -mysqldb="$(sed -n '/.*\(.*\)<\/database>.*/s::\1:p' $kohaconfig)" -mysqluser="$(sed -n '/.*\(.*\)<\/user>.*/s::\1:p' $kohaconfig | tail -n1)" -mysqlpass="$(sed -n '/.*\(.*\)<\/pass>.*/s::\1:p' $kohaconfig)" -mysqldump --databases --user="$mysqluser" --password="$mysqlpass" "$mysqldb" | +mysqlhost="$( xmlstarlet sel -t -v 'yazgfs/config/hostname' $kohaconfig )" +mysqldb="$( xmlstarlet sel -t -v 'yazgfs/config/database' $kohaconfig )" +mysqluser="$( xmlstarlet sel -t -v 'yazgfs/config/user' $kohaconfig )" +mysqlpass="$( xmlstarlet sel -t -v 'yazgfs/config/pass' $kohaconfig )" +mysqldump --databases --host="$mysqlhost" --user="$mysqluser" \ + --password="$mysqlpass" "$mysqldb" | sed "s/$name/__KOHASITE__/g" diff --git a/debian/scripts/koha-restore b/debian/scripts/koha-restore index 560dc406c0..49990883ba 100755 --- a/debian/scripts/koha-restore +++ b/debian/scripts/koha-restore @@ -69,7 +69,7 @@ tar -C / -xf "$configdump" # Re-create database and database user. mysqldb="koha_$name" mysqluser="koha_$name" -mysqlpwd="$(sed -n '/.*\(.*\)<\/pass>.*/s//\1/p' /etc/koha/sites/$name/koha-conf.xml)" +mysqlpwd="$( xmlstarlet sel -t -v 'yazgfs/config/pass' /etc/koha/sites/$name/koha-conf.xml )" zcat "$sqldump" | mysql --defaults-extra-file=/etc/mysql/koha-common.cnf mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <