X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=upgrade%2Finc%2Fpervasive.sh;h=bc369ceff94362f3907aa3182286f1c65415c023;hb=c76545c351fae4e2298624ff9ee5bf854dc5a5b6;hp=f5b279e4e48f2606722fb7b6249557180a388475;hpb=f3a7456dbe1cbe78dfe0ccc2e99c299ad97203c5;p=platal.git diff --git a/upgrade/inc/pervasive.sh b/upgrade/inc/pervasive.sh index f5b279e..bc369ce 100755 --- a/upgrade/inc/pervasive.sh +++ b/upgrade/inc/pervasive.sh @@ -5,7 +5,7 @@ MYSQL='mysql -u admin ' set -e -if [ "$UID" != 0 ]; then +if [ "$UID" != 0 ] && [ "$1" != "-u" ] ; then echo "has to be run as root" exit 1 fi @@ -13,23 +13,94 @@ fi if [[ -n "${DBPREFIX}" ]]; then echo "Using non-default database ${DBPREFIX}x4dat." fi -declare -r DATABASE="${DBPREFIX}x4dat" +if [[ -z "${DATABASE}" ]]; then + DATABASE="${DBPREFIX}x4dat" +fi + +function die() { + echo $1 + exit 1 +} + +function confirm() { + 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_pipe_nodb() { + sed -e "s/#\([0-9a-z]*\)#/${DBPREFIX}\1/g" | $MYSQL +} + +function mysql_exec_nodb() { + echo -n " * executing $1 " + if [[ -z "${DRY_RUN}" ]]; then + (echo "$1" | mysql_pipe_nodb) || die "ERROR" + fi + echo "OK" +} + +function mysql_run() { + echo -n " * running $1 " + if [[ -z "${DRY_RUN}" ]]; then + (cat "$1" | mysql_pipe) || die "ERROR" + fi + echo "OK" +} + +function mysql_run_directory() { + for sql in $1/*.sql ; do + mysql_run $sql + done +} + +function script_run() { + 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 . }