Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggestion: restore environment variable if found, and new exec_crate…
…_command.sh (in contrast to run_crate_command.sh)
- Loading branch information
1 parent
dcf62c7
commit 1f8920e
Showing
7 changed files
with
137 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/bin/bash | ||
|
||
# installer/exec_crate_command.sh | ||
|
||
# ============================================================================== | ||
# | ||
# Copyright (C) 2015, University of Cambridge, Department of Psychiatry. | ||
# Created by Rudolf Cardinal (rnc1001@cam.ac.uk). | ||
# | ||
# This file is part of CRATE. | ||
# | ||
# CRATE is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# CRATE 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with CRATE. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
# ============================================================================== | ||
|
||
# Runs a command in the CRATE container | ||
|
||
set -euo pipefail | ||
|
||
# Activate Python virtual environment | ||
CRATE_INSTALLER_VENV=${HOME}/.virtualenvs/crate-installer | ||
source "${CRATE_INSTALLER_VENV}/bin/activate" | ||
|
||
# Restore user's environment variables, if found | ||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" | ||
source "${SCRIPT_DIR}/restore_crate_envvars.sh" | ||
|
||
# Run Python installer script with a command | ||
INSTALLER_HOME="$( cd "$( dirname "$0" )" && pwd )" | ||
python "${INSTALLER_HOME}/installer.py" exec "$*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# installer/restore_crate_envvars.sh | ||
|
||
# ============================================================================== | ||
# | ||
# Copyright (C) 2015, University of Cambridge, Department of Psychiatry. | ||
# Created by Rudolf Cardinal (rnc1001@cam.ac.uk). | ||
# | ||
# This file is part of CRATE. | ||
# | ||
# CRATE is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# CRATE 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 General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with CRATE. If not, see <https://www.gnu.org/licenses/>. | ||
# | ||
# ============================================================================== | ||
|
||
# When the installer first runs, it stores a copy of the relevant environment | ||
# variables. To run other Docker commands, it's helpful to "source" them back, | ||
# if found. Likewise, this file itself should be "sourced", not executed. | ||
|
||
# The default is $HOME/crate/set_crate_docker_host_envvars (per HostPath in | ||
# installer.py). We allow the user to pre-override this with environment | ||
# variables. | ||
CRATE_DIR=${CRATE_DIR:=$HOME/crate} | ||
CRATE_CONFIG_DIR=${CRATE_CONFIG_DIR:=$CRATE_DIR/config} | ||
CRATE_ENVVAR_FILE=${CRATE_CONFIG_DIR}/set_crate_docker_host_envvars | ||
# ... filename itself not configurable, and written by installer.py | ||
|
||
if [ -f "${CRATE_ENVVAR_FILE}" ]; then | ||
echo "- Restoring user-supplied environment variables from: ${CRATE_ENVVAR_FILE}" | ||
# shellcheck disable=SC1090 | ||
source "${CRATE_ENVVAR_FILE}" | ||
else | ||
echo "- No previous environment variable file found at: ${CRATE_ENVVAR_FILE}" | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters