From cd7d7ae4773a08b07c2f7b027f278d67e9817d9a Mon Sep 17 00:00:00 2001 From: Tobias Wicky Date: Mon, 23 Oct 2023 15:50:04 +0200 Subject: [PATCH] protect against scripts being sourced (#121) --- tmpl/tools/run-mypy.sh.j2 | 5 +++++ tmpl/tools/setup_env.sh.j2 | 5 +++++ tmpl/tools/setup_miniconda.sh | 5 +++++ 3 files changed, 15 insertions(+) diff --git a/tmpl/tools/run-mypy.sh.j2 b/tmpl/tools/run-mypy.sh.j2 index 44edb38..da9d049 100755 --- a/tmpl/tools/run-mypy.sh.j2 +++ b/tmpl/tools/run-mypy.sh.j2 @@ -9,6 +9,11 @@ # # src: https://jaredkhan.com/blog/mypy-pre-commit +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + echo "Please simply call the script instead of sourcing it!" + return +fi + set -o errexit VERBOSE=${VERBOSE:-false} diff --git a/tmpl/tools/setup_env.sh.j2 b/tmpl/tools/setup_env.sh.j2 index fe11f0a..e1f3f33 100755 --- a/tmpl/tools/setup_env.sh.j2 +++ b/tmpl/tools/setup_env.sh.j2 @@ -6,6 +6,11 @@ # - 2022-09 (S. Ruedisuehli) Refactor; add some options # +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + echo "Please simply call the script instead of sourcing it!" + return +fi + # Default env names DEFAULT_ENV_NAME="{{ project_slug }}" diff --git a/tmpl/tools/setup_miniconda.sh b/tmpl/tools/setup_miniconda.sh index a0fcb59..a5c36ab 100755 --- a/tmpl/tools/setup_miniconda.sh +++ b/tmpl/tools/setup_miniconda.sh @@ -6,6 +6,11 @@ # - 2022-09 (S. Ruedisuehli) Refactor # +if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then + echo "Please simply call the script instead of sourcing it!" + return +fi + # Default options INSTALL_PREFIX=${PWD} USER_INSTALL=false