summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--bin/README.md7
-rw-r--r--bin/bash_shared/includes.sh5
-rwxr-xr-xbin/db_assembler/db_assembler.sh1
-rw-r--r--bin/db_exporter/.gitignore1
-rwxr-xr-xbin/db_exporter/db_export.sh45
-rw-r--r--conf/config.sh.dist21
-rw-r--r--modules/hw-core/bash-lib-event/src/hooks.sh (renamed from bin/bash_shared/functions.sh)4
-rwxr-xr-xmodules/hw-core/bash-lib-git/bin/git-subtree-list7
-rw-r--r--modules/hw-core/bash-lib-git/src/subtree.sh3
-rw-r--r--modules/uwd/mysql-tools/.gitignore13
-rw-r--r--modules/uwd/mysql-tools/README53
-rwxr-xr-xmodules/uwd/mysql-tools/bin/dump-parserbin0 -> 13355 bytes
-rw-r--r--modules/uwd/mysql-tools/bin/mysql.exebin0 -> 4094976 bytes
-rw-r--r--modules/uwd/mysql-tools/bin/mysqldump.exebin0 -> 4079104 bytes
-rw-r--r--modules/uwd/mysql-tools/bin/mysqlimport.exebin0 -> 4013056 bytes
-rw-r--r--modules/uwd/mysql-tools/build-dump-parser.sh5
-rw-r--r--modules/uwd/mysql-tools/dump-parser.c129
-rw-r--r--modules/uwd/mysql-tools/mysql-config.dist62
-rw-r--r--modules/uwd/mysql-tools/mysql-dump119
-rw-r--r--modules/uwd/mysql-tools/mysql-import109
-rw-r--r--modules/uwd/mysql-tools/mysql-tools23
-rw-r--r--modules/uwd/mysql-tools/shared-def34
23 files changed, 638 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 3521a66dc7..f0bb2e3a7a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -15,6 +15,7 @@ modules/*/*
!modules/uwd/*
!modules/uwd/cmake-utils/*
modules/uwd/joiner
+!modules/hw-core/*
!modules/acore/*
build*/
diff --git a/bin/README.md b/bin/README.md
new file mode 100644
index 0000000000..81af2e053f
--- /dev/null
+++ b/bin/README.md
@@ -0,0 +1,7 @@
+All bash script here must be compatible with following environments:
+
+- *linux*: bash 4.x
+
+- *windows*: git for windows 2.9.3
+
+- *osx*
diff --git a/bin/bash_shared/includes.sh b/bin/bash_shared/includes.sh
index bd4e124e21..21e28ff508 100644
--- a/bin/bash_shared/includes.sh
+++ b/bin/bash_shared/includes.sh
@@ -4,7 +4,10 @@ AC_PATH_SHARED="$AC_PATH_BIN/bash_shared"
source "$AC_PATH_SHARED/defines.sh"
-source "$AC_PATH_SHARED/functions.sh"
+source "$AC_PATH_MODULES/hw-core/bash-lib-event/src/hooks.sh"
+
+alias registerHooks="hwc_event_register_hooks"
+alias runHooks="hwc_event_run_hooks"
source "$AC_PATH_CONF/config.sh.dist" # "hack" to avoid missing conf variables
diff --git a/bin/db_assembler/db_assembler.sh b/bin/db_assembler/db_assembler.sh
index d5bf3fac1f..5a62ccc48d 100755
--- a/bin/db_assembler/db_assembler.sh
+++ b/bin/db_assembler/db_assembler.sh
@@ -13,7 +13,6 @@ if [ -f "./config.sh" ]; then
source "./config.sh" # should overwrite previous
fi
-unamestr=`uname`
if [[ "$unamestr" == 'Darwin' ]]; then
MD5_CMD="md5"
else
diff --git a/bin/db_exporter/.gitignore b/bin/db_exporter/.gitignore
new file mode 100644
index 0000000000..cdd7c19c8d
--- /dev/null
+++ b/bin/db_exporter/.gitignore
@@ -0,0 +1 @@
+config.sh
diff --git a/bin/db_exporter/db_export.sh b/bin/db_exporter/db_export.sh
new file mode 100755
index 0000000000..e419d38bf2
--- /dev/null
+++ b/bin/db_exporter/db_export.sh
@@ -0,0 +1,45 @@
+#!/bin/bash
+
+ROOTPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../../" && pwd )"
+
+source $ROOTPATH"/bin/bash_shared/includes.sh"
+
+if [ -f "./config.sh" ]; then
+ source "./config.sh" # should overwrite previous
+fi
+
+echo "===== STARTING PROCESS ====="
+
+
+function export() {
+ echo "Working on: "$1
+ database=$1
+
+ var_base_path="DB_"$database"_PATHS"
+ base_path=${!var_base_path}
+
+ base_conf="TPATH="$base_path";\
+ CLEANFOLDER=1; \
+ CHMODE=0; \
+ TEXTDUMPS=0; \
+ PARSEDUMP=1; \
+ FULL=0; \
+ DUMPOPTS='--skip-comments --skip-set-charset --routines --extended-insert --order-by-primary --single-transaction --quick'; \
+ "
+
+ var_base_conf="DB_"$database"_CONF"
+ base_conf=$base_conf${!var_base_conf}
+
+ var_base_name="DB_"$database"_NAME"
+ base_name=${!var_base_name}
+
+
+ bash $AC_PATH_MODULES"/uwd/mysql-tools/mysql-tools" dump "" $base_name "" "$base_conf"
+}
+
+for db in ${DATABASES[@]}
+do
+ export "$db"
+done
+
+echo "===== DONE ====="
diff --git a/conf/config.sh.dist b/conf/config.sh.dist
index 7e16328574..3a0f46a802 100644
--- a/conf/config.sh.dist
+++ b/conf/config.sh.dist
@@ -100,14 +100,35 @@ DB_CHARACTERS_PATHS=(
$SRCPATH"/data/sql/base/characters"
)
+DB_CHARACTERS_NAME="characters"
+
+DB_CHARACTERS_CONF="MYSQL_USER='root'; \
+ MYSQL_PASS='root'; \
+ MYSQL_HOST='localhost';\
+ "
+
DB_AUTH_PATHS=(
$SRCPATH"/data/sql/base/auth/"
)
+DB_AUTH_NAME="auth"
+
+DB_AUTH_CONF="MYSQL_USER='root'; \
+ MYSQL_PASS='root'; \
+ MYSQL_HOST='localhost';\
+ "
+
DB_WORLD_PATHS=(
$SRCPATH"/data/sql/base/world/"
)
+DB_WORLD_NAME="world"
+
+DB_WORLD_CONF="MYSQL_USER='root'; \
+ MYSQL_PASS='root'; \
+ MYSQL_HOST='localhost';\
+ "
+
# UPDATES
DB_CHARACTERS_UPDATE_PATHS=(
$SRCPATH"/data/sql/updates/characters/"
diff --git a/bin/bash_shared/functions.sh b/modules/hw-core/bash-lib-event/src/hooks.sh
index 6da557adea..b791a600fb 100644
--- a/bin/bash_shared/functions.sh
+++ b/modules/hw-core/bash-lib-event/src/hooks.sh
@@ -1,5 +1,5 @@
# par 1: hook_name
-function runHooks() {
+function hwc_event_run_hooks() {
hook_name="HOOKS_MAP_$1"
read -r -a SRCS <<< ${!hook_name}
echo "Running hooks: $hook_name"
@@ -9,7 +9,7 @@ function runHooks() {
done
}
-function registerHooks() {
+function hwc_event_register_hooks() {
hook_name="HOOKS_MAP_$1"
hooks=${@:2}
declare -g "$hook_name+=$hooks "
diff --git a/modules/hw-core/bash-lib-git/bin/git-subtree-list b/modules/hw-core/bash-lib-git/bin/git-subtree-list
new file mode 100755
index 0000000000..d3af413e9c
--- /dev/null
+++ b/modules/hw-core/bash-lib-git/bin/git-subtree-list
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+source $CUR_DIR"/../src/subtree.sh"
+
+hwc_git_subtree_list
diff --git a/modules/hw-core/bash-lib-git/src/subtree.sh b/modules/hw-core/bash-lib-git/src/subtree.sh
new file mode 100644
index 0000000000..08820e6405
--- /dev/null
+++ b/modules/hw-core/bash-lib-git/src/subtree.sh
@@ -0,0 +1,3 @@
+function hwc_git_subtree_list() {
+ git log | grep git-subtree-dir | tr -d ' ' | cut -d ":" -f2 | sort | uniq
+}
diff --git a/modules/uwd/mysql-tools/.gitignore b/modules/uwd/mysql-tools/.gitignore
new file mode 100644
index 0000000000..fa1ea4671a
--- /dev/null
+++ b/modules/uwd/mysql-tools/.gitignore
@@ -0,0 +1,13 @@
+/mysql_config
+mysql_tools_(for usr-local-bin)
+
+#
+# Editors / debuggers / other output files
+#
+*~
+*.bak
+*.orig
+*.patch
+callgrind.out.*
+
+.upt.json
diff --git a/modules/uwd/mysql-tools/README b/modules/uwd/mysql-tools/README
new file mode 100644
index 0000000000..453829ce72
--- /dev/null
+++ b/modules/uwd/mysql-tools/README
@@ -0,0 +1,53 @@
+* Copyright (C) 2007 - 2015 Hyperweb2 All rights reserved.
+* GNU General Public License version 3; see www.hyperweb2.com/terms/
+
+#
+# HOW TO USE MYSQL_* tools
+#
+
+Before starting to dump/import, please rename mysql_config.dist in mysql_config and change infos using your configurations
+If you are using AppArmor , edit /etc/apparmor.d/usr.sbin.mysqld and add directory that must be used by the dump
+
+to easy dump/import the database, use ./mysql-tools command that includes dump and import scripts, instead if you need to separate the functions ,
+ use ./mysql-dump and ./mysql-import.
+
+mysql-tools utilization:
+
+# This script automatically dump and import sql files
+#
+# syntax: ./mysql_tools <opt> <database> <tables> <method> <configpath>
+# OPT -> dump/import ( export / import tables )
+# TABLES -> use "," to separate table names; ex: mysql_dump "" "table1,table2..tableN". Leave blank to dump all tables.
+# DATABASE -> specify database to process, use "" for default ( see in mysql-config )
+# METHOD -> 0/1 (0: no fulldb,1: use fulldb) default: ( see in mysql-config )
+# CONFIGPATH -> specify alternative path of config file, use "" to check in source folder
+#
+
+
+mysql-dump utilization:
+
+# This script will export all tables from specified db and tables in separated sql files
+# it can also export the full db in a single sql file.
+#
+# syntax: ./mysql_dump <database> <tables> <method> <configpath>
+# options are not required, because values can be defined in config file:
+# DATABASE -> specify database to dump, use "" for default ( see in mysql-config )
+# TABLES -> use "" to dump all tables. Use "," to separate table names; ex: mysql_dump "" "table1,table2..tableN"
+# METHOD -> 0/1 (0: no fulldb,1: with fulldb) default: ( see in mysql-config )
+# CONFIGPATH -> specify alternative path for config file, use "" to check in source folder.
+#
+
+
+mysql-import utilization:
+
+# This script will import the contents of the sql/ directory to the MySQL database.
+# You can choose to import table by table, or the entire db
+#
+# syntax: ./mysql_import <database> <tables> <method> <configpath>
+# options are not required, because values can be defined in config file:
+#
+# DATABASE -> specify database to dump, use "" for default ( see in mysql-config )
+# TABLES -> use "," to separate table names; ex: mysql_dump "" "table1,table2..tableN" ..OR use "" to dump all tables.
+# METHOD -> 1/0 ( 1: by folder, 0: by full dump) default: ( see in mysql-config )
+# CONFIGPATH -> specify alternative path for config file, use "" to check in source folder.
+#
diff --git a/modules/uwd/mysql-tools/bin/dump-parser b/modules/uwd/mysql-tools/bin/dump-parser
new file mode 100755
index 0000000000..6d07b528f1
--- /dev/null
+++ b/modules/uwd/mysql-tools/bin/dump-parser
Binary files differ
diff --git a/modules/uwd/mysql-tools/bin/mysql.exe b/modules/uwd/mysql-tools/bin/mysql.exe
new file mode 100644
index 0000000000..66267a989a
--- /dev/null
+++ b/modules/uwd/mysql-tools/bin/mysql.exe
Binary files differ
diff --git a/modules/uwd/mysql-tools/bin/mysqldump.exe b/modules/uwd/mysql-tools/bin/mysqldump.exe
new file mode 100644
index 0000000000..24355c07c3
--- /dev/null
+++ b/modules/uwd/mysql-tools/bin/mysqldump.exe
Binary files differ
diff --git a/modules/uwd/mysql-tools/bin/mysqlimport.exe b/modules/uwd/mysql-tools/bin/mysqlimport.exe
new file mode 100644
index 0000000000..8dc3613870
--- /dev/null
+++ b/modules/uwd/mysql-tools/bin/mysqlimport.exe
Binary files differ
diff --git a/modules/uwd/mysql-tools/build-dump-parser.sh b/modules/uwd/mysql-tools/build-dump-parser.sh
new file mode 100644
index 0000000000..a38a195f81
--- /dev/null
+++ b/modules/uwd/mysql-tools/build-dump-parser.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+gcc -O2 -Wall -pedantic dump-parser.c -o ./bin/dump-parser
+
+read -p "done"
diff --git a/modules/uwd/mysql-tools/dump-parser.c b/modules/uwd/mysql-tools/dump-parser.c
new file mode 100644
index 0000000000..a9262d4f92
--- /dev/null
+++ b/modules/uwd/mysql-tools/dump-parser.c
@@ -0,0 +1,129 @@
+/* gcc -O2 -Wall -pedantic dump-parser.c -o dump-parser
+ Usage: cat dump.sql | dump-parser
+ Or : dump-parser dump.sql
+ bugs :
+ * the parser will fail if the 10001st character of a line is an escaped quote, it will see it as an unescaped quote.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdbool.h>
+#include <string.h>
+
+#define BUFFER 100000
+
+bool is_escaped(char* string, int offset) {
+ if (offset == 0) {
+ return false;
+ } else if (string[offset - 1] == '\\') {
+ return !is_escaped(string, offset - 1);
+ } else {
+ return false;
+ }
+}
+
+bool is_commented(char* string) {
+ char buffer[4];
+
+ sprintf(buffer, "%.3s", string);
+
+ return strcmp(buffer, "-- ") == 0;
+}
+
+int main(int argc, char *argv[])
+{
+ FILE* file = argc > 1 ? fopen(argv[1], "r") : stdin;
+
+ char buffer[BUFFER];
+ char* line;
+ int pos;
+ int parenthesis = 0;
+ bool quote = false;
+ bool escape = false;
+ bool comment = false;
+
+ while (fgets(buffer, BUFFER, file) != NULL) {
+ line = buffer;
+
+ /* skip commented */
+ if (comment || is_commented(line)) {
+ comment = line[strlen(line) - 1] != '\n';
+ fputs(line, stdout);
+ } else {
+ pos = 0;
+
+ nullchar:
+ while (line[pos] != '\0') {
+ /* if we are still in escape state, we need to check first char. */
+ if (!escape) {
+ /* find any character in ()' */
+ pos = strcspn(line, "()'\\");
+ }
+
+ if (pos > 0) {
+ /* print before match */
+ printf("%.*s", pos, line);
+ }
+
+ switch (line[pos]) {
+ case '(':
+ if (!quote) {
+ if (parenthesis == 0) {
+ putchar('\n');
+ }
+ parenthesis++;
+ }
+ if (escape) {
+ escape = false;
+ }
+ break;
+
+ case ')':
+ if (!quote) {
+ if (parenthesis > 0) {
+ parenthesis--;
+ } else {
+ /* whoops */
+ puts("\n");
+ fputs(line, stdout);
+ fputs("Found closing parenthesis without opening one.\n", stderr);
+ exit(1);
+ }
+ }
+ if (escape) {
+ escape = false;
+ }
+ break;
+
+ case '\\':
+ escape = !escape;
+ break;
+
+ case '\'':
+ if (escape) {
+ escape = false;
+ } else {
+ quote = !quote;
+ }
+ break;
+
+ case '\0':
+ goto nullchar;
+
+ default:
+ if (escape) {
+ escape = false;
+ }
+ break;
+ }
+
+ /* print char then skip it (to make sure we don’t double match) */
+ putchar(line[pos]);
+ line = line + pos + 1;
+ pos = 0;
+ }
+ }
+ }
+
+ return 0;
+}
diff --git a/modules/uwd/mysql-tools/mysql-config.dist b/modules/uwd/mysql-tools/mysql-config.dist
new file mode 100644
index 0000000000..ca71fc41ea
--- /dev/null
+++ b/modules/uwd/mysql-tools/mysql-config.dist
@@ -0,0 +1,62 @@
+#!/bin/bash
+#
+# * Copyright (C) 2007 - 2015 Hyperweb2 All rights reserved.
+# * GNU General Public License version 3; see www.hyperweb2.com/terms/
+#
+# This file contains login/password information for accessing the MySQL database
+# and is used by all the mysql_* scripts.
+#
+
+#
+# MYSQL
+#
+
+# change these lines with your mysql config
+MYSQL_DB=test
+MYSQL_USER=usr
+MYSQL_PASS=pwd
+MYSQL_HOST=localhost
+#MYSQL_SOCK=/var/lib/mysql/mysql.sock
+
+#
+# File Options
+#
+
+# path of directory where extract separated tables ( without end slash )
+TPATH=./tables
+
+# (boolean) clean directory before dump, in this way non-existant db tables will be deleted
+CLEANFOLDER=1
+
+# path of file to extract database full dump
+FPATH=./full/full.sql
+
+# (boolean) switch to enable(1)/disable(0) the dump/import of full db file
+# ( you can do it manually using command parameters )
+FULL=0
+
+# (boolean) set 1 to enable --tab option for mysqldump and import data from it
+# it's very fast import/export process but doesn't utilize the insert query
+# NOTE: full db continue to be dumped with normal sql format
+# NOTE2: if you have problem with permissions ( mysql errorcode:13) mostly in linux
+# you should enable CHMODE config and disable/edit
+# some protections such as AppArmor in Ubuntu or SELinux in Fedora..
+
+TEXTDUMPS=1
+
+# (boolean) allow to change "TPATH" folder permissions to enable mysql server writing
+
+CHMODE=0
+
+
+#
+# TOOLS OPTIONS
+#
+
+#number of threads you want to use in TEXT import mode ( you can safely set it to your number of processor increasing process speed )
+THREADS=1
+
+IMPORTOPTS_TEXT="--use-threads=$THREADS --local --compress --delete --lock-tables"
+
+DUMPOPTS="--skip-comments --skip-set-charset --extended-insert --order-by-primary --single-transaction --quick"
+
diff --git a/modules/uwd/mysql-tools/mysql-dump b/modules/uwd/mysql-tools/mysql-dump
new file mode 100644
index 0000000000..33e5e35aca
--- /dev/null
+++ b/modules/uwd/mysql-tools/mysql-dump
@@ -0,0 +1,119 @@
+#!/bin/bash
+#
+# * Copyright (C) 2007 - 2015 Hyperweb2 All rights reserved.
+# * GNU General Public License version 3; see www.hyperweb2.com/terms/
+
+echo "starting dump process.."
+# check config from same folder and include only if exists
+CONF_FILE=$MT_DIR"/mysql-config"
+if [ -f "$CONF_FILE" ]; then
+ source "$CONF_FILE"
+fi;
+
+#overwrite configs if file exists and variables are defined
+if [ ! -z "$4" ]; then
+ if [ -e "$4" ]; then
+ source "$4"
+ else # if 4th parameter is not a file, then try to eval
+ eval "$4"
+ fi;
+fi;
+
+source $MT_DIR"/shared-def"
+
+if [ ! -z "$1" ]; then
+ MYSQL_DB=$1;
+fi
+
+#change group instead mod
+#group=`ls -l tables | awk '{print $4}'`
+#if [ $group != "mysql" ]; then
+# if (($CHMODE != 0)); then
+# sudo chgrp -v mysql $TPATH
+# fi
+#fi
+
+#change permissions for other users
+if [ ! -z $TPATH ]; then
+ if [ ! -d "$TPATH" ]; then
+ #create the path recursively
+ echo "creating dir: $TPATH.."
+ mkdir -p "$TPATH"
+ fi
+
+ if (($CHMODE != 0)); then
+ echo "changing permissions.."
+ sudo chmod -v o=rwx $TPATH
+ fi
+
+ #clean old tables
+ if (($CLEANFOLDER != 0)); then
+ rm -rvf $TPATH/*
+ fi
+
+ if [ ! -z "$2" ]; then
+ #if tables are specified in parameters then..
+ arr=$(echo $2 | tr "," "\n")
+
+ for T in $arr
+ do
+ echo "exporting "$T;
+ if (($TEXTDUMPS != 1)); then
+ FILE="$TPATH/$T.sql"
+ if [ -f $FILE ]; then
+ rm -f $FILE
+ fi
+
+ if (($PARSEDUMP != 0)); then
+ echo "Parsing enabled";
+ eval "$MYSQLDUMP$OPTS $DUMPOPTS '$MYSQL_DB' '$T' | $DUMPPARSER > $FILE"
+ else
+ eval "$MYSQLDUMP$OPTS $DUMPOPTS '$MYSQL_DB' '$T' -r $FILE"
+ fi
+ else
+ echo $(eval "$MYSQLDUMP$OPTS $DUMPOPTS --tab=$TPATH/ '$MYSQL_DB' '$T'")
+ fi
+ done
+
+ else
+ #else get all tables from selected db
+ CMD="$MYSQL$OPTS -N -B -e 'show tables from \`$MYSQL_DB\`'"
+ echo "command: "$CMD
+ for T in $(eval $CMD)
+ do
+ if (($TEXTDUMPS != 1)); then
+ echo "exporting "$T;
+ FILE="$TPATH/$T.sql"
+ if [ -f $FILE ]; then
+ rm -f $FILE
+ fi
+
+ if (($PARSEDUMP != 0)); then
+ echo "Parsing enabled on file "$FILE;
+ eval "$MYSQLDUMP$OPTS $DUMPOPTS '$MYSQL_DB' '$T' | $DUMPPARSER > $FILE"
+ else
+ eval "$MYSQLDUMP$OPTS $DUMPOPTS '$MYSQL_DB' '$T' -r $FILE"
+ fi
+ else
+ echo "exporting "$MYSQL_DB" tables: "$T;
+ echo $(eval "$MYSQLDUMP$OPTS $DUMPOPTS --tab=$TPATH/ '$MYSQL_DB' '$T'")
+ fi
+ done;
+
+ fi
+fi
+
+if [ ! -z "$3" ]; then FULL=$3; fi
+# export full file if option is enabled
+if (($FULL != 0)); then
+ echo 'exporting FULL '$MYSQL_DB' in single file';
+ rm -f $FPATH
+
+ if (($PARSEDUMP != 0)); then
+ echo "Parsing enabled";
+ eval "$MYSQLDUMP$OPTS $DUMPOPTS '$MYSQL_DB' | $DUMPPARSER > $FPATH"
+ else
+ eval "$MYSQLDUMP$OPTS $DUMPOPTS '$MYSQL_DB' -r $FPATH"
+ fi
+fi
+
diff --git a/modules/uwd/mysql-tools/mysql-import b/modules/uwd/mysql-tools/mysql-import
new file mode 100644
index 0000000000..ad05e1bd05
--- /dev/null
+++ b/modules/uwd/mysql-tools/mysql-import
@@ -0,0 +1,109 @@
+#!/bin/bash
+#
+# * Copyright (C) 2007 - 2015 Hyperweb2 All rights reserved.
+# * GNU General Public License version 3; see www.hyperweb2.com/terms/
+
+echo "starting import process.."
+# check config from same folder and include only if exists
+CONF_FILE=$MT_DIR"/mysql-config"
+if [ -f "$CONF_FILE" ]; then
+ source "$CONF_FILE"
+fi;
+
+#overwrite configs if file exists and variables are defined
+if [ ! -z "$4" ]; then
+ if [ -e "$4" ]; then
+ source "$4"
+ else # if 4th parameter is not a file, then try to eval
+ eval "$4"
+ fi;
+fi;
+
+source $MT_DIR"/shared-def"
+
+if [ ! -z "$1" ]; then
+ MYSQL_DB=$1;
+fi
+
+# Table prefix ( to implement )
+PFX=
+
+# par 1 : db_name
+function checkdb {
+ # Check if database exists
+ err=`echo "quit" | $(eval "$MYSQL$OPTS '$1'") 2>&1`
+ if [ $? != 0 ]; then
+ if echo "$err" | grep -q "Access denied"; then
+ echo -e "\nDATABASE $1 EXISTS BUT USER $MYSQL_USER DOES NOT HAVE ACCESS TO IT, ABORTING"
+ exit
+ fi
+ echo -n "[creating $1]"
+ if ! echo "CREATE DATABASE $1;" | $(eval "$MYSQL$OPTS" ) 2>/dev/null ; then
+ echo -e "\nDATABASE $1 DOES NOT EXIST AND I FAILED TO CREATE IT, ABORTING"
+ exit
+ fi
+ fi
+}
+
+#par1: is_text_file ; par2: file
+function import
+{
+ echo "Importing $2 into $MYSQL_DB (text: $1) ..."
+
+ SQL="SET FOREIGN_KEY_CHECKS = 0;"
+ #eval "$MYSQL$OPTS -e \"SET FOREIGN_KEY_CHECKS = 0\" '$MYSQL_DB'" #disable foreign check
+
+ FILE=$2
+ if (($1 != 0)); then
+ #eval "$MYSQLIMPORT$OPTS $IMPORTOPTS_TEXT '$MYSQL_DB' $2"
+ TABLE=${FILE##*/}
+ TABLE=${TABLE%.txt}
+ SQL+="LOAD DATA LOCAL INFILE '$2' INTO TABLE $MYSQL_DB.$TABLE;"
+ else
+ #eval "$MYSQL$OPTS '$MYSQL_DB'" < "$2"
+ SQL+="SOURCE $2;"
+ fi
+ #eval "$MYSQL$OPTS -e \"SET FOREIGN_KEY_CHECKS = 1\" '$MYSQL_DB'" #enable foreign check
+ SQL+="SET FOREIGN_KEY_CHECKS = 1";
+
+ eval "$MYSQL$OPTS -e \"$SQL\" '$MYSQL_DB'"
+
+ echo " done"
+}
+
+if [ ! -z "$1" ]; then
+ DB=$1;
+fi
+
+checkdb $MYSQL_DB
+
+if [ ! -z "$2" ]; then
+ tables=$(echo $2 | tr "," "\n")
+fi
+if [ ! -z "$3" ]; then
+ FULL=$3;
+fi
+
+if (($FULL != 0)); then
+ echo "importing full world file"
+ $(eval "$MYSQL$OPTS '$MYSQL_DB'") < $FPATH
+else
+ if [ ! -z "$2" ]; then
+ import "0" "$TPATH/$2.sql" # TODO we should check if it's a set of tables before
+ if (($TEXTDUMPS != 0)); then
+ for x in $TPATH/*.txt; do
+ import "1" "$x"
+ done
+ fi
+ else
+ for x in $TPATH/*.sql; do
+ import "0" "$x"
+ done
+
+ if (($TEXTDUMPS != 0)); then
+ for x in $TPATH/*.txt; do
+ import "1" "$x"
+ done
+ fi
+ fi
+fi
diff --git a/modules/uwd/mysql-tools/mysql-tools b/modules/uwd/mysql-tools/mysql-tools
new file mode 100644
index 0000000000..6f2fad77c6
--- /dev/null
+++ b/modules/uwd/mysql-tools/mysql-tools
@@ -0,0 +1,23 @@
+#!/bin/bash
+#
+# * Copyright (C) 2007 - 2015 Hyperweb2 All rights reserved.
+# * GNU General Public License version 3; see www.hyperweb2.com/terms/
+
+MT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+
+function main {
+ if [ ! -z "$1" ]; then
+ if [ "$1" == "dump" ]; then
+ source $MT_DIR"/mysql-dump" "$3" "$2" "$4" "$5"
+ return
+ elif [ "$1" == "import" ]; then
+ source $MT_DIR"/mysql-import" "$3" "$2" "$4" "$5"
+ return
+ fi
+ else
+ echo "!!no command specified!!"
+ fi
+}
+
+# OPT - Tables - database - full file - config path
+main "$1" "$2" "$3" "$4" "$5"
diff --git a/modules/uwd/mysql-tools/shared-def b/modules/uwd/mysql-tools/shared-def
new file mode 100644
index 0000000000..6742fcf3b8
--- /dev/null
+++ b/modules/uwd/mysql-tools/shared-def
@@ -0,0 +1,34 @@
+#!/bin/bash
+#
+# * Copyright (C) 2007 - 2015 Hyperweb2 All rights reserved.
+# * GNU General Public License version 3; see www.hyperweb2.com/terms/
+
+MYSQL="mysql"
+MYSQLIMPORT="mysqlimport"
+MYSQLDUMP="mysqldump"
+DUMPPARSER=$MT_DIR"/bin/dump-parser"
+
+#empty for bash commands
+WIN_BIN=0
+command -v mysql >/dev/null 2>&1 || { WIN_BIN=1; }
+command -v mysqlimport >/dev/null 2>&1 || { WIN_BIN=1; }
+command -v mysqldump >/dev/null 2>&1 || { WIN_BIN=1; }
+
+WIN_BIN=1
+if [ `uname -s` == "Linux" ]; then
+ WIN_BIN=0
+else
+ WIN_BIN=1
+fi;
+
+if (($WIN_BIN != 0)); then
+ MYSQL=$MT_DIR"/bin/$MYSQL"
+ MYSQLIMPORT=$MT_DIR"/bin/$MYSQLIMPORT"
+ MYSQLDUMP=$MT_DIR"/bin/$MYSQLDUMP"
+fi;
+
+OPTS=
+[ ! -z "$MYSQL_USER" ] && OPTS+=" -u $MYSQL_USER"
+[ ! -z "$MYSQL_PASS" ] && OPTS+=" -p$MYSQL_PASS"
+[ ! -z "$MYSQL_HOST" ] && OPTS+=" -h $MYSQL_HOST"
+[ ! -z "$MYSQL_SOCK" ] && OPTS+=" -S $MYSQL_SOCK"