diff --git a/config.defaults b/config.defaults index c9101986c5d0099b0031f68665e05e54d0472ac2..a07b908e6e3be610a7f2cc9d33c1979c641f30bd 100644 --- a/config.defaults +++ b/config.defaults @@ -56,4 +56,5 @@ DATABASE_USER_PW=random1234 # network. DATABASE_USER_HOST_LIST=localhost, - +# path to utility scripts +UTILSPATH=`realpath "utils"` diff --git a/patches/applyPatches.sh b/patches/applyPatches.sh index f3aaf46904f643de59aa794696b8a106c6bd5d10..660d8da55b15188302bdb1bab33b7ae4368bb578 100755 --- a/patches/applyPatches.sh +++ b/patches/applyPatches.sh @@ -27,10 +27,8 @@ #apply all available patches. set -e PATCHES="./patch*/patch.sh" -export UTILSPATH="../utils" -. ../utils/load_settings.sh -. ../utils/helpers.sh +. $UTILSPATH/helpers.sh for p in $PATCHES do $p "$@" --patch=$p diff --git a/patches/utils/patch_header.sh b/patches/utils/patch_header.sh deleted file mode 100644 index de6581548b32fd04cb192b20b1a0eaeaa7d6e318..0000000000000000000000000000000000000000 --- a/patches/utils/patch_header.sh +++ /dev/null @@ -1,123 +0,0 @@ -# -# ** header v3.0 -# 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 -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 of the -# License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# 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/>. -# -# ** end header -# -#header for patch scripts - -. load_settings.sh -. helpers.sh - -USAGE="$1 [ --env=ENV_FILE ] [ --patch=PATCH ] [ --backupdir=BACKUPDIR ]\n\n" -CMD_OPTIONS=$(cat <<EOF -options: - --h, --help - Show brief help. ---env=ENV_FILE - A file where variables are stored in the format of shell environment - variables. Content of this file overrides environment variables already - present. ---patch=PATCH - *TODO* Please document this option. ---backupdir=BACKUPDIR - The directory where backup files are stored to. ---yaml[=True|False] - If given (and the optional value is not False), additional machine-readable - YAML output is emitted. Only implemented for some commands yet. - -This script basically uses the same environment variables as the server -configuration make file. Notable examples are: - -- LOGIN_PATH -- MYSQL_HOST -- MYSQL_PORT -- DATABASE_NAME -- DATABASE_USER -- DATABASE_USER_PW - -EOF - ) -set -e - -function _print_help() { - echo -e "$USAGE" - echo -e "$CMD_OPTIONS" - if [ -n "$PRINT_HELP" ]; then - echo -e "$PRINT_HELP" - fi - if [ -n "$1" ]; then - echo -e "$1" - fi -} - -while test $# -gt 0; do - case "$1" in - -h|--help) - _print_help - exit 0 - ;; - --env*) - ENV_FILE="${1#--*=}" - shift - ;; - --patch*) - PATCH="${1#--*=}" - shift - ;; - --backupdir*) - BACKUPDIR="${1#--*=}" - shift - ;; - --yaml*) - if [[ "$1" == "--yaml" ]] ; then - YAML="True" - else - YAML="${1#--*=}" - fi - shift - ;; - *) - echo "Unknown option $1" - exit 1 - shift - ;; - esac -done - - -if [ -n "$PATCH" ]; then - echo -ne "applying patch $PATCH to $DATABASE_NAME ... " -fi -# @param $1: db version string, e.g. v2.0.0 -# @return: 0 on success, 1 on failure -function check_version { - local version=$($MYSQL_CMD $MYSQL_CONNECTION -B -e "Select CaosDBVersion();") - if [[ "$(echo $version | sed 's/^CaosDBVersion()\s//')" = "$1" ]]; then - return 0 - fi - uptodate -} - -# @param $1: new version string -function update_version { - mysql_execute "DROP FUNCTION IF EXISTS CaosDBVersion; CREATE FUNCTION CaosDBVersion() RETURNS VARCHAR(255) DETERMINISTIC RETURN '$1';" -} diff --git a/utils/load_settings.sh b/utils/load_settings.sh index 5f2b499ba524c97cfcdc352b4337107b3c7e8afd..196e89ec3e5f2f2721b38bc0f06dba4f8866d20a 100644 --- a/utils/load_settings.sh +++ b/utils/load_settings.sh @@ -18,16 +18,14 @@ # 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/>. -UTILS_PATH=`dirname "$(realpath $0)"` -MAIN_PATH=`dirname "${UTILS_PATH}"` - -[[ -n "${MAIN_PATH}/config.defaults" ]] && source "${MAIN_PATH}/config.defaults" -[[ -n "${MAIN_PATH}/.config" ]] && source "${MAIN_PATH}/.config" +[[ -n "config.defaults" ]] && source "config.defaults" +[[ -n ".config" ]] && source ".config" [[ -n "$ENV_FILE" ]] && source "$ENV_FILE" if [[ -z "$DATABASE_NAME" && -z "$MYSQL_CONNECTION" ]] then - _print_help "Please specify the database." + echo "A database or a mysql connection need to be set via the corresponding" \ + "environment variables." exit 1 fi @@ -57,7 +55,7 @@ elif [[ -z "$MYSQL_CONNECTION" ]]; then MYSQL_CONNECTION="$MYSQL_CONNECTION --database=$DATABASE_NAME" fi -# TODO is this a good idea? export MYSQL_CONNECTION export MYSQL_CONNECTION_NO_DB export DATABASE_NAME +export UTILSPATH diff --git a/utils/patch_header.sh b/utils/patch_header.sh index 2b6608679ba1eae016e6e66d9dcff83c85735006..5a4039fed68b6d03db1c4bc9019644767c556c45 100644 --- a/utils/patch_header.sh +++ b/utils/patch_header.sh @@ -24,8 +24,7 @@ #header for patch scripts # load useful functions ####################################################### -UTILS_PATH=`dirname "$(realpath $0)"` -. $UTILS_PATH/helpers.sh +. $UTILSPATH/helpers.sh USAGE="$1 [ --env=ENV_FILE ] [ --patch=PATCH ] [ --backupdir=BACKUPDIR ]\n\n" CMD_OPTIONS=$(cat <<EOF