build(node): package NetBird and JK BMS with pinned shared UI sources
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
"""Versioned Ubuntu 24.04/amd64 preparation. Bundled, pinned vendor package only."""
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path("/usr/share/mission-core-node/netbird")
|
||||
|
||||
|
||||
def install():
|
||||
system = dict(
|
||||
line.split("=", 1)
|
||||
for line in Path("/etc/os-release").read_text().splitlines()
|
||||
if "=" in line
|
||||
)
|
||||
if (
|
||||
system.get("ID", "").strip('"') != "ubuntu"
|
||||
or system.get("VERSION_ID", "").strip('"') != "24.04"
|
||||
or os.uname().machine != "x86_64"
|
||||
):
|
||||
raise ValueError("NetBird подготовлен для Ubuntu 24.04 amd64.")
|
||||
lock = json.loads((ROOT / "clients.lock.json").read_text())
|
||||
item = next(row for row in lock["items"] if row["id"] == "linux-amd64")
|
||||
package = ROOT / item["filename"]
|
||||
with package.open("rb") as stream:
|
||||
if (
|
||||
package.stat().st_size != item["bytes"]
|
||||
or hashlib.file_digest(stream, "sha256").hexdigest() != item["sha256"]
|
||||
):
|
||||
raise ValueError("Пакет NetBird повреждён.")
|
||||
current = subprocess.run(
|
||||
["/usr/bin/dpkg-query", "-W", "-f=${Version}\t${db:Status-Status}", "netbird"],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
if current.returncode == 0 and current.stdout.strip().split("\t")[0] != lock["version"]:
|
||||
raise ValueError(
|
||||
"Установлена другая версия NetBird. Сохраните её настройки перед обновлением."
|
||||
)
|
||||
if current.returncode or not current.stdout.strip().endswith("\tinstalled"):
|
||||
subprocess.run(
|
||||
["/usr/bin/apt-get", "-y", "--no-remove", "install", str(package)],
|
||||
check=True,
|
||||
timeout=600,
|
||||
env={"PATH": "/usr/sbin:/usr/bin:/sbin:/bin", "DEBIAN_FRONTEND": "noninteractive"},
|
||||
capture_output=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
"/usr/bin/systemctl",
|
||||
"enable",
|
||||
"--now",
|
||||
"netbird.service",
|
||||
"mission-core-node-netbird.service",
|
||||
],
|
||||
check=True,
|
||||
timeout=45,
|
||||
capture_output=True,
|
||||
)
|
||||
subprocess.run(
|
||||
[
|
||||
"/usr/bin/systemctl",
|
||||
"is-active",
|
||||
"--quiet",
|
||||
"netbird.service",
|
||||
"mission-core-node-netbird.service",
|
||||
],
|
||||
check=True,
|
||||
timeout=10,
|
||||
)
|
||||
return "NetBird установлен. Выберите сервер и способ входа в разделе «Частная сеть»."
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if os.geteuid() != 0:
|
||||
raise SystemExit("Use environment preparation")
|
||||
print(install())
|
||||
Reference in New Issue
Block a user