|
@@ -14,6 +14,7 @@ from pathlib import Path, PurePosixPath
|
|
|
import yaml
|
|
import yaml
|
|
|
|
|
|
|
|
from validate_desired_state import validate_state
|
|
from validate_desired_state import validate_state
|
|
|
|
|
+from generate_mod_ui_pedalboard import generate_bundle_files
|
|
|
|
|
|
|
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
@@ -40,16 +41,20 @@ def load_deployment():
|
|
|
pipewire = deployment.get("pipewire")
|
|
pipewire = deployment.get("pipewire")
|
|
|
reconcile = deployment.get("reconcile")
|
|
reconcile = deployment.get("reconcile")
|
|
|
midi_bridge = deployment.get("midi_bridge")
|
|
midi_bridge = deployment.get("midi_bridge")
|
|
|
|
|
+ mod_host_ports = deployment.get("mod_host_ports")
|
|
|
|
|
+ mod_ui = deployment.get("mod_ui")
|
|
|
if (
|
|
if (
|
|
|
not isinstance(namlv2, dict)
|
|
not isinstance(namlv2, dict)
|
|
|
or not isinstance(sooperlooper, dict)
|
|
or not isinstance(sooperlooper, dict)
|
|
|
or not isinstance(pipewire, dict)
|
|
or not isinstance(pipewire, dict)
|
|
|
or not isinstance(reconcile, dict)
|
|
or not isinstance(reconcile, dict)
|
|
|
or not isinstance(midi_bridge, dict)
|
|
or not isinstance(midi_bridge, dict)
|
|
|
|
|
+ or not isinstance(mod_host_ports, dict)
|
|
|
|
|
+ or not isinstance(mod_ui, dict)
|
|
|
):
|
|
):
|
|
|
raise ValueError(
|
|
raise ValueError(
|
|
|
"deployment.namlv2, deployment.sooperlooper, deployment.pipewire, deployment.reconcile, "
|
|
"deployment.namlv2, deployment.sooperlooper, deployment.pipewire, deployment.reconcile, "
|
|
|
- "and deployment.midi_bridge must be mappings"
|
|
|
|
|
|
|
+ "deployment.midi_bridge, deployment.mod_host_ports, and deployment.mod_ui must be mappings"
|
|
|
)
|
|
)
|
|
|
for component, archive_format in PLUGIN_ARCHIVES.items():
|
|
for component, archive_format in PLUGIN_ARCHIVES.items():
|
|
|
plugin = deployment.get(component)
|
|
plugin = deployment.get(component)
|
|
@@ -122,6 +127,24 @@ def tree_sha256(path):
|
|
|
return digest.hexdigest()
|
|
return digest.hexdigest()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def runtime_tree_sha256(path):
|
|
|
|
|
+ digest = hashlib.sha256()
|
|
|
|
|
+ for item in sorted(path.rglob("*")):
|
|
|
|
|
+ if "__pycache__" in item.parts or item.suffix in {".pyc", ".pyo"}:
|
|
|
|
|
+ continue
|
|
|
|
|
+ relative = item.relative_to(path).as_posix().encode()
|
|
|
|
|
+ digest.update(relative + b"\0")
|
|
|
|
|
+ if item.is_symlink():
|
|
|
|
|
+ digest.update(b"link\0" + os.readlink(item).encode())
|
|
|
|
|
+ elif item.is_file():
|
|
|
|
|
+ digest.update(b"file\0" + item.read_bytes())
|
|
|
|
|
+ elif item.is_dir():
|
|
|
|
|
+ digest.update(b"directory\0")
|
|
|
|
|
+ else:
|
|
|
|
|
+ raise RuntimeError(f"unsupported file type in runtime bundle: {item}")
|
|
|
|
|
+ return digest.hexdigest()
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def validate_user_destination(destination):
|
|
def validate_user_destination(destination):
|
|
|
home = Path.home().resolve()
|
|
home = Path.home().resolve()
|
|
|
parent = destination.parent.resolve()
|
|
parent = destination.parent.resolve()
|
|
@@ -810,27 +833,23 @@ def systemd_quote(value):
|
|
|
def render_mod_host_service(config):
|
|
def render_mod_host_service(config):
|
|
|
binary = ROOT / config["binary_source"]
|
|
binary = ROOT / config["binary_source"]
|
|
|
service_template = ROOT / config["service_source"]
|
|
service_template = ROOT / config["service_source"]
|
|
|
- configure_script = ROOT / config["configure_script"]
|
|
|
|
|
readiness_script = ROOT / config["readiness_script"]
|
|
readiness_script = ROOT / config["readiness_script"]
|
|
|
state_file = ROOT / "config" / "desired-state.yaml"
|
|
state_file = ROOT / "config" / "desired-state.yaml"
|
|
|
if not binary.is_file() or not os.access(binary, os.X_OK):
|
|
if not binary.is_file() or not os.access(binary, os.X_OK):
|
|
|
raise RuntimeError(f"ARM64 mod-host artifact is missing or not executable: {binary}")
|
|
raise RuntimeError(f"ARM64 mod-host artifact is missing or not executable: {binary}")
|
|
|
if not service_template.is_file():
|
|
if not service_template.is_file():
|
|
|
raise RuntimeError(f"mod-host service template is missing: {service_template}")
|
|
raise RuntimeError(f"mod-host service template is missing: {service_template}")
|
|
|
- if not configure_script.is_file():
|
|
|
|
|
- raise RuntimeError(f"mod-host startup configurator is missing: {configure_script}")
|
|
|
|
|
if not readiness_script.is_file():
|
|
if not readiness_script.is_file():
|
|
|
raise RuntimeError(f"mod-host PipeWire readiness checker is missing: {readiness_script}")
|
|
raise RuntimeError(f"mod-host PipeWire readiness checker is missing: {readiness_script}")
|
|
|
replacements = {
|
|
replacements = {
|
|
|
"@PW_JACK@": systemd_quote(config["pw_jack_path"]),
|
|
"@PW_JACK@": systemd_quote(config["pw_jack_path"]),
|
|
|
"@MOD_HOST_BINARY@": systemd_quote(binary.resolve()),
|
|
"@MOD_HOST_BINARY@": systemd_quote(binary.resolve()),
|
|
|
"@SOCKET_PORT@": str(config["socket_port"]),
|
|
"@SOCKET_PORT@": str(config["socket_port"]),
|
|
|
|
|
+ "@FEEDBACK_PORT@": str(config["feedback_port"]),
|
|
|
"@PYTHON@": systemd_quote(config["python_path"]),
|
|
"@PYTHON@": systemd_quote(config["python_path"]),
|
|
|
"@READINESS_SCRIPT@": systemd_quote(readiness_script.resolve()),
|
|
"@READINESS_SCRIPT@": systemd_quote(readiness_script.resolve()),
|
|
|
"@PORT_WAIT_TIMEOUT_SECONDS@": str(config["port_wait_timeout_seconds"]),
|
|
"@PORT_WAIT_TIMEOUT_SECONDS@": str(config["port_wait_timeout_seconds"]),
|
|
|
- "@CONFIGURE_SCRIPT@": systemd_quote(configure_script.resolve()),
|
|
|
|
|
"@DESIRED_STATE@": systemd_quote(state_file.resolve()),
|
|
"@DESIRED_STATE@": systemd_quote(state_file.resolve()),
|
|
|
- "@REPOSITORY_ROOT@": systemd_quote(ROOT.resolve()),
|
|
|
|
|
}
|
|
}
|
|
|
content = service_template.read_text(encoding="utf-8")
|
|
content = service_template.read_text(encoding="utf-8")
|
|
|
for placeholder, replacement in replacements.items():
|
|
for placeholder, replacement in replacements.items():
|
|
@@ -840,6 +859,104 @@ def render_mod_host_service(config):
|
|
|
return content.encode("utf-8")
|
|
return content.encode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def render_mod_host_ports_service(config):
|
|
|
|
|
+ state_file = ROOT / "config" / "desired-state.yaml"
|
|
|
|
|
+ runner_script = ROOT / config["runner_script"]
|
|
|
|
|
+ service_template = ROOT / config["service_source"]
|
|
|
|
|
+ binary = Path(config["binary_path"])
|
|
|
|
|
+ for description, path in (
|
|
|
|
|
+ ("mod-host port runner", runner_script),
|
|
|
|
|
+ ("mod-host ports service template", service_template),
|
|
|
|
|
+ ):
|
|
|
|
|
+ if not path.is_file():
|
|
|
|
|
+ raise RuntimeError(f"{description} is missing: {path}")
|
|
|
|
|
+
|
|
|
|
|
+ replacements = {
|
|
|
|
|
+ "@PYTHON@": systemd_quote(config["python_path"]),
|
|
|
|
|
+ "@RUNNER_SCRIPT@": systemd_quote(runner_script.resolve()),
|
|
|
|
|
+ "@DESIRED_STATE@": systemd_quote(state_file.resolve()),
|
|
|
|
|
+ "@PW_LOOPBACK@": systemd_quote(binary),
|
|
|
|
|
+ }
|
|
|
|
|
+ content = service_template.read_text(encoding="utf-8")
|
|
|
|
|
+ for placeholder, replacement in replacements.items():
|
|
|
|
|
+ content = content.replace(placeholder, replacement)
|
|
|
|
|
+ if re.search(r"@[A-Z_]+@", content):
|
|
|
|
|
+ raise RuntimeError("unexpanded placeholder remains in mod-host ports service template")
|
|
|
|
|
+ fingerprint = hashlib.sha256(
|
|
|
|
|
+ json.dumps(config, sort_keys=True, separators=(",", ":")).encode("utf-8")
|
|
|
|
|
+ + runner_script.read_bytes()
|
|
|
|
|
+ + (ROOT / "scripts" / "validate_desired_state.py").read_bytes()
|
|
|
|
|
+ + state_file.read_bytes()
|
|
|
|
|
+ ).hexdigest()
|
|
|
|
|
+ return {
|
|
|
|
|
+ "name": config["user_service"],
|
|
|
|
|
+ "destination": Path.home() / config["service_destination"],
|
|
|
|
|
+ "content": (content + f"\n# Rigforge runtime fingerprint: {fingerprint}\n").encode("utf-8"),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def render_mod_ui_service(config):
|
|
|
|
|
+ state_file = ROOT / "config" / "desired-state.yaml"
|
|
|
|
|
+ launcher = ROOT / config["launcher"]
|
|
|
|
|
+ runner_script = ROOT / config["runner_script"]
|
|
|
|
|
+ service_template = ROOT / config["service_source"]
|
|
|
|
|
+ with state_file.open(encoding="utf-8") as stream:
|
|
|
|
|
+ state = yaml.safe_load(stream)
|
|
|
|
|
+ reference_files = generate_bundle_files(state, ROOT)
|
|
|
|
|
+ bundle_digest = hashlib.sha256()
|
|
|
|
|
+ for name, content_bytes in sorted(reference_files.items()):
|
|
|
|
|
+ bundle_digest.update(name.encode("utf-8") + b"\0" + content_bytes + b"\0")
|
|
|
|
|
+ reference_pedalboard = (
|
|
|
|
|
+ Path.home()
|
|
|
|
|
+ / config["reference_directory"]
|
|
|
|
|
+ / f"rigforge-guitar-{bundle_digest.hexdigest()[:16]}.pedalboard"
|
|
|
|
|
+ )
|
|
|
|
|
+ for description, path in (
|
|
|
|
|
+ ("mod-ui launcher", launcher),
|
|
|
|
|
+ ("mod-ui service runner", runner_script),
|
|
|
|
|
+ ("mod-ui service template", service_template),
|
|
|
|
|
+ ):
|
|
|
|
|
+ if not path.is_file():
|
|
|
|
|
+ raise RuntimeError(f"{description} is missing: {path}")
|
|
|
|
|
+
|
|
|
|
|
+ home = Path.home()
|
|
|
|
|
+ replacements = {
|
|
|
|
|
+ "@PYTHON@": systemd_quote(config["python_path"]),
|
|
|
|
|
+ "@RUNNER_SCRIPT@": systemd_quote(runner_script.resolve()),
|
|
|
|
|
+ "@MOD_UI_LAUNCHER@": systemd_quote(launcher.resolve()),
|
|
|
|
|
+ "@PW_JACK@": systemd_quote(config["pw_jack_path"]),
|
|
|
|
|
+ "@WEBSOCKET_HOST@": config["websocket_host"],
|
|
|
|
|
+ "@WEBSOCKET_PORT@": str(config["websocket_port"]),
|
|
|
|
|
+ "@MOD_DATA_DIR@": systemd_quote(home / ".local" / "share" / "rigforge" / "mod-ui"),
|
|
|
|
|
+ "@MOD_LAST_STATE@": systemd_quote(home / config["last_state_file"]),
|
|
|
|
|
+ "@PEDALBOARDS_DIR@": systemd_quote(home / config["pedalboards_directory"]),
|
|
|
|
|
+ "@REFERENCE_PEDALBOARD@": systemd_quote(reference_pedalboard),
|
|
|
|
|
+ "@HARDWARE_INPUT_PORT@": config["hardware_input_port"],
|
|
|
|
|
+ "@HARDWARE_OUTPUT_PORT@": config["hardware_output_port"],
|
|
|
|
|
+ }
|
|
|
|
|
+ content = service_template.read_text(encoding="utf-8")
|
|
|
|
|
+ for placeholder, replacement in replacements.items():
|
|
|
|
|
+ content = content.replace(placeholder, replacement)
|
|
|
|
|
+ if re.search(r"@[A-Z_]+@", content):
|
|
|
|
|
+ raise RuntimeError("unexpanded placeholder remains in mod-ui service template")
|
|
|
|
|
+ artifact_root = ROOT / config["artifact_directory"]
|
|
|
|
|
+ runtime_digest = hashlib.sha256()
|
|
|
|
|
+ runtime_digest.update(runtime_tree_sha256(artifact_root).encode("ascii"))
|
|
|
|
|
+ runtime_digest.update(runner_script.read_bytes())
|
|
|
|
|
+ runtime_digest.update((ROOT / "scripts" / "mod_ui_websocket.py").read_bytes())
|
|
|
|
|
+ runtime_digest.update((ROOT / "scripts" / "generate_mod_ui_pedalboard.py").read_bytes())
|
|
|
|
|
+ for name, content_bytes in sorted(reference_files.items()):
|
|
|
|
|
+ runtime_digest.update(name.encode("utf-8") + b"\0" + content_bytes + b"\0")
|
|
|
|
|
+ content += f"\n# Rigforge runtime fingerprint: {runtime_digest.hexdigest()}\n"
|
|
|
|
|
+ return {
|
|
|
|
|
+ "name": config["user_service"],
|
|
|
|
|
+ "destination": home / config["service_destination"],
|
|
|
|
|
+ "content": content.encode("utf-8"),
|
|
|
|
|
+ "reference_bundle": reference_pedalboard,
|
|
|
|
|
+ "reference_files": reference_files,
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def render_reconcile_units(config):
|
|
def render_reconcile_units(config):
|
|
|
repository_root = ROOT.resolve()
|
|
repository_root = ROOT.resolve()
|
|
|
state_file = repository_root / "config" / "desired-state.yaml"
|
|
state_file = repository_root / "config" / "desired-state.yaml"
|
|
@@ -909,6 +1026,13 @@ def render_midi_bridge_service(config):
|
|
|
content = content.replace(placeholder, replacement)
|
|
content = content.replace(placeholder, replacement)
|
|
|
if re.search(r"@[A-Z_]+@", content):
|
|
if re.search(r"@[A-Z_]+@", content):
|
|
|
raise RuntimeError("unexpanded placeholder remains in MIDI bridge service template")
|
|
raise RuntimeError("unexpanded placeholder remains in MIDI bridge service template")
|
|
|
|
|
+ fingerprint = hashlib.sha256(
|
|
|
|
|
+ bridge_script.read_bytes()
|
|
|
|
|
+ + (ROOT / "scripts" / "mod_ui_websocket.py").read_bytes()
|
|
|
|
|
+ + (ROOT / "config" / "midi-bindings.yaml").read_bytes()
|
|
|
|
|
+ + state_file.read_bytes()
|
|
|
|
|
+ ).hexdigest()
|
|
|
|
|
+ content += f"\n# Rigforge runtime fingerprint: {fingerprint}\n"
|
|
|
return {
|
|
return {
|
|
|
"name": config["user_service"],
|
|
"name": config["user_service"],
|
|
|
"destination": Path.home() / config["service_destination"],
|
|
"destination": Path.home() / config["service_destination"],
|
|
@@ -1177,12 +1301,199 @@ def deploy_single_user_service(action, registry_key, target_name, display_name,
|
|
|
|
|
|
|
|
|
|
|
|
|
def deploy_midi_bridge(action, config, registry):
|
|
def deploy_midi_bridge(action, config, registry):
|
|
|
|
|
+ if action == "install" and "mod_ui" not in registry:
|
|
|
|
|
+ raise RuntimeError("install mod-ui before installing the MIDI bridge")
|
|
|
unit = render_midi_bridge_service(config)
|
|
unit = render_midi_bridge_service(config)
|
|
|
deploy_single_user_service(
|
|
deploy_single_user_service(
|
|
|
action, "midi_bridge", "midi-bridge", "MIDI bridge", unit, registry
|
|
action, "midi_bridge", "midi-bridge", "MIDI bridge", unit, registry
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def deploy_mod_host_ports(action, config, registry):
|
|
|
|
|
+ if action == "uninstall" and (
|
|
|
|
|
+ "mod_host" in registry or "mod_ui" in registry
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError("uninstall mod-ui and mod-host before uninstalling mod-host-ports")
|
|
|
|
|
+ unit = render_mod_host_ports_service(config)
|
|
|
|
|
+ deploy_single_user_service(
|
|
|
|
|
+ action,
|
|
|
|
|
+ "mod_host_ports",
|
|
|
|
|
+ "mod-host-ports",
|
|
|
|
|
+ "mod-host PipeWire ports",
|
|
|
|
|
+ unit,
|
|
|
|
|
+ registry,
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def deploy_mod_ui(action, config, registry):
|
|
|
|
|
+ if action == "install":
|
|
|
|
|
+ if "mod_host_ports" not in registry:
|
|
|
|
|
+ raise RuntimeError("install mod-host-ports before installing mod-ui")
|
|
|
|
|
+ if "mod_host" not in registry:
|
|
|
|
|
+ raise RuntimeError("install mod-host before installing mod-ui")
|
|
|
|
|
+ if "mod_ui" not in registry and mod_ui_port_is_open(
|
|
|
|
|
+ config["websocket_host"], config["websocket_port"]
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"mod-ui web port {config['websocket_port']} is already in use; "
|
|
|
|
|
+ "stop any manually launched mod-ui before installing the service"
|
|
|
|
|
+ )
|
|
|
|
|
+ if "mod_ui" not in registry and (
|
|
|
|
|
+ user_unit_is_active(config["user_service"])
|
|
|
|
|
+ or user_unit_is_enabled(config["user_service"])
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"an unmanaged {config['user_service']} is already active or enabled; "
|
|
|
|
|
+ "inspect it before installing Rigforge's unit"
|
|
|
|
|
+ )
|
|
|
|
|
+ if action == "reset":
|
|
|
|
|
+ reset_mod_ui_reference(config, registry)
|
|
|
|
|
+ return
|
|
|
|
|
+ if action == "uninstall" and "midi_bridge" in registry:
|
|
|
|
|
+ raise RuntimeError("uninstall midi-bridge before uninstalling mod-ui")
|
|
|
|
|
+ unit = render_mod_ui_service(config)
|
|
|
|
|
+ reference_sha256 = None
|
|
|
|
|
+ if action != "uninstall":
|
|
|
|
|
+ reference_sha256 = prepare_mod_ui_reference_bundle(unit)
|
|
|
|
|
+ deploy_single_user_service(
|
|
|
|
|
+ action,
|
|
|
|
|
+ "mod_ui",
|
|
|
|
|
+ "mod-ui",
|
|
|
|
|
+ "mod-ui",
|
|
|
|
|
+ unit,
|
|
|
|
|
+ registry,
|
|
|
|
|
+ )
|
|
|
|
|
+ if action == "install":
|
|
|
|
|
+ registry["mod_ui"]["reference_bundle"] = {
|
|
|
|
|
+ "destination": str(unit["reference_bundle"]),
|
|
|
|
|
+ "installed_sha256": reference_sha256,
|
|
|
|
|
+ }
|
|
|
|
|
+ write_registry(registry)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def next_reset_backup_path(path):
|
|
|
|
|
+ base = path.with_name(path.name + ".rigforge-reset-backup")
|
|
|
|
|
+ candidate = base
|
|
|
|
|
+ suffix = 1
|
|
|
|
|
+ while candidate.exists() or candidate.is_symlink():
|
|
|
|
|
+ suffix += 1
|
|
|
|
|
+ candidate = base.with_name(base.name + f".{suffix}")
|
|
|
|
|
+ validate_user_destination(candidate)
|
|
|
|
|
+ return candidate
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def prepare_mod_ui_reference_bundle(unit):
|
|
|
|
|
+ destination = unit["reference_bundle"]
|
|
|
|
|
+ files = unit["reference_files"]
|
|
|
|
|
+ validate_user_destination(destination)
|
|
|
|
|
+ if destination.exists():
|
|
|
|
|
+ if destination.is_symlink() or not destination.is_dir():
|
|
|
|
|
+ raise RuntimeError(f"generated mod-ui reference path has the wrong type: {destination}")
|
|
|
|
|
+ current_files = {}
|
|
|
|
|
+ for path in destination.rglob("*"):
|
|
|
|
|
+ if path.is_symlink():
|
|
|
|
|
+ raise RuntimeError(f"generated mod-ui reference contains a symlink: {path}")
|
|
|
|
|
+ if path.is_file():
|
|
|
|
|
+ current_files[path.relative_to(destination).as_posix()] = path.read_bytes()
|
|
|
|
|
+ if current_files != files:
|
|
|
|
|
+ raise RuntimeError(f"generated mod-ui reference changed locally: {destination}")
|
|
|
|
|
+ else:
|
|
|
|
|
+ destination.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ staged = Path(tempfile.mkdtemp(prefix=f".{destination.name}.", dir=destination.parent))
|
|
|
|
|
+ try:
|
|
|
|
|
+ for relative, content in files.items():
|
|
|
|
|
+ path = staged / relative
|
|
|
|
|
+ path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ path.write_bytes(content)
|
|
|
|
|
+ os.replace(staged, destination)
|
|
|
|
|
+ finally:
|
|
|
|
|
+ if staged.exists():
|
|
|
|
|
+ shutil.rmtree(staged)
|
|
|
|
|
+ return tree_sha256(destination)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def reset_mod_ui_reference(config, registry):
|
|
|
|
|
+ managed = registry.get("mod_ui")
|
|
|
|
|
+ if managed is None:
|
|
|
|
|
+ raise RuntimeError("mod-ui is not managed; install mod-ui before resetting it")
|
|
|
|
|
+ if managed.get("pending_uninstall"):
|
|
|
|
|
+ raise RuntimeError("mod-ui uninstall is incomplete; retry uninstall mod-ui first")
|
|
|
|
|
+ unit = render_mod_ui_service(config)
|
|
|
|
|
+ destination = unit["destination"]
|
|
|
|
|
+ if not destination.is_file() or file_sha256(destination) != managed.get("installed_sha256"):
|
|
|
|
|
+ raise RuntimeError(f"managed mod-ui service file changed locally: {destination}")
|
|
|
|
|
+
|
|
|
|
|
+ reference = unit["reference_bundle"]
|
|
|
|
|
+ reference_record = managed.get("reference_bundle")
|
|
|
|
|
+ if not isinstance(reference_record, dict):
|
|
|
|
|
+ raise RuntimeError("mod-ui reference bundle is missing from the deployment registry")
|
|
|
|
|
+ reference_sha256 = reference_record.get("installed_sha256")
|
|
|
|
|
+ if (
|
|
|
|
|
+ reference_record.get("destination") != str(reference)
|
|
|
|
|
+ or not reference.is_dir()
|
|
|
|
|
+ or tree_sha256(reference) != reference_sha256
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError(f"managed mod-ui reference pedalboard changed locally: {reference}")
|
|
|
|
|
+ pedalboards = Path.home() / config["pedalboards_directory"]
|
|
|
|
|
+ default_board = pedalboards / "default.pedalboard"
|
|
|
|
|
+ last_state = Path.home() / config["last_state_file"]
|
|
|
|
|
+ for path in (default_board, last_state):
|
|
|
|
|
+ validate_user_destination(path)
|
|
|
|
|
+ if path.is_symlink():
|
|
|
|
|
+ raise RuntimeError(f"refusing to reset a symlink: {path}")
|
|
|
|
|
+ if default_board.exists() and not default_board.is_dir():
|
|
|
|
|
+ raise RuntimeError(f"mod-ui default pedalboard has the wrong type: {default_board}")
|
|
|
|
|
+ if last_state.exists() and not last_state.is_file():
|
|
|
|
|
+ raise RuntimeError(f"mod-ui last-state path has the wrong type: {last_state}")
|
|
|
|
|
+
|
|
|
|
|
+ backup_board = next_reset_backup_path(default_board)
|
|
|
|
|
+ backup_state = next_reset_backup_path(last_state)
|
|
|
|
|
+
|
|
|
|
|
+ staged = default_board.with_name(default_board.name + ".rigforge-reset-new")
|
|
|
|
|
+ if staged.exists() or staged.is_symlink():
|
|
|
|
|
+ raise RuntimeError(f"reset staging path already exists: {staged}")
|
|
|
|
|
+ default_board.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ shutil.copytree(reference, staged, symlinks=False)
|
|
|
|
|
+ run(["systemctl", "--user", "stop", config["user_service"]])
|
|
|
|
|
+ board_backed_up = False
|
|
|
|
|
+ state_backed_up = False
|
|
|
|
|
+ reference_installed = False
|
|
|
|
|
+ try:
|
|
|
|
|
+ if default_board.exists():
|
|
|
|
|
+ os.replace(default_board, backup_board)
|
|
|
|
|
+ board_backed_up = True
|
|
|
|
|
+ if last_state.exists():
|
|
|
|
|
+ os.replace(last_state, backup_state)
|
|
|
|
|
+ state_backed_up = True
|
|
|
|
|
+ os.replace(staged, default_board)
|
|
|
|
|
+ reference_installed = True
|
|
|
|
|
+ run(["systemctl", "--user", "start", config["user_service"]])
|
|
|
|
|
+ run(["systemctl", "--user", "is-active", "--quiet", config["user_service"]])
|
|
|
|
|
+ if "midi_bridge" in registry:
|
|
|
|
|
+ run(["systemctl", "--user", "start", "rigforge-midi-bridge.service"])
|
|
|
|
|
+ run(["systemctl", "--user", "is-active", "--quiet", "rigforge-midi-bridge.service"])
|
|
|
|
|
+ except (OSError, subprocess.CalledProcessError):
|
|
|
|
|
+ try:
|
|
|
|
|
+ run(["systemctl", "--user", "stop", config["user_service"]])
|
|
|
|
|
+ except subprocess.CalledProcessError:
|
|
|
|
|
+ pass
|
|
|
|
|
+ if staged.exists():
|
|
|
|
|
+ shutil.rmtree(staged)
|
|
|
|
|
+ if reference_installed and default_board.exists():
|
|
|
|
|
+ shutil.rmtree(default_board)
|
|
|
|
|
+ if board_backed_up and backup_board.exists():
|
|
|
|
|
+ os.replace(backup_board, default_board)
|
|
|
|
|
+ if state_backed_up and backup_state.exists():
|
|
|
|
|
+ os.replace(backup_state, last_state)
|
|
|
|
|
+ run(["systemctl", "--user", "start", config["user_service"]])
|
|
|
|
|
+ raise
|
|
|
|
|
+
|
|
|
|
|
+ print(
|
|
|
|
|
+ "Rigforge reference pedalboard restored. Previous default and last-state data "
|
|
|
|
|
+ "were preserved as adjacent .rigforge-reset-backup files when present."
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def deploy_sooperlooper(action, config, registry, state=None):
|
|
def deploy_sooperlooper(action, config, registry, state=None):
|
|
|
if state is None:
|
|
if state is None:
|
|
|
state = yaml.safe_load(
|
|
state = yaml.safe_load(
|
|
@@ -1425,7 +1736,6 @@ def deploy_reconcile(action, config, registry):
|
|
|
|
|
|
|
|
def mod_host_runtime_digest(config):
|
|
def mod_host_runtime_digest(config):
|
|
|
state_path = ROOT / "config" / "desired-state.yaml"
|
|
state_path = ROOT / "config" / "desired-state.yaml"
|
|
|
- script_path = ROOT / config["configure_script"]
|
|
|
|
|
readiness_script = ROOT / config["readiness_script"]
|
|
readiness_script = ROOT / config["readiness_script"]
|
|
|
validator_path = ROOT / "scripts" / "validate_desired_state.py"
|
|
validator_path = ROOT / "scripts" / "validate_desired_state.py"
|
|
|
binary_path = ROOT / config["binary_source"]
|
|
binary_path = ROOT / config["binary_source"]
|
|
@@ -1433,20 +1743,16 @@ def mod_host_runtime_digest(config):
|
|
|
state = yaml.safe_load(stream)
|
|
state = yaml.safe_load(stream)
|
|
|
guitar_chain = state["routing"]["mod_host_chains"]["guitar"]
|
|
guitar_chain = state["routing"]["mod_host_chains"]["guitar"]
|
|
|
mod_host_config = state["deployment"]["mod_host"]
|
|
mod_host_config = state["deployment"]["mod_host"]
|
|
|
- files = [script_path, readiness_script, validator_path, binary_path]
|
|
|
|
|
- for processor in guitar_chain["processors"]:
|
|
|
|
|
- asset_path = PurePosixPath(processor["asset_path"])
|
|
|
|
|
- if asset_path.is_absolute() or ".." in asset_path.parts:
|
|
|
|
|
- raise RuntimeError(f"unsafe mod-host asset path: {processor['asset_path']!r}")
|
|
|
|
|
- resolved = (ROOT / Path(*asset_path.parts)).resolve()
|
|
|
|
|
- if not resolved.is_relative_to(ROOT.resolve()) or not resolved.is_file():
|
|
|
|
|
- raise RuntimeError(f"declared mod-host asset is missing or escapes the repository: {resolved}")
|
|
|
|
|
- files.append(resolved)
|
|
|
|
|
|
|
+ files = [readiness_script, validator_path, binary_path]
|
|
|
|
|
|
|
|
digest = hashlib.sha256()
|
|
digest = hashlib.sha256()
|
|
|
digest.update(
|
|
digest.update(
|
|
|
json.dumps(
|
|
json.dumps(
|
|
|
- {"deployment.mod_host": mod_host_config, "routing.mod_host_chains.guitar": guitar_chain},
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ "deployment.mod_host": mod_host_config,
|
|
|
|
|
+ "deployment.mod_host_ports": state["deployment"]["mod_host_ports"],
|
|
|
|
|
+ "routing.mod_host_chains.guitar": guitar_chain,
|
|
|
|
|
+ },
|
|
|
sort_keys=True,
|
|
sort_keys=True,
|
|
|
separators=(",", ":"),
|
|
separators=(",", ":"),
|
|
|
).encode("utf-8")
|
|
).encode("utf-8")
|
|
@@ -1469,6 +1775,14 @@ def mod_host_port_is_open(port):
|
|
|
return False
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def mod_ui_port_is_open(host, port):
|
|
|
|
|
+ try:
|
|
|
|
|
+ with socket.create_connection((host, port), timeout=0.25):
|
|
|
|
|
+ return True
|
|
|
|
|
+ except OSError:
|
|
|
|
|
+ return False
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def user_unit_is_active(service_name):
|
|
def user_unit_is_active(service_name):
|
|
|
result = subprocess.run(
|
|
result = subprocess.run(
|
|
|
["systemctl", "--user", "is-active", "--quiet", service_name],
|
|
["systemctl", "--user", "is-active", "--quiet", service_name],
|
|
@@ -1495,6 +1809,23 @@ def deploy_mod_host(action, config, registry):
|
|
|
service_name = config["user_service"]
|
|
service_name = config["user_service"]
|
|
|
managed = registry.get("mod_host")
|
|
managed = registry.get("mod_host")
|
|
|
|
|
|
|
|
|
|
+ if action == "install" and "mod_host_ports" not in registry:
|
|
|
|
|
+ raise RuntimeError("install mod-host-ports before installing mod-host")
|
|
|
|
|
+ if action == "uninstall" and "mod_ui" in registry:
|
|
|
|
|
+ raise RuntimeError("uninstall mod-ui before uninstalling mod-host")
|
|
|
|
|
+ if managed is not None and not user_unit_is_active(service_name):
|
|
|
|
|
+ occupied_ports = [
|
|
|
|
|
+ port
|
|
|
|
|
+ for port in (config["socket_port"], config["feedback_port"])
|
|
|
|
|
+ if mod_host_port_is_open(port)
|
|
|
|
|
+ ]
|
|
|
|
|
+ if occupied_ports:
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ "mod-host TCP port(s) "
|
|
|
|
|
+ f"{occupied_ports} are open while the managed service is inactive; "
|
|
|
|
|
+ "stop any unmanaged/manual mod-host process before retrying"
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
if action == "reload":
|
|
if action == "reload":
|
|
|
if managed is None:
|
|
if managed is None:
|
|
|
raise RuntimeError("mod-host is not managed; install mod-host before reloading it")
|
|
raise RuntimeError("mod-host is not managed; install mod-host before reloading it")
|
|
@@ -1609,6 +1940,11 @@ def deploy_mod_host(action, config, registry):
|
|
|
f"mod-host control port {config['socket_port']} is already in use; "
|
|
f"mod-host control port {config['socket_port']} is already in use; "
|
|
|
"stop the unmanaged test process before installing the user service"
|
|
"stop the unmanaged test process before installing the user service"
|
|
|
)
|
|
)
|
|
|
|
|
+ if mod_host_port_is_open(config["feedback_port"]):
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"mod-host feedback port {config['feedback_port']} is already in use; "
|
|
|
|
|
+ "stop the unmanaged test process before installing the user service"
|
|
|
|
|
+ )
|
|
|
backup = None
|
|
backup = None
|
|
|
backup_sha256 = None
|
|
backup_sha256 = None
|
|
|
if destination.exists():
|
|
if destination.exists():
|
|
@@ -1671,7 +2007,7 @@ def deploy_mod_host(action, config, registry):
|
|
|
|
|
|
|
|
def main(argv=None):
|
|
def main(argv=None):
|
|
|
parser = argparse.ArgumentParser()
|
|
parser = argparse.ArgumentParser()
|
|
|
- parser.add_argument("action", choices=("install", "uninstall", "reload"))
|
|
|
|
|
|
|
+ parser.add_argument("action", choices=("install", "uninstall", "reload", "reset"))
|
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
|
"target",
|
|
"target",
|
|
|
choices=(
|
|
choices=(
|
|
@@ -1679,13 +2015,17 @@ def main(argv=None):
|
|
|
"lsp",
|
|
"lsp",
|
|
|
"dragonfly-reverb",
|
|
"dragonfly-reverb",
|
|
|
"pipewire",
|
|
"pipewire",
|
|
|
|
|
+ "mod-host-ports",
|
|
|
"mod-host",
|
|
"mod-host",
|
|
|
|
|
+ "mod-ui",
|
|
|
"reconcile",
|
|
"reconcile",
|
|
|
"midi-bridge",
|
|
"midi-bridge",
|
|
|
"sooperlooper",
|
|
"sooperlooper",
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
args = parser.parse_args(argv)
|
|
args = parser.parse_args(argv)
|
|
|
|
|
+ if args.action == "reset" and args.target != "mod-ui":
|
|
|
|
|
+ parser.error("reset is only supported for mod-ui")
|
|
|
try:
|
|
try:
|
|
|
state = yaml.safe_load((ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8"))
|
|
state = yaml.safe_load((ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8"))
|
|
|
deployment = load_deployment()
|
|
deployment = load_deployment()
|
|
@@ -1699,6 +2039,10 @@ def main(argv=None):
|
|
|
deploy_pipewire(args.action, deployment["pipewire"], registry, quantum_frames)
|
|
deploy_pipewire(args.action, deployment["pipewire"], registry, quantum_frames)
|
|
|
elif args.target == "mod-host":
|
|
elif args.target == "mod-host":
|
|
|
deploy_mod_host(args.action, deployment["mod_host"], registry)
|
|
deploy_mod_host(args.action, deployment["mod_host"], registry)
|
|
|
|
|
+ elif args.target == "mod-host-ports":
|
|
|
|
|
+ deploy_mod_host_ports(args.action, deployment["mod_host_ports"], registry)
|
|
|
|
|
+ elif args.target == "mod-ui":
|
|
|
|
|
+ deploy_mod_ui(args.action, deployment["mod_ui"], registry)
|
|
|
elif args.target == "reconcile":
|
|
elif args.target == "reconcile":
|
|
|
deploy_reconcile(args.action, deployment["reconcile"], registry)
|
|
deploy_reconcile(args.action, deployment["reconcile"], registry)
|
|
|
elif args.target == "midi-bridge":
|
|
elif args.target == "midi-bridge":
|