mirror of
https://github.com/pyMC-dev/pyMC_Repeater.git
synced 2026-08-03 23:42:48 +02:00
Merge pull request #213 from yellowcooln/dev
Fix Buildroot OTA updates to use the repo upgrade path
This commit is contained in:
@@ -24,6 +24,8 @@ R2_ENABLED=1
|
||||
YQ_VERSION="${YQ_VERSION:-v4.44.3}"
|
||||
PYMC_CORE_REPO="${PYMC_CORE_REPO:-https://github.com/rightup/pyMC_core.git}"
|
||||
PYMC_CORE_REF="${PYMC_CORE_REF:-}"
|
||||
PYMC_CORE_LOCAL_DIR="${PYMC_CORE_LOCAL_DIR:-}"
|
||||
PYMC_SKIP_BUILDROOT_DEP_INSTALL="${PYMC_SKIP_BUILDROOT_DEP_INSTALL:-0}"
|
||||
RADIO_SETTINGS_JSON="$SCRIPT_DIR/radio-settings.json"
|
||||
RADIO_PRESETS_JSON="$SCRIPT_DIR/radio-presets.json"
|
||||
BUILDROOT_RADIO_SETTINGS_JSON="$SCRIPT_DIR/radio-settings-buildroot.json"
|
||||
@@ -533,6 +535,15 @@ install_buildroot_dependencies() {
|
||||
local wheel_base
|
||||
local deps
|
||||
|
||||
if [ "${PYMC_SKIP_BUILDROOT_DEP_INSTALL}" = "1" ]; then
|
||||
stage "Checking embedded Python dependency baseline"
|
||||
if check_buildroot_dependencies_installed >/dev/null 2>&1; then
|
||||
info "Image-provided Python dependency wheels already satisfy Buildroot requirements"
|
||||
return 0
|
||||
fi
|
||||
fail "Embedded/offline install requested, but the required Python dependency wheels are not already present in the image."
|
||||
fi
|
||||
|
||||
wheel_base=$(get_r2_wheel_base 2>/dev/null || true)
|
||||
deps=$(set_wheel_dependencies)
|
||||
stage "Installing Python dependency wheels"
|
||||
@@ -611,9 +622,32 @@ PY
|
||||
info "Linked image-provided Python runtime into the venv"
|
||||
}
|
||||
|
||||
remove_shadowing_buildroot_native_packages() {
|
||||
local removed=0
|
||||
|
||||
if "$VENV_PIP" show python-periphery >/dev/null 2>&1; then
|
||||
stage "Restoring Buildroot GPIO runtime"
|
||||
info "Removing venv-installed python-periphery so the image-provided package is used"
|
||||
"$VENV_PIP" uninstall -y python-periphery >/dev/null 2>&1 || true
|
||||
removed=1
|
||||
fi
|
||||
|
||||
if [ "$removed" -eq 0 ]; then
|
||||
info "No shadowing Buildroot native GPIO wheels found in the venv"
|
||||
fi
|
||||
}
|
||||
|
||||
install_core_into_venv() {
|
||||
local core_repo core_ref core_spec
|
||||
|
||||
if [ -n "$PYMC_CORE_LOCAL_DIR" ]; then
|
||||
[ -d "$PYMC_CORE_LOCAL_DIR" ] || fail "Missing local pyMC_core checkout: $PYMC_CORE_LOCAL_DIR"
|
||||
stage "Installing pyMC_core"
|
||||
info "Local dir: ${PYMC_CORE_LOCAL_DIR}"
|
||||
"$VENV_PIP" install --upgrade --no-cache-dir --no-deps --no-build-isolation "$PYMC_CORE_LOCAL_DIR"
|
||||
return 0
|
||||
fi
|
||||
|
||||
core_repo="$PYMC_CORE_REPO"
|
||||
case "$core_repo" in
|
||||
*.git) ;;
|
||||
@@ -1342,6 +1376,7 @@ install_repeater() {
|
||||
install_buildroot_dependencies
|
||||
install_core_into_venv
|
||||
install_repeater_package
|
||||
remove_shadowing_buildroot_native_packages
|
||||
link_system_site_packages
|
||||
|
||||
stage "Validating installed runtime"
|
||||
@@ -1407,6 +1442,7 @@ upgrade_repeater() {
|
||||
ensure_yq >/dev/null 2>&1 || true
|
||||
install_repeater_package
|
||||
fi
|
||||
remove_shadowing_buildroot_native_packages
|
||||
link_system_site_packages
|
||||
stage "Validating installed runtime"
|
||||
if check_venv_runtime; then
|
||||
|
||||
@@ -29,6 +29,7 @@ from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
import cherrypy
|
||||
from repeater.service_utils import is_buildroot
|
||||
|
||||
logger = logging.getLogger("HTTPServer")
|
||||
|
||||
@@ -58,6 +59,18 @@ def _get_github_ssl_context() -> ssl.SSLContext:
|
||||
return _github_ssl_ctx
|
||||
|
||||
|
||||
def _find_buildroot_upgrade_helper() -> Optional[str]:
|
||||
candidates = [
|
||||
"/root/pyMC_Repeater/buildroot-manage.sh",
|
||||
"/opt/pymc_repeater/pyMC_Repeater/buildroot-manage.sh",
|
||||
"/root/scripts/buildroot-manage.sh",
|
||||
]
|
||||
for path in candidates:
|
||||
if os.path.isfile(path):
|
||||
return path
|
||||
return None
|
||||
|
||||
|
||||
class _RateLimitError(Exception):
|
||||
"""Raised when GitHub returns HTTP 403 due to rate limiting."""
|
||||
def __init__(self, msg: str, reset_at: Optional[datetime] = None):
|
||||
@@ -808,9 +821,18 @@ def _do_install() -> None:
|
||||
_state.append_line(f"[pyMC updater] Installing from channel '{channel}'…")
|
||||
|
||||
_UPGRADE_WRAPPER = "/usr/local/bin/pymc-do-upgrade"
|
||||
_BUILDROOT_UPGRADE_HELPER = _find_buildroot_upgrade_helper()
|
||||
is_root = (_os.geteuid() == 0)
|
||||
|
||||
if is_root:
|
||||
if is_root and is_buildroot():
|
||||
env["PYMC_REPEATER_REF"] = channel
|
||||
env["PYMC_CORE_REF"] = channel
|
||||
if not _BUILDROOT_UPGRADE_HELPER:
|
||||
_state.finish_install(False, "Buildroot upgrade helper not found in repo checkout or image bootstrap paths")
|
||||
return
|
||||
_state.append_line(f"[pyMC updater] Buildroot image detected – using {_BUILDROOT_UPGRADE_HELPER}")
|
||||
cmd = ["/bin/sh", _BUILDROOT_UPGRADE_HELPER, "upgrade"]
|
||||
elif is_root:
|
||||
_migrate_service_unit()
|
||||
|
||||
# Ensure venv exists (migration from system-pip era)
|
||||
|
||||
Reference in New Issue
Block a user