From 05bbe4cdd3317a62f1ff542d7758266b9354966f Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Mon, 8 Jul 2024 18:23:10 -0300 Subject: [PATCH] refactor(installer): add an additional check to env removal in case an invalid external variable was set https://github.com/dw-0/kiauh/issues/488 --- scripts/KlipperScreen-install.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/KlipperScreen-install.sh b/scripts/KlipperScreen-install.sh index faadc6b9..5ac9c391 100755 --- a/scripts/KlipperScreen-install.sh +++ b/scripts/KlipperScreen-install.sh @@ -115,18 +115,24 @@ check_requirements() create_virtualenv() { - if [ -d $KSENV ]; then + if [ "${KSENV}" = "/" ]; then + echo_error "Failed to resolve venv location. Aborting." + exit 1 + fi + + if [ -d "$KSENV" ]; then echo_text "Removing old virtual environment" - rm -rf ${KSENV} + rm -rf "${KSENV}" fi echo_text "Creating virtual environment" - python3 -m venv ${KSENV} + python3 -m venv "${KSENV}" - if ! source ${KSENV}/bin/activate; then + if ! . "${KSENV}/bin/activate"; then echo_error "Could not activate the enviroment, try deleting ${KSENV} and retry" exit 1 fi + if [[ "$(uname -m)" =~ armv[67]l ]]; then echo_text "Using armv[67]l! Adding piwheels.org as extra index..." pip --disable-pip-version-check install --extra-index-url https://www.piwheels.org/simple -r ${KSPATH}/scripts/KlipperScreen-requirements.txt @@ -152,7 +158,7 @@ create_virtualenv() fi fi deactivate - echo_ok "Virtual enviroment created" + echo_ok "Virtual environment created" } install_systemd_service()