refactor: migrate legacy pymc paths to openhop and clean up system packages

This commit is contained in:
Lloyd
2026-06-24 23:49:08 +01:00
parent 6f6e984d9d
commit 16e88579ae
2 changed files with 89 additions and 0 deletions
+37
View File
@@ -118,17 +118,28 @@ migrate_to_venv() {
sed -i 's|WorkingDirectory=/opt/openhop_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$svc_unit"
echo " ✓ Fixed WorkingDirectory in service unit"
fi
if grep -q 'WorkingDirectory=/opt/pymc_repeater\|WorkingDirectory=/var/lib/pymc_repeater' "$svc_unit" 2>/dev/null; then
sed -i 's|WorkingDirectory=/opt/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$svc_unit"
sed -i 's|WorkingDirectory=/var/lib/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$svc_unit"
echo " ✓ Migrated legacy WorkingDirectory to openhop path"
fi
# 4. Ensure ExecStart uses the venv python
if grep -q 'ExecStart=/usr/bin/python3' "$svc_unit" 2>/dev/null; then
sed -i "s|ExecStart=/usr/bin/python3|ExecStart=$VENV_PYTHON|" "$svc_unit"
echo " ✓ Updated ExecStart to use venv python"
fi
if grep -q 'ExecStart=/opt/pymc_repeater/venv/bin/python' "$svc_unit" 2>/dev/null; then
sed -i "s|ExecStart=/opt/pymc_repeater/venv/bin/python|ExecStart=$VENV_PYTHON|" "$svc_unit"
echo " ✓ Migrated legacy ExecStart to openhop venv"
fi
systemctl daemon-reload
fi
# 5. Remove the package from system python (best-effort)
python3 -m pip uninstall -y openhop_repeater 2>/dev/null || true
python3 -m pip uninstall -y openhop_core 2>/dev/null || true
python3 -m pip uninstall -y pymc_repeater 2>/dev/null || true
python3 -m pip uninstall -y pymc_core 2>/dev/null || true
echo " ✓ Cleaned up system-level packages (if any)"
# 6. Remove stale source trees that could shadow the venv package
@@ -546,16 +557,29 @@ if grep -q 'WorkingDirectory=/opt/openhop_repeater' "$SVC_UNIT" 2>/dev/null; the
sed -i 's|WorkingDirectory=/opt/openhop_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$SVC_UNIT"
systemctl daemon-reload
fi
if grep -q 'WorkingDirectory=/opt/pymc_repeater\|WorkingDirectory=/var/lib/pymc_repeater' "$SVC_UNIT" 2>/dev/null; then
sed -i 's|WorkingDirectory=/opt/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$SVC_UNIT"
sed -i 's|WorkingDirectory=/var/lib/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$SVC_UNIT"
systemctl daemon-reload
fi
if grep -q 'ExecStart=/usr/bin/python3' "$SVC_UNIT" 2>/dev/null; then
sed -i "s|ExecStart=/usr/bin/python3|ExecStart=$VENV_PYTHON|" "$SVC_UNIT"
systemctl daemon-reload
fi
if grep -q 'ExecStart=/opt/pymc_repeater/venv/bin/python' "$SVC_UNIT" 2>/dev/null; then
sed -i "s|ExecStart=/opt/pymc_repeater/venv/bin/python|ExecStart=$VENV_PYTHON|" "$SVC_UNIT"
systemctl daemon-reload
fi
# ---- Remove stale source trees that shadow the venv package ----
[ -d /opt/openhop_repeater/repeater ] && rm -rf /opt/openhop_repeater/repeater
[ -d /opt/openhop_repeater/openhop-repeater ] && rm -rf /opt/openhop_repeater/openhop-repeater
[ -d /opt/pymc_repeater/repeater ] && rm -rf /opt/pymc_repeater/repeater
[ -d /opt/pymc_repeater/pymc-repeater ] && rm -rf /opt/pymc_repeater/pymc-repeater
# ---- Remove old system-level packages to avoid confusion ----
python3 -m pip uninstall -y openhop_repeater 2>/dev/null || true
python3 -m pip uninstall -y openhop_core 2>/dev/null || true
python3 -m pip uninstall -y pymc_repeater 2>/dev/null || true
python3 -m pip uninstall -y pymc_core 2>/dev/null || true
# ---- Try R2 wheels first for faster OTA upgrades ----
R2_BASE_URL="https://wheel.pymc.dev/pymc_build_deps"
MACHINE_ARCH=$(uname -m)
@@ -967,16 +991,29 @@ if grep -q 'WorkingDirectory=/opt/openhop_repeater' "$SVC_UNIT" 2>/dev/null; the
sed -i 's|WorkingDirectory=/opt/openhop_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$SVC_UNIT"
systemctl daemon-reload
fi
if grep -q 'WorkingDirectory=/opt/pymc_repeater\|WorkingDirectory=/var/lib/pymc_repeater' "$SVC_UNIT" 2>/dev/null; then
sed -i 's|WorkingDirectory=/opt/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$SVC_UNIT"
sed -i 's|WorkingDirectory=/var/lib/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|' "$SVC_UNIT"
systemctl daemon-reload
fi
if grep -q 'ExecStart=/usr/bin/python3' "$SVC_UNIT" 2>/dev/null; then
sed -i "s|ExecStart=/usr/bin/python3|ExecStart=$VENV_PYTHON|" "$SVC_UNIT"
systemctl daemon-reload
fi
if grep -q 'ExecStart=/opt/pymc_repeater/venv/bin/python' "$SVC_UNIT" 2>/dev/null; then
sed -i "s|ExecStart=/opt/pymc_repeater/venv/bin/python|ExecStart=$VENV_PYTHON|" "$SVC_UNIT"
systemctl daemon-reload
fi
# ---- Remove stale source trees that shadow the venv package ----
[ -d /opt/openhop_repeater/repeater ] && rm -rf /opt/openhop_repeater/repeater
[ -d /opt/openhop_repeater/openhop-repeater ] && rm -rf /opt/openhop_repeater/openhop-repeater
[ -d /opt/pymc_repeater/repeater ] && rm -rf /opt/pymc_repeater/repeater
[ -d /opt/pymc_repeater/pymc-repeater ] && rm -rf /opt/pymc_repeater/pymc-repeater
# ---- Remove old system-level packages to avoid confusion ----
python3 -m pip uninstall -y openhop_repeater 2>/dev/null || true
python3 -m pip uninstall -y openhop_core 2>/dev/null || true
python3 -m pip uninstall -y pymc_repeater 2>/dev/null || true
python3 -m pip uninstall -y pymc_core 2>/dev/null || true
# ---- Try R2 wheels first for faster OTA upgrades ----
R2_BASE_URL="https://wheel.pymc.dev/pymc_build_deps"
MACHINE_ARCH=$(uname -m)
+52
View File
@@ -54,6 +54,7 @@ _SED_BIN = "/usr/bin/sed"
_SYSTEMCTL_BIN = "/bin/systemctl"
_SUDO_BIN = "/usr/bin/sudo"
_INSTALL_DIR = "/opt/openhop_repeater"
_LEGACY_PYMC_INSTALL_DIR = "/opt/pymc_repeater"
_github_ssl_ctx: Optional[ssl.SSLContext] = None
_disk_version_mismatch_logged: Optional[tuple] = None
@@ -809,22 +810,70 @@ def _migrate_service_unit() -> None:
],
check=False,
) # nosec B603
subprocess.run(
[
_SED_BIN,
"-i",
"s|WorkingDirectory=/opt/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|",
_SVC_UNIT,
],
check=False,
) # nosec B603
subprocess.run(
[
_SED_BIN,
"-i",
"s|WorkingDirectory=/var/lib/pymc_repeater|WorkingDirectory=/var/lib/openhop_repeater|",
_SVC_UNIT,
],
check=False,
) # nosec B603
subprocess.run(
[_SED_BIN, "-i", f"s|ExecStart=/usr/bin/python3|ExecStart={_VENV_PYTHON}|", _SVC_UNIT],
check=False,
) # nosec B603
subprocess.run(
[
_SED_BIN,
"-i",
f"s|ExecStart=/opt/pymc_repeater/venv/bin/python|ExecStart={_VENV_PYTHON}|",
_SVC_UNIT,
],
check=False,
) # nosec B603
subprocess.run([_SYSTEMCTL_BIN, "daemon-reload"], check=False) # nosec B603
logger.info("[Update] Service unit migration applied (root path).")
except Exception as exc:
logger.warning(f"[Update] Service unit migration failed: {exc}")
def _migrate_pymc_install_dir() -> None:
"""Move legacy /opt/pymc_repeater into /opt/openhop_repeater when needed."""
if not os.path.isdir(_LEGACY_PYMC_INSTALL_DIR):
return
if not os.path.exists(_INSTALL_DIR):
os.rename(_LEGACY_PYMC_INSTALL_DIR, _INSTALL_DIR)
_state.append_line(
f"[pyMC updater] Migrated legacy install path: {_LEGACY_PYMC_INSTALL_DIR} -> {_INSTALL_DIR}"
)
return
backup_path = f"{_LEGACY_PYMC_INSTALL_DIR}.migrated.{time.strftime('%Y%m%d_%H%M%S')}"
os.rename(_LEGACY_PYMC_INSTALL_DIR, backup_path)
_state.append_line(f"[pyMC updater] Archived legacy install path at {backup_path}")
def _cleanup_stale_source_trees() -> None:
stale_paths = [
"/opt/openhop_repeater/repeater",
"/opt/openhop_repeater/openhop_core",
"/opt/openhop_repeater/openhop-repeater",
"/opt/openhop_repeater/openhop-core",
"/opt/pymc_repeater/repeater",
"/opt/pymc_repeater/pymc_core",
"/opt/pymc_repeater/pymc-repeater",
"/opt/pymc_repeater/pymc-core",
]
removed_any = False
@@ -895,6 +944,7 @@ def _do_install() -> None:
)
cmd = ["/bin/sh", _BUILDROOT_UPGRADE_HELPER, "upgrade"]
elif is_root:
_migrate_pymc_install_dir()
_migrate_service_unit()
# Ensure venv exists (migration from system-pip era)
@@ -906,6 +956,8 @@ def _do_install() -> None:
# Clean up system-level packages to avoid shadowing
_run(["/usr/bin/python3", "-m", "pip", "uninstall", "-y", "openhop_repeater"], env=env)
_run(["/usr/bin/python3", "-m", "pip", "uninstall", "-y", "openhop_core"], env=env)
_run(["/usr/bin/python3", "-m", "pip", "uninstall", "-y", "pymc_repeater"], env=env)
_run(["/usr/bin/python3", "-m", "pip", "uninstall", "-y", "pymc_core"], env=env)
# Remove stale source trees that could shadow the venv package
_cleanup_stale_source_trees()