From f6d267307b5215716d4408c138ca8fecd439f462 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 30 May 2010 13:37:13 +0200 Subject: [PATCH] Add options DRY_RUN and NO_CONFIRM to upgrade scripts MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Adds a mysql_exec function to execute a simple query Signed-off-by: Raphaël Barrois --- upgrade/inc/pervasive.sh | 52 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 14 deletions(-) diff --git a/upgrade/inc/pervasive.sh b/upgrade/inc/pervasive.sh index 2206abc..94cb23b 100755 --- a/upgrade/inc/pervasive.sh +++ b/upgrade/inc/pervasive.sh @@ -23,18 +23,34 @@ function die() { } function confirm() { - echo "$1" - echo "* press ^D to start import (^C to cancel)" - cat + if [[ -n "${NO_CONFIRM}" ]]; then + echo "$1" + echo "* press ^C to cancel, waiting 5 seconds..." + sleep 5 + else + echo "$1" + echo "* press ^D to start import (^C to cancel)" + cat + fi } function mysql_pipe() { sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" | $MYSQL $DATABASE } +function mysql_exec() { + echo -n " * executing $1 " + if [[ -z "${DRY_RUN}" ]]; then + (echo $1 | mysql_pipe) || die "ERROR" + fi + echo "OK" +} + function mysql_run() { - echo -n "* running $1" - (cat $1 | mysql_pipe) || die "ERROR" + echo -n " * running $1 " + if [[ -z "${DRY_RUN}" ]]; then + (cat $1 | mysql_pipe) || die "ERROR" + fi echo "OK" } @@ -45,26 +61,34 @@ function mysql_run_directory() { } function script_run() { - echo -n "* running $1" - $1 || die "ERROR" + echo -n " * running $1 " + if [[ -z "${DRY_RUN}" ]]; then + $1 || die "ERROR" + fi echo "OK" } function mailman_stop() { - echo -n "stops mailman" - /etc/init.d/mailman stop &>/dev/null + echo -n " * stops mailman" + if [[ -z "${DRY_RUN}" ]]; then + /etc/init.d/mailman stop &>/dev/null + fi echo . } function mailman_templates() { - echo -n "copies new mails templates" - mkdir -p /etc/mailman/xorg - cp -f ../../modules/lists/mail_templates/*.txt /etc/mailman/xorg + echo -n " * copies new mails templates" + if [[ -z "${DRY_RUN}" ]]; then + mkdir -p /etc/mailman/xorg + cp -f ../../modules/lists/mail_templates/*.txt /etc/mailman/xorg + fi echo . } function mailman_start() { - echo -n "starts mailman" - /etc/init.d/mailman start &>/dev/null + echo -n " * starts mailman" + if [[ -z "${DRY_RUN}" ]]; then + /etc/init.d/mailman start &>/dev/null + fi echo . } -- 2.1.4