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

Merge branch 's-clean-up-stage' into f-new-tools

parents 084a0240 bac0a91e
No related branches found
No related tags found
No related merge requests found
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
# Copyright (C) 2018 Research Group Biomedical Physics, # 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 Timm Fitschen <t.fitschen@indiscale.com> # 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> # Copyright (C) 2020 IndiScale <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
...@@ -33,8 +34,6 @@ set -e ...@@ -33,8 +34,6 @@ set -e
if [ -z "$UTILSPATH" ]; then if [ -z "$UTILSPATH" ]; then
UTILSPATH=$(realpath "$(dirname $0)/../utils") UTILSPATH=$(realpath "$(dirname $0)/../utils")
export UTILSPATH export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi fi
source $UTILSPATH/load_settings.sh source $UTILSPATH/load_settings.sh
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # 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 IndiScale <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -27,8 +29,6 @@ ...@@ -27,8 +29,6 @@
if [ -z "$UTILSPATH" ]; then if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $0))" UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi fi
# The directory which the dump is to be stored to. Do not change it here. Use # The directory which the dump is to be stored to. Do not change it here. Use
...@@ -45,14 +45,30 @@ function backup() { ...@@ -45,14 +45,30 @@ function backup() {
database="$1" database="$1"
backupdir="$2" backupdir="$2"
<<<<<<< HEAD
# Assert backup dir # Assert backup dir
mkdir -p "$backupdir" mkdir -p "$backupdir"
datastring=$(date -u --rfc-3339=ns | sed 's/ /T/g') datastring=$(date -u --rfc-3339=ns | sed 's/ /T/g')
backupfile=${BACKUPDIR}/${DATABASE_NAME}.${datastring}.dump.sql backupfile=${BACKUPDIR}/${DATABASE_NAME}.${datastring}.dump.sql
=======
shift 2
# 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 \
"$NARG_NAME" > "$NARG_FILE"
>>>>>>> s-clean-up-stage
if [ -e "$backupfile" ]; then if [ -e "$backupfile" ]; then
failure "dumpfile already exists." failure "dumpfile already exists."
fi fi
<<<<<<< HEAD
=======
success
}
>>>>>>> s-clean-up-stage
echo "Dumping database $database to $backupfile ... " echo "Dumping database $database to $backupfile ... "
$MYSQLDUMP_CMD $(get_mysql_args_nodb) --opt --default-character-set=utf8\ $MYSQLDUMP_CMD $(get_mysql_args_nodb) --opt --default-character-set=utf8\
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # 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 2019, 2020 Daniel Hornung # Copyright (C) 2019, 2020 Daniel Hornung (d.hornung@indiscale.com)
# Copyright 2020 Henrik tom Wörden, IndiScale GmbH # 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 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -32,14 +33,12 @@ ...@@ -32,14 +33,12 @@
function mysql_execute { function mysql_execute {
#TODO is it meaningful that here always the database user is used??? #TODO is it meaningful that here always the database user is used???
set +e set -e
# env | sort
$MYSQL_CMD $(get_db_args) -e "$1" $MYSQL_CMD $(get_db_args) -e "$1"
ret=${PIPESTATUS[0]} ret=${PIPESTATUS[0]}
if [ "$ret" -ne 0 ]; then if [ "$ret" -ne 0 ]; then
failure "MYSQL ERROR" failure "MYSQL ERROR"
fi fi
set -e
} }
function get_mysql_args { function get_mysql_args {
......
# This file is a part of the CaosDB Project. # This file is a part of the CaosDB Project.
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # 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 2019 Daniel Hornung # Copyright (C) 2019, 2020 Daniel Hornung (d.hornung@indiscale.com)
# Copyright 2020 Henrik tom Wörden, IndiScale GmbH # 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 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -23,29 +24,34 @@ ...@@ -23,29 +24,34 @@
# - .config (in the current directory) # - .config (in the current directory)
# - The file given in ENV_FILE. # - The file given in ENV_FILE.
if [ "$MAINPATH" ]; then if [ -z "$MAINPATH" ]; then
pushd "$MAINPATH" > /dev/null if [ -z "$UTILSPATH" ] ; then
pushed=1 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 fi
if [[ -r "config.defaults" ]] ; then # Make a backup of the important environment variables.
source "config.defaults" my_env=$(export -p | grep -E '(MYSQL|DATABASE)')
fi
if [[ -r ".config" ]] ; then source "$MAINPATH/config.defaults"
source ".config"
if [[ -r "$MAINPATH/.config" ]] ; then
source "$MAINPATH/.config"
fi fi
if [[ -n "$ENV_FILE" ]] ; then if [[ -n "$ENV_FILE" ]] ; then
source "$ENV_FILE" source "$ENV_FILE"
fi fi
if [[ -z "$MYSQL_CMD" ]] ; then if [[ -z "$MYSQL_CMD" ]] ; then
echo "mysql not defined!" echo "'mysql' executable not defined!"
exit 1 exit 1
fi fi
if [ $pushed ]; then # Restore backup.
popd > /dev/null eval "$my_env"
fi
export MYSQL_CMD export MYSQL_CMD
export MYSQLDUMP_CMD export MYSQLDUMP_CMD
......
...@@ -3,8 +3,9 @@ ...@@ -3,8 +3,9 @@
# ** header v3.0 # ** header v3.0
# This file is a part of the CaosDB Project. # 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 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2020 Henrik tom Wörden <h.tomwoerden@indiscale.com>
# Copyright (C) 2020 IndiScale <info@indiscale.com> # Copyright (C) 2020 IndiScale <info@indiscale.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
...@@ -27,20 +28,13 @@ set -e ...@@ -27,20 +28,13 @@ set -e
INSTALL_SQL_FILE="db_2_0.sql" INSTALL_SQL_FILE="db_2_0.sql"
if [ -z "$UTILSPATH" ]; then if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $0))" UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi fi
source $UTILSPATH/load_settings.sh source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh source $UTILSPATH/helpers.sh
function fail() {
echo "Some error occured, exiting."
exit 1
}
UNITTEST_DATABASE=${UNITTEST_DATABASE-_caosdb_schema_unit_tests} UNITTEST_DATABASE=${UNITTEST_DATABASE-_caosdb_schema_unit_tests}
# optional parameter: [--fresh] for installing a fresh data base. Otherwise an existing one would be reused. # optional parameter: [--fresh] for installing a fresh data base. Otherwise an existing one would be reused.
...@@ -50,7 +44,7 @@ function runtests() { ...@@ -50,7 +44,7 @@ function runtests() {
_install_unit_test_database $@ _install_unit_test_database $@
_execute_tests || ( echo "[FAILURE]" && exit 1 ) _execute_tests || ( failure )
echo "[PASS]" echo "[PASS]"
} }
...@@ -103,7 +97,7 @@ function _setup_mytap() { ...@@ -103,7 +97,7 @@ function _setup_mytap() {
echo MyTAB framework is already installed [OK] echo MyTAB framework is already installed [OK]
return 0 return 0
fi fi
echo -n "Installing MyTAB framework ... " echo -n "Installing MyTAP framework ... "
pushd libs > /dev/null pushd libs > /dev/null
unzip -u mytap*.zip > /dev/null unzip -u mytap*.zip > /dev/null
pushd mytap*/ > /dev/null pushd mytap*/ > /dev/null
...@@ -111,7 +105,7 @@ function _setup_mytap() { ...@@ -111,7 +105,7 @@ function _setup_mytap() {
popd > /dev/null popd > /dev/null
rm -r mytap*/ rm -r mytap*/
popd > /dev/null popd > /dev/null
echo [DONE] echo "[DONE]"
} }
function install_db() { function install_db() {
...@@ -123,7 +117,7 @@ Call 'make drop-$DATABASE_NAME' to delete that database or reconfigure with ...@@ -123,7 +117,7 @@ Call 'make drop-$DATABASE_NAME' to delete that database or reconfigure with
exit 0 exit 0
fi 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 # Inserts the dump (arg 1) into the database
...@@ -144,7 +138,7 @@ function grant() { ...@@ -144,7 +138,7 @@ function grant() {
while true; do while true; do
read -p "Please enter the password for ${DATABASE_USER}: " \ read -p "Please enter the password for ${DATABASE_USER}: " \
-s password -s password
echo echo
read -p "Please repeat the password: " -s password2 read -p "Please repeat the password: " -s password2
echo echo
[[ "$password" == "$password2" ]] && { [[ "$password" == "$password2" ]] && {
...@@ -158,7 +152,7 @@ function grant() { ...@@ -158,7 +152,7 @@ function grant() {
if [[ "$1" == "--strict" ]] ; then if [[ "$1" == "--strict" ]] ; then
for host in ${DATABASE_USER_HOST_LIST//,/ } ; do for host in ${DATABASE_USER_HOST_LIST//,/ } ; do
CMD="SELECT COUNT(*) FROM mysql.user WHERE user='${DATABASE_USER}' AND host='${host}';" 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 "The user '${DATABASE_USER}@${host}' is already in the database."
echo "Please use another user or delete it, e.g. with" echo "Please use another user or delete it, e.g. with"
echo "'mysql -u ${MYSQL_USER} -p -e \"DROP USER ${DATABASE_USER}@${host};\"'" echo "'mysql -u ${MYSQL_USER} -p -e \"DROP USER ${DATABASE_USER}@${host};\"'"
...@@ -199,12 +193,12 @@ function _db_exists() { ...@@ -199,12 +193,12 @@ function _db_exists() {
case $1 in case $1 in
"drop") drop $2 ;; "drop") drop $2 ;;
"grant") grant $2 ;; "grant") grant $2 ;;
"test") shift ; runtests $@ ;; "test") shift ; runtests $@ ;;
"test-connection") test-connection ;; "test-connection") test-connection ;;
"install_db") install_db ;; "install_db") install_db ;;
"restore_db") restore_db $2 ;; "restore_db") restore_db $2 ;;
# "prep_sql") prepare_sql ;; # "prep_sql") prepare_sql ;;
*) echo "Unknown action: $1" *) echo "Unknown action: $1"
esac esac
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # 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 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 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -21,7 +23,12 @@ ...@@ -21,7 +23,12 @@
# #
# ** end header # ** end header
# #
#header for patch scripts
###############################################################################
# header for patch scripts #
###############################################################################
set -e
# load useful functions ####################################################### # load useful functions #######################################################
source $UTILSPATH/load_settings.sh source $UTILSPATH/load_settings.sh
...@@ -57,7 +64,6 @@ configuration make file. Notable examples are: ...@@ -57,7 +64,6 @@ configuration make file. Notable examples are:
EOF EOF
) )
set -e
function _print_help() { function _print_help() {
echo -e "$USAGE" echo -e "$USAGE"
......
...@@ -4,7 +4,10 @@ ...@@ -4,7 +4,10 @@
# This file is a part of the CaosDB Project. # This file is a part of the CaosDB Project.
# #
# Copyright (C) 2018 Research Group Biomedical Physics, # 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 # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
...@@ -24,24 +27,21 @@ ...@@ -24,24 +27,21 @@
# Updates all SQL procedures # Updates all SQL procedures
set -e
if [ -z "$UTILSPATH" ]; then if [ -z "$UTILSPATH" ]; then
UTILSPATH=$(realpath "$(dirname $0)") UTILSPATH=$(realpath "$(dirname $0)")
export UTILSPATH export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi fi
source $UTILSPATH/helpers.sh
source $UTILSPATH/load_settings.sh source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
echo -n "updating rules ... " echo -n "updating rules ... "
set -e
mysql_execute "$(sed s/db_2_0/$DATABASE_NAME/g rules.sql)" mysql_execute "$(sed s/db_2_0/$DATABASE_NAME/g rules.sql)"
echo "OK" echo "OK"
echo -n "updating procedures ... " 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" echo "OK"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment