Skip to content
Snippets Groups Projects
Commit 2073ab74 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-clean-scripts-daniel' into f-new-tools

parents 600363aa 4724ee70
No related branches found
No related tags found
No related merge requests found
......@@ -23,13 +23,14 @@
# # Commands
# The MySQL client program.
MYSQL_CMD=$(command -v mysql)
MYSQL_CMD=$(command -v mysql || echo "mysql not found!" >&2)
# The mysqladmin program which comes with the MySQL client.
MYSQLADMIN_CMD=$(command -v mysqladmin)
MYSQLADMIN_CMD=$(command -v mysqladmin || echo "mysqladmin not found!" >&2)
# The mysqldump program which comes with the MySQL client.
MYSQLDUMP_CMD=$(command -v mysqldump)
MYSQLDUMP_CMD=$(command -v mysqldump || echo "mysqldump not found!" >&2)
# The mysql_config_editor program which is used to store the credentials.
MYSQL_CONFIG_EDITOR_CMD=$(command -v mysql_config_editor)
MYSQL_CONFIG_EDITOR_CMD=$(command -v mysql_config_editor \
|| echo "mysql_config_editor not found!" >&2)
# # MySQL Connection
# The host of the MySQL server.
......
......@@ -24,12 +24,29 @@
# ** end header
#
#apply all available patches.
###############################################################################
# Apply all available patches #
###############################################################################
set -e
if [ -z "$UTILSPATH" ]; then
UTILSPATH=$(realpath "$(dirname $0)/../utils")
export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi
source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
PATCHES="./patch*/patch.sh"
for p in $PATCHES
do
echo "$p"
env | grep MYSQL | sort
export | grep MYSQL | sort
$p "$@" --patch=$p
done
......
......@@ -24,10 +24,11 @@
# Dump a database with all procedures, permissions, structure and data
if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi
# The directory which the dump is to be stored to. Do not change it here. Use
......
......@@ -2,7 +2,7 @@
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright 2019 Daniel Hornung
# Copyright 2019, 2020 Daniel Hornung
# Copyright 2020 Henrik tom Wörden, IndiScale GmbH
#
# This program is free software: you can redistribute it and/or modify
......@@ -19,15 +19,27 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
###############################################################################
# Helper function definitions #
###############################################################################
# When sourcing this file, the following variables must be set:
#
# MYSQL_CMD : source $UTILSPATH/load_settings.sh
function mysql_execute {
#TODO is it meaningful that here always the database user is used???
set +e
$MYSQL_CMD $(get_db_args) -e "$1"
ret=${PIPESTATUS[0]}
if [ "$ret" -ne 0 ]; then
failure "MYSQL ERROR"
fi
set -e
#TODO is it meaningful that here always the database user is used???
set +e
# env | sort
$MYSQL_CMD $(get_db_args) -e "$1"
ret=${PIPESTATUS[0]}
if [ "$ret" -ne 0 ]; then
failure "MYSQL ERROR"
fi
set -e
}
function get_mysql_args {
......
......@@ -18,9 +18,34 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
[[ -n "config.defaults" ]] && source "config.defaults"
[[ -n ".config" ]] && source ".config"
[[ -n "$ENV_FILE" ]] && source "$ENV_FILE"
# Load setting from different files, in this order:
# - config.defaults (in the current directory)
# - .config (in the current directory)
# - The file given in ENV_FILE.
if [ "$MAINPATH" ]; then
pushd "$MAINPATH" > /dev/null
pushed=1
fi
if [[ -r "config.defaults" ]] ; then
source "config.defaults"
fi
if [[ -r ".config" ]] ; then
source ".config"
fi
if [[ -n "$ENV_FILE" ]] ; then
source "$ENV_FILE"
fi
if [[ -z "$MYSQL_CMD" ]] ; then
echo "mysql not defined!"
exit 1
fi
if [ $pushed ]; then
popd > /dev/null
fi
export MYSQL_CMD
export MYSQLDUMP_CMD
......
......@@ -22,18 +22,20 @@
#
# ** end header
set -e
INSTALL_SQL_FILE="db_2_0.sql"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi
source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
set -e
function fail() {
echo "Some error occured, exiting."
exit 1
......@@ -131,6 +133,7 @@ function restore_db() {
}
function test-connection() {
echo $MYSQL_CMD $(get_mysql_args_nodb) -e "select 0;"
$MYSQL_CMD $(get_mysql_args_nodb) -e "select 0;"
}
......
......@@ -24,7 +24,8 @@
#header for patch scripts
# load useful functions #######################################################
. $UTILSPATH/helpers.sh
source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
USAGE="$1 [ --env=ENV_FILE ] [ --patch=PATCH ] [ --backupdir=BACKUPDIR ]\n\n"
CMD_OPTIONS=$(cat <<EOF
......
......@@ -24,7 +24,15 @@
# Updates all SQL procedures
if [ -z "$UTILSPATH" ]; then
UTILSPATH=$(realpath "$(dirname $0)")
export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi
source $UTILSPATH/helpers.sh
source $UTILSPATH/load_settings.sh
echo -n "updating rules ... "
set -e
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment