ubuntu deadsneaks

This commit is contained in:
Mateusz Gruszczyński
2025-10-24 20:52:52 +02:00
parent bf96a22963
commit 590532477e

View File

@@ -211,39 +211,25 @@ def sync_backup_nginx_conf():
print(f"Warning: sync failed for {p} -> {target}: {e}")
def _is_ubuntu() -> bool:
info = os_release()
id_ = (info.get("ID") or "").lower()
if id_ == "ubuntu":
return True
pretty = (info.get("PRETTY") or "").lower()
if "ubuntu" in pretty:
return True
codename = (info.get("CODENAME") or "").lower()
if codename in {"bionic","focal","jammy","kinetic","lunar","mantic","noble","oracular"}:
return True
# /etc/lsb-release fallback
try:
txt = Path("/etc/lsb-release").read_text().lower()
if "distrib_id=ubuntu" in txt:
return True
except Exception:
pass
return False
def setup_certbot_venv(venv_dir: Path = Path("/opt/certbot")):
info = os_release()
print(f"[setup_certbot_venv] DETECTED: {info}")
distro_id = (info.get("ID") or "").lower()
# --- UBUNTU: PPA deadsnakes + venv ---
if _is_ubuntu():
with step(f"Ubuntu: install Python 3.11 via deadsnakes ( {info.get('PRETTY','')} )"):
run(["apt-get", "update", "-y"], check=False)
# software-properties-common + PPA
# --- Debian pyenv
PYENV_ROOT = Path("/opt/npm/.pyenv")
PYENV_OWNER = "npm"
PYTHON_VERSION = "3.11.11"
PYENV_BIN_CANDIDATES = ["pyenv", "/usr/bin/pyenv", "/usr/lib/pyenv/bin/pyenv"]
# --- Ubuntu: PPA deadsnakes + venv ---
if distro_id == "ubuntu":
with step(f"Ubuntu detected: {info.get('PRETTY','Ubuntu')}. Install Python 3.11 via deadsnakes"):
try:
run(["apt-get", "update", "-y"], check=False)
apt_try_install(["software-properties-common"])
except Exception:
run(["apt-get", "install", "-y", "software-properties-common"], check=False)
run(["add-apt-repository", "-y", "ppa:deadsnakes/ppa"])
run(["apt-get", "update", "-y"], check=False)
run(["apt-get", "install", "-y", "python3.11", "python3.11-venv"])
@@ -252,7 +238,6 @@ def setup_certbot_venv(venv_dir: Path = Path("/opt/certbot")):
venv_dir.mkdir(parents=True, exist_ok=True)
run(["python3.11", "-m", "venv", str(venv_dir)])
# wspólny post-setup
venv_bin = venv_dir / "bin"
pip_path = venv_bin / "pip"
certbot_path = venv_bin / "certbot"
@@ -274,11 +259,6 @@ def setup_certbot_venv(venv_dir: Path = Path("/opt/certbot")):
print(f"Certbot: {cb_ver.strip()} | Pip: {pip_ver.strip()}")
return
PYENV_ROOT = Path("/opt/npm/.pyenv")
PYENV_OWNER = "npm"
PYTHON_VERSION = "3.11.X"
PYENV_BIN_CANDIDATES = ["pyenv", "/usr/bin/pyenv", "/usr/lib/pyenv/bin/pyenv"]
try:
apt_try_install([
"pyenv", "build-essential", "gcc", "make", "pkg-config",
@@ -328,7 +308,7 @@ def setup_certbot_venv(venv_dir: Path = Path("/opt/certbot")):
"bash", "-lc", install_cmd
])
profile_snippet = f"""# Auto-generated by setup_certbot_venv
profile_snippet = f"""# Auto-generated by npm-auto-auto-install
# pyenv for '{PYENV_OWNER}'
if [ -d "{PYENV_ROOT}" ]; then
export PYENV_ROOT="{PYENV_ROOT}"
@@ -364,6 +344,7 @@ fi
env_build = os.environ.copy()
env_build["SETUPTOOLS_USE_DISTUTILS"] = "local"
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)
@@ -378,6 +359,8 @@ fi
pip_ver = run_out([str(pip_path), "--version"], check=False) or ""
print(f"Certbot: {cb_ver.strip()} | Pip: {pip_ver.strip()}")
run(["chown", "-R", f"{PYENV_OWNER}:{PYENV_OWNER}", str(PYENV_ROOT)], check=False)
def configure_letsencrypt():
with step("configure letsencrypt"):