+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_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"
+}