Skip to content

Commit ca9e899

Browse files
committed
chore: ensure init-deployment.sh works when invoked using sudo
Recent testing of the cookiecutter deployment template surfaced a bug in the validate_python_cmd function of the init-deployment.sh script. The command that checks that the jinja2 library was installed would break when you ran init-deployment.sh using the `--python` option in tandem with sudo. The root cause was that the way the command is quoted before it is passed to `python -c` was not compatible with all bash invocation modes. This commit fixes the function to be broadly compatible.
1 parent e3b7bec commit ca9e899

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

  • cookiecutter-templates/cookiecutter-dioptra-deployment/{{cookiecutter.__project_slug}}

cookiecutter-templates/cookiecutter-dioptra-deployment/{{cookiecutter.__project_slug}}/init-deployment.sh

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,25 @@ log_info() {
142142
###########################################################################################
143143

144144
validate_python_cmd() {
145-
local python_cmd="${1}"
145+
local candidate_python_cmd="${1}"
146146

147-
if ! command -v "${python_cmd}" >/dev/null 2>&1; then
148-
log_error "Command ${python_cmd} not found, exiting..."
147+
if ! command -v "${candidate_python_cmd}" >/dev/null 2>&1; then
148+
log_error "Command \"${candidate_python_cmd}\" not found, exiting..."
149149
exit 1
150150
fi
151151

152152
local jinja2_installed
153-
local jinja2_cmd_check="'import importlib.util;print(importlib.util.find_spec("jinja2") is not None)'"
154-
if ! jinja2_installed="$(${python_cmd} -c ${jinja2_cmd_check})"; then
155-
log_error "Command ${python_cmd} -c ${jinja2_cmd_check} failed, exiting..."
153+
local jinja2_cmd_check=(
154+
"import"
155+
"importlib.util;"
156+
'print(importlib.util.find_spec("jinja2")'
157+
"is"
158+
"not"
159+
"None)"
160+
)
161+
if ! jinja2_installed="$("${candidate_python_cmd}" -c "${jinja2_cmd_check[*]}")"; then
162+
log_error "Command \"${candidate_python_cmd}\" -c \"${jinja2_cmd_check[*]}\"" \
163+
"failed, exiting..."
156164
exit 1
157165
fi
158166

0 commit comments

Comments
 (0)