From 1d79730089c040cdd0751b59d347c290c01207f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20tom=20W=C3=B6rden?= <henrik@trineo.org> Date: Fri, 27 Mar 2020 08:18:47 +0100 Subject: [PATCH] MAINT: make calling skripts more cwd independent --- utils/backup.sh | 3 ++- utils/load_settings.sh | 9 +++++++++ utils/make_db | 2 ++ utils/update_sql_procedures.sh | 2 ++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/utils/backup.sh b/utils/backup.sh index 752c4e4..36e920b 100755 --- a/utils/backup.sh +++ b/utils/backup.sh @@ -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 # the --backupdir=./my/dir/ option or an environment variable instead. diff --git a/utils/load_settings.sh b/utils/load_settings.sh index 16f5545..a46db58 100644 --- a/utils/load_settings.sh +++ b/utils/load_settings.sh @@ -23,6 +23,11 @@ # - .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 @@ -38,6 +43,10 @@ if [[ -z "$MYSQL_CMD" ]] ; then exit 1 fi +if [ $pushed ]; then + popd > /dev/null +fi + export MYSQL_CMD export MYSQLDUMP_CMD export MYSQLADMIN_CMD diff --git a/utils/make_db b/utils/make_db index c8b9ae9..8685686 100755 --- a/utils/make_db +++ b/utils/make_db @@ -29,6 +29,8 @@ 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 diff --git a/utils/update_sql_procedures.sh b/utils/update_sql_procedures.sh index e363a7d..2b78ab8 100755 --- a/utils/update_sql_procedures.sh +++ b/utils/update_sql_procedures.sh @@ -27,6 +27,8 @@ if [ -z "$UTILSPATH" ]; then UTILSPATH=$(realpath "$(dirname $0)") export UTILSPATH + MAINPATH="$(dirname $UTILSPATH)" + export MAINPATH fi source $UTILSPATH/helpers.sh -- GitLab