autodetect python version for debian 12

This commit is contained in:
Mateusz Gruszczyński
2025-10-25 21:56:22 +02:00
parent e4cd853001
commit c0b4181ddf
2 changed files with 19 additions and 13 deletions

View File

@@ -301,7 +301,6 @@ def setup_certbot_venv(venv_dir: Path = Path("/opt/certbot")):
# ============================================================
if available_python:
with step(f"Using system Python ({available_python}) for certbot venv"):
# Ensure python3-venv is installed
if distro_id in ["debian", "ubuntu"]:
apt_try_install(["python3-venv", "python3-pip"])
@@ -317,18 +316,23 @@ def setup_certbot_venv(venv_dir: Path = Path("/opt/certbot")):
run([str(pip_path), "install", "-U", "pip", "setuptools", "wheel"], env=env_build)
run([str(pip_path), "install", "-U", "cryptography", "cffi", "certbot", "tldextract"], env=env_build)
# Create symlink
Path("/usr/local/bin").mkdir(parents=True, exist_ok=True)
target = Path("/usr/local/bin/certbot")
if target.exists() or target.is_symlink():
try: target.unlink()
except Exception: pass
target.symlink_to(certbot_path)
cb_ver = run_out([str(certbot_path), "--version"], check=False) or ""
pip_ver = run_out([str(pip_path), "--version"], check=False) or ""
print(f"✔ Certbot: {cb_ver.strip()} | Pip: {pip_ver.strip()} | Python: {python_version_str}")
return
cb_ver = run_out([str(certbot_path), "--version"], check=False) or ""
pip_ver = run_out([str(pip_path), "--version"], check=False) or ""
cb_clean = cb_ver.strip().split('\n')[0]
pip_clean = pip_ver.strip().split(' from ')[0]
print(f" Python: {python_version_str}")
print(f" Certbot: {cb_clean}")
print(f" Pip: {pip_clean}")
return
# ============================================================
# STEP 3: Ubuntu - install Python 3.11 from deadsnakes PPA
@@ -367,7 +371,8 @@ def setup_certbot_venv(venv_dir: Path = Path("/opt/certbot")):
cb_ver = run_out([str(certbot_path), "--version"], check=False) or ""
pip_ver = run_out([str(pip_path), "--version"], check=False) or ""
print(f" Certbot: {cb_ver.strip()} | Pip: {pip_ver.strip()}")
print(f" Certbot: {cb_ver.strip()}")
print(f" Pip: {pip_ver.strip().split(' from ')[0]}")
return
# ============================================================
@@ -476,9 +481,11 @@ fi
except Exception: pass
target.symlink_to(certbot_path)
cb_ver = run_out([str(certbot_path), "--version"], check=False) or ""
pip_ver = run_out([str(pip_path), "--version"], check=False) or ""
#print(f"✔ Certbot: {cb_ver.strip()} | Pip: {pip_ver.strip()}")
cb_ver = run_out([str(certbot_path), "--version"], check=False) or ""
pip_ver = run_out([str(pip_path), "--version"], check=False) or ""
print(f" Python: {PYTHON_VERSION} (pyenv)")
print(f" Certbot: {cb_ver.strip()}")
print(f" Pip: {pip_ver.strip().split(' from ')[0]}")
run(["chown", "-R", f"{PYENV_OWNER}:{PYENV_OWNER}", str(PYENV_ROOT)], check=False)
@@ -498,7 +505,6 @@ preferred-chain = ISRG Root X1
write_file(Path("/etc/letsencrypt.ini"), ini, 0o644)
run(["chown", "-R", "npm:npm", "/etc/letsencrypt"], check=False)
def ensure_nginx_symlink():
from pathlib import Path
target = Path("/etc/angie")