From 6444f638622f7bae4d7f8d705d8ec02c7a620582 Mon Sep 17 00:00:00 2001 From: Nicola Belluti Date: Wed, 6 May 2026 08:08:25 +0200 Subject: [PATCH] Check if venv is valid before continuing with the script --- .../run_before_archlinux.sh.tmpl | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/home/.chezmoiscripts/run_before_archlinux.sh.tmpl b/home/.chezmoiscripts/run_before_archlinux.sh.tmpl index 1f00ea1..aaf4f3f 100755 --- a/home/.chezmoiscripts/run_before_archlinux.sh.tmpl +++ b/home/.chezmoiscripts/run_before_archlinux.sh.tmpl @@ -50,6 +50,28 @@ fi ANSIBLE_ROOT="{{ .chezmoi.workingTree }}/setup-script" +# If a venv exists, check if it's still valid +if [ -d "$ANSIBLE_ROOT/.venv" ]; then + VENV_PYTHON="$ANSIBLE_ROOT/.venv/bin/python3" + SYS_PYTHON_VERSION=$(python3 -c "import sys; print(sys.version_info[:2])") + VENV_OK=true + + # Check if the Python binary inside the venv is functional + if ! "$VENV_PYTHON" --version >/dev/null 2>&1; then + echo -e "\e[1;33mVenv Python binary is broken.\e[0m" + VENV_OK=false + # Check if the venv Python version matches the system Python version + elif [ "$("$VENV_PYTHON" -c "import sys; print(sys.version_info[:2])")" != "$SYS_PYTHON_VERSION" ]; then + echo -e "\e[1;33mVenv Python version mismatch with system Python.\e[0m" + VENV_OK=false + fi + + if [ "$VENV_OK" = false ]; then + echo -e "\e[1;34mDeleting the invalid venv...\e[0m" + rm -rf "$ANSIBLE_ROOT/.venv" + fi +fi + # Check if there is a venv in "setup-script/" if [ ! -d "$ANSIBLE_ROOT/.venv" ]; then echo -e "\e[1;34mNo venv found in "$ANSIBLE_ROOT". Creating one...\e[0m"