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
This commit is contained in:
Alfredo Monclus
2024-07-08 18:23:10 -03:00
parent 243e67609b
commit 05bbe4cdd3

View File

@@ -115,18 +115,24 @@ check_requirements()
create_virtualenv() 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" echo_text "Removing old virtual environment"
rm -rf ${KSENV} rm -rf "${KSENV}"
fi fi
echo_text "Creating virtual environment" 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" echo_error "Could not activate the enviroment, try deleting ${KSENV} and retry"
exit 1 exit 1
fi fi
if [[ "$(uname -m)" =~ armv[67]l ]]; then if [[ "$(uname -m)" =~ armv[67]l ]]; then
echo_text "Using armv[67]l! Adding piwheels.org as extra index..." 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 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
fi fi
deactivate deactivate
echo_ok "Virtual enviroment created" echo_ok "Virtual environment created"
} }
install_systemd_service() install_systemd_service()