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
Branches
Tags
No related merge requests found
......@@ -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
......@@ -33,8 +34,6 @@ set -e
if [ -z "$UTILSPATH" ]; then
UTILSPATH=$(realpath "$(dirname $0)/../utils")
export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
fi
source $UTILSPATH/load_settings.sh
......
......@@ -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
......@@ -27,8 +29,6 @@
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
......@@ -45,14 +45,30 @@ function backup() {
database="$1"
backupdir="$2"
<<<<<<< HEAD
# Assert backup dir
mkdir -p "$backupdir"
datastring=$(date -u --rfc-3339=ns | sed 's/ /T/g')
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
failure "dumpfile already exists."
fi
<<<<<<< HEAD
=======
success
}
>>>>>>> s-clean-up-stage
echo "Dumping database $database to $backupfile ... "
$MYSQLDUMP_CMD $(get_mysql_args_nodb) --opt --default-character-set=utf8\
......
......@@ -2,8 +2,9 @@
#
# Copyright (C) 2018 Research Group Biomedical Physics,
# Max-Planck-Institute for Dynamics and Self-Organization Göttingen
# Copyright 2019, 2020 Daniel Hornung
# Copyright 2020 Henrik tom Wörden, IndiScale GmbH
# 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
......@@ -32,14 +33,12 @@
function mysql_execute {
#TODO is it meaningful that here always the database user is used???
set +e
# env | sort
set -e
$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 {
......
# 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
......@@ -23,29 +24,34 @@
# - .config (in the current directory)
# - The file given in ENV_FILE.
if [ "$MAINPATH" ]; then
pushd "$MAINPATH" > /dev/null
pushed=1
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
if [[ -r "config.defaults" ]] ; then
source "config.defaults"
fi
if [[ -r ".config" ]] ; then
source ".config"
# Make a backup of the important environment variables.
my_env=$(export -p | grep -E '(MYSQL|DATABASE)')
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 not defined!"
echo "'mysql' executable not defined!"
exit 1
fi
if [ $pushed ]; then
popd > /dev/null
fi
# Restore backup.
eval "$my_env"
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
......@@ -27,20 +28,13 @@ set -e
INSTALL_SQL_FILE="db_2_0.sql"
if [ -z "$UTILSPATH" ]; then
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
MAINPATH="$(dirname $UTILSPATH)"
export MAINPATH
UTILSPATH="$(realpath $(dirname $0))"
export UTILSPATH
fi
source $UTILSPATH/load_settings.sh
source $UTILSPATH/helpers.sh
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.
......@@ -50,7 +44,7 @@ function runtests() {
_install_unit_test_database $@
_execute_tests || ( echo "[FAILURE]" && exit 1 )
_execute_tests || ( failure )
echo "[PASS]"
}
......@@ -103,7 +97,7 @@ function _setup_mytap() {
echo MyTAB framework is already installed [OK]
return 0
fi
echo -n "Installing MyTAB framework ... "
echo -n "Installing MyTAP framework ... "
pushd libs > /dev/null
unzip -u mytap*.zip > /dev/null
pushd mytap*/ > /dev/null
......@@ -111,7 +105,7 @@ function _setup_mytap() {
popd > /dev/null
rm -r mytap*/
popd > /dev/null
echo [DONE]
echo "[DONE]"
}
function install_db() {
......@@ -123,7 +117,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
......@@ -144,7 +138,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" ]] && {
......@@ -158,7 +152,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};\"'"
......@@ -199,12 +193,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,7 +23,12 @@
#
# ** end header
#
#header for patch scripts
###############################################################################
# header for patch scripts #
###############################################################################
set -e
# load useful functions #######################################################
source $UTILSPATH/load_settings.sh
......@@ -57,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,24 +27,21 @@
# Updates all SQL procedures
set -e
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
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.
Please register or to comment