Skip to content
Snippets Groups Projects
Unverified Commit f93a3735 authored by Daniel's avatar Daniel
Browse files

FIX: Runs in Docker again.

Also:

- More strict `set -e`
- Global path variables.
- A few more comments
- Copyright notices

== Technically, this is a big squash merge: ===

Squashed commit of the following:

commit 5c26e223e78192ba3d788ab2c640e8c3a1c73866
Author: Daniel <daniel@harvey>
Date:   Fri Mar 27 13:11:43 2020 +0100

    MAINT: No warning if mysql_config_editor can not be found.

commit 06c3f1d25e3bd1a37942f7f0630daac82c8a7738
Author: Daniel <daniel@harvey>
Date:   Fri Mar 27 12:57:15 2020 +0100

    MAINT: Moved `set -e` more to the front.

commit 68ad8469e0dd8c5dc3c4d93f41b4902e622f579f
Author: Daniel <daniel@harvey>
Date:   Fri Mar 27 12:56:37 2020 +0100

    MAINT: Removed debugging output, added copyright lines.

commit 7ed57cdaf1d1299b5cb8d412988409410eee9b45
Author: Daniel <daniel@harvey>
Date:   Fri Mar 27 11:59:37 2020 +0100

    MAINT: moved MAINPATH definition into load_settings.sh

commit b34f82812a59e8913d40d71c3ae34f3f0106fdf2
Author: Daniel <daniel@harvey>
Date:   Fri Mar 27 10:59:57 2020 +0100

    MAINT: A bit of cleanup.

commit 4a88516991f39091edf628bcad066b6873b347c0
Author: Daniel <daniel@harvey>
Date:   Fri Mar 27 09:35:16 2020 +0100

    STY: Whitespace fixup.

commit 4724ee70
Author: Henrik tom Wörden <henrik@trineo.org>
Date:   Fri Mar 27 08:22:53 2020 +0100

    FIX: added missing env setting in applypatches

commit 1d797300
Author: Henrik tom Wörden <henrik@trineo.org>
Date:   Fri Mar 27 08:18:47 2020 +0100

    MAINT: make calling skripts more cwd independent

commit c908d69b
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 19:48:58 2020 +0100

    MAINT: Failing fast if no SQL is found.

commit 2fa7d1bb
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 19:26:57 2020 +0100

    Debug

commit a520f4a2
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 19:22:48 2020 +0100

    Debug

commit fb60953d
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 19:10:56 2020 +0100

    FIX: Loading load_settings.sh

commit d1768287
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 19:01:40 2020 +0100

    DBG .

commit b1c5d47c
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 18:55:21 2020 +0100

    FIX: Load definitions first.

commit ed5c4d9c
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 18:44:03 2020 +0100

    DBG

commit 0763ef3a
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 18:19:40 2020 +0100

    FIX: Set UTILSPATH in applyPatches.sh

commit f351aceb
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 18:08:03 2020 +0100

    FIX: More strinct error handling, message if commands are not found.

commit 0338357e
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 17:26:04 2020 +0100

    DBG .

commit 8f0545c2
Author: Daniel <daniel@harvey>
Date:   Thu Mar 26 16:46:15 2020 +0100

    MAINT: Earlier set -e, also documentation.
parent e68951af
No related branches found
No related tags found
No related merge requests found
......@@ -23,13 +23,13 @@
# # 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 || true)
# # MySQL Connection
# The host of the MySQL server.
......
......@@ -6,6 +6,7 @@
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
......@@ -24,8 +25,20 @@
# ** end header
#
#apply all available patches.
###############################################################################
# Apply all available patches #
###############################################################################
set -e
if [ -z "$UTILSPATH" ]; then
UTILSPATH=$(realpath "$(dirname $0)/../utils")
export UTILSPATH
fi
source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
PATCHES="./patch*/patch.sh"
for p in $PATCHES
......
......@@ -5,6 +5,8 @@
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -24,10 +26,9 @@
# Dump a database with all procedures, permissions, structure and data
if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
fi
# The directory which the dump is to be stored to. Do not change it here. Use
# the --backupdir=./my/dir/ option or an environment variable instead.
......@@ -74,18 +75,18 @@ function backup() {
NARG_FILE="$2"
shift 2
# parameters: connection, database, outfile
if [ -e "$NARG_FILE" ]; then
failure "dumpfile already exists."
fi
# parameters: connection, database, outfile
if [ -e "$NARG_FILE" ]; then
failure "dumpfile already exists."
fi
echo "Dumping database $NARG_NAME to $NARG_FILE ... "
$MYSQLDUMP_CMD $(get_mysql_args_nodb) $* --opt --default-character-set=utf8 --routines \
$MYSQLDUMP_CMD $(get_mysql_args_nodb) $* --opt --default-character-set=utf8 --routines \
"$NARG_NAME" > "$NARG_FILE"
if [[ "$YAML" == "true" ]] ; then
yaml_success "$NARG_FILE" "$DATE"
fi
success
success
}
# Print a YAML failure message, if YAML is true.
......
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright 2019 Daniel Hornung
# Copyright 2020 Henrik tom Wörden, IndiScale GmbH
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2019, 2020 Daniel Hornung (d.hornung@indiscale.com)
# Copyright (C) 2020 Henrik tom Wörden
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -19,15 +20,25 @@
# 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
$MYSQL_CMD $(get_db_args) -e "$1"
ret=${PIPESTATUS[0]}
if [ "$ret" -ne 0 ]; then
failure "MYSQL ERROR"
fi
}
function get_mysql_args {
......
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright 2019 Daniel Hornung
# Copyright 2020 Henrik tom Wörden, IndiScale GmbH
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2019, 2020 Daniel Hornung (d.hornung@indiscale.com)
# Copyright (C) 2020 Henrik tom Wörden
# Copyright (C) 2020 IndiScale GmbH <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -18,9 +19,33 @@
# 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 [ -z "$MAINPATH" ]; then
if [ -z "$UTILSPATH" ] ; then
echo "At least one of MAINPATH and UTILSPATH must be defined in load_settings.sh" >&2
exit 1
fi
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi
source "$MAINPATH/config.defaults"
if [[ -r "$MAINPATH/.config" ]] ; then
source "$MAINPATH/.config"
fi
if [[ -n "$ENV_FILE" ]] ; then
source "$ENV_FILE"
fi
if [[ -z "$MYSQL_CMD" ]] ; then
echo "'mysql' executable not defined!"
exit 1
fi
export MYSQL_CMD
export MYSQLDUMP_CMD
......
......@@ -3,8 +3,9 @@
# ** header v3.0
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2019 Daniel Hornung, Göttingen
# Copyright (C) 2019, 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2020 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
......@@ -22,23 +23,18 @@
#
# ** end header
set -e
INSTALL_SQL_FILE="db_2_0.sql"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
fi
source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
set -e
function fail() {
echo "Some error occured, exiting."
exit 1
}
UNITTEST_DATABASE=${UNITTEST_DATABASE-_caosdb_schema_unit_tests}
# optional parameter: [--fresh] for installing a fresh data base. Otherwise an existing one would be reused.
......@@ -48,7 +44,7 @@ function runtests() {
_install_unit_test_database $@
_execute_tests || ( echo "[FAILURE]" && exit 1 )
_execute_tests || ( failure )
echo "[PASS]"
}
......@@ -113,22 +109,24 @@ function _setup_mytap() {
}
function setup_os() {
# - mariadb-client :: For SQL server configuration.
PACKAGES="git
make
mariadb-client
maven
openjdk-8-jdk-headless
python3-pip
screen
unzip
"
# - vim :: For debugging
PACKAGES+="vim
"
apt-get update
apt-get dist-upgrade -y
apt-get install -y $PACKAGES
# - mariadb-client :: For SQL server configuration.
PACKAGES="
git
make
mariadb-client
maven
openjdk-8-jdk-headless
python3-pip
screen
unzip
"
# - vim :: For debugging
PACKAGES+="
vim
"
apt-get update
apt-get dist-upgrade -y
apt-get install -y $PACKAGES
}
function install_db() {
......@@ -140,7 +138,7 @@ Call 'make drop-$DATABASE_NAME' to delete that database or reconfigure with
exit 0
fi
sed "s/db_2_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb)
sed "s/db_2_0/$DATABASE_NAME/g" "$INSTALL_SQL_FILE" | $MYSQL_CMD $(get_mysql_args_nodb)
}
# Inserts the dump (arg 1) into the database
......@@ -160,7 +158,7 @@ function grant() {
while true; do
read -p "Please enter the password for ${DATABASE_USER}: " \
-s password
echo
echo
read -p "Please repeat the password: " -s password2
echo
[[ "$password" == "$password2" ]] && {
......@@ -174,7 +172,7 @@ function grant() {
if [[ "$1" == "--strict" ]] ; then
for host in ${DATABASE_USER_HOST_LIST//,/ } ; do
CMD="SELECT COUNT(*) FROM mysql.user WHERE user='${DATABASE_USER}' AND host='${host}';"
[[ $($MYSQL_CMD $(get_mysql_args_nodb) -s -N -e "$CMD") == 0 ]] || {
[[ $($MYSQL_CMD $(get_mysql_args_nodb) -s -N -e "$CMD") == 0 ]] || {
echo "The user '${DATABASE_USER}@${host}' is already in the database."
echo "Please use another user or delete it, e.g. with"
echo "'mysql -u ${MYSQL_USER} -p -e \"DROP USER ${DATABASE_USER}@${host};\"'"
......@@ -215,12 +213,12 @@ function _db_exists() {
case $1 in
"drop") drop $2 ;;
"grant") grant $2 ;;
"test") shift ; runtests $@ ;;
"test-connection") test-connection ;;
"install_db") install_db ;;
"restore_db") restore_db $2 ;;
# "prep_sql") prepare_sql ;;
*) echo "Unknown action: $1"
"drop") drop $2 ;;
"grant") grant $2 ;;
"test") shift ; runtests $@ ;;
"test-connection") test-connection ;;
"install_db") install_db ;;
"restore_db") restore_db $2 ;;
# "prep_sql") prepare_sql ;;
*) echo "Unknown action: $1"
esac
......@@ -4,7 +4,9 @@
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright 2019 Daniel Hornung
# Copyright (C) 2019, 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -21,10 +23,16 @@
#
# ** end header
#
#header for patch scripts
###############################################################################
# header for patch scripts #
###############################################################################
set -e
# 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
......@@ -56,7 +64,6 @@ configuration make file. Notable examples are:
EOF
)
set -e
function _print_help() {
echo -e "$USAGE"
......
......@@ -4,7 +4,10 @@
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright (C) 2020 Daniel Hornung <d.hornung@indiscale.com>
# Copyright (C) 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -24,16 +27,21 @@
# Updates all SQL procedures
set -e
if [ -z "$UTILSPATH" ]; then
UTILSPATH=$(realpath "$(dirname $0)")
export UTILSPATH
fi
source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
echo -n "updating rules ... "
set -e
mysql_execute "$(sed s/db_2_0/$DATABASE_NAME/g rules.sql)"
echo "OK"
echo -n "updating procedures ... "
mysql_execute "$(sed s/db_2_0/$DATABASE_NAME/g procedures/*.sql procedures/query/*.sql)"
mysql_execute "$(sed s/db_2_0/$DATABASE_NAME/g procedures/*.sql procedures/query/*.sql)"
echo "OK"
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