|
|
@@ -36,17 +36,19 @@ def load_deployment():
|
|
|
if not isinstance(deployment, dict):
|
|
|
raise ValueError("deployment must be a mapping")
|
|
|
namlv2 = deployment.get("namlv2")
|
|
|
+ sooperlooper = deployment.get("sooperlooper")
|
|
|
pipewire = deployment.get("pipewire")
|
|
|
reconcile = deployment.get("reconcile")
|
|
|
midi_bridge = deployment.get("midi_bridge")
|
|
|
if (
|
|
|
not isinstance(namlv2, dict)
|
|
|
+ or not isinstance(sooperlooper, dict)
|
|
|
or not isinstance(pipewire, dict)
|
|
|
or not isinstance(reconcile, dict)
|
|
|
or not isinstance(midi_bridge, dict)
|
|
|
):
|
|
|
raise ValueError(
|
|
|
- "deployment.namlv2, deployment.pipewire, deployment.reconcile, "
|
|
|
+ "deployment.namlv2, deployment.sooperlooper, deployment.pipewire, deployment.reconcile, "
|
|
|
"and deployment.midi_bridge must be mappings"
|
|
|
)
|
|
|
for component, archive_format in PLUGIN_ARCHIVES.items():
|
|
|
@@ -914,6 +916,66 @@ def render_midi_bridge_service(config):
|
|
|
}
|
|
|
|
|
|
|
|
|
+def render_sooperlooper_service(config, state):
|
|
|
+ repository_root = ROOT.resolve()
|
|
|
+ binary = repository_root / config["binary_source"]
|
|
|
+ service_template = repository_root / config["service_source"]
|
|
|
+ binding_file = repository_root / config["binding_file"]
|
|
|
+ for description, path in (
|
|
|
+ ("ARM64 SooperLooper artifact", binary),
|
|
|
+ ("SooperLooper service template", service_template),
|
|
|
+ ("SooperLooper MIDI binding file", binding_file),
|
|
|
+ ):
|
|
|
+ if not path.is_file():
|
|
|
+ raise RuntimeError(f"{description} is missing: {path}")
|
|
|
+ if not os.access(binary, os.X_OK):
|
|
|
+ raise RuntimeError(f"ARM64 SooperLooper artifact is not executable: {binary}")
|
|
|
+
|
|
|
+ components = state.get("system", {}).get("components", [])
|
|
|
+ loopers = [
|
|
|
+ component for component in components
|
|
|
+ if isinstance(component, dict) and component.get("id") == "looper"
|
|
|
+ ] if isinstance(components, list) else []
|
|
|
+ if len(loopers) != 1:
|
|
|
+ raise RuntimeError("desired state must declare exactly one SooperLooper component")
|
|
|
+ loop_count = loopers[0].get("loop_count")
|
|
|
+ channels_per_loop = loopers[0].get("channels_per_loop")
|
|
|
+ if (
|
|
|
+ not isinstance(loop_count, int)
|
|
|
+ or isinstance(loop_count, bool)
|
|
|
+ or loop_count < 1
|
|
|
+ or not isinstance(channels_per_loop, int)
|
|
|
+ or isinstance(channels_per_loop, bool)
|
|
|
+ or channels_per_loop < 1
|
|
|
+ ):
|
|
|
+ raise RuntimeError("desired SooperLooper loop and channel counts must be positive integers")
|
|
|
+
|
|
|
+ osc = config["osc"]
|
|
|
+ replacements = {
|
|
|
+ "@PW_JACK@": systemd_quote(config["pw_jack_path"]),
|
|
|
+ "@SOOPERLOOPER_BINARY@": systemd_quote(binary.resolve()),
|
|
|
+ "@LOOP_COUNT@": str(loop_count),
|
|
|
+ "@CHANNELS_PER_LOOP@": str(channels_per_loop),
|
|
|
+ "@TIMEOUT_SECONDS@": str(config["timeout_seconds"]),
|
|
|
+ "@BINDING_FILE@": systemd_quote(binding_file.resolve()),
|
|
|
+ "@POST_START_DELAY_SECONDS@": str(osc["post_start_delay_seconds"]),
|
|
|
+ "@OSCSEND@": systemd_quote(config["oscsend_path"]),
|
|
|
+ "@OSC_HOST@": systemd_quote(osc["host"]),
|
|
|
+ "@OSC_PORT@": str(osc["port"]),
|
|
|
+ "@DISCRETE_PREFADER@": str(osc["discrete_prefader"]),
|
|
|
+ }
|
|
|
+ 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 SooperLooper service template")
|
|
|
+ return {
|
|
|
+ "name": config["user_service"],
|
|
|
+ "destination": Path.home() / config["service_destination"],
|
|
|
+ "content": content.encode("utf-8"),
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
def atomic_install_bytes(content, destination):
|
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
|
fd, temporary_name = tempfile.mkstemp(prefix=f".{destination.name}.", dir=destination.parent)
|
|
|
@@ -927,51 +989,56 @@ def atomic_install_bytes(content, destination):
|
|
|
os.unlink(temporary_name)
|
|
|
|
|
|
|
|
|
-def deploy_midi_bridge(action, config, registry):
|
|
|
- unit = render_midi_bridge_service(config)
|
|
|
+def deploy_single_user_service(action, registry_key, target_name, display_name, unit, registry):
|
|
|
destination = unit["destination"]
|
|
|
service_name = unit["name"]
|
|
|
validate_user_destination(destination)
|
|
|
if destination.exists() and not destination.is_file():
|
|
|
- raise RuntimeError(f"MIDI bridge service destination has the wrong type: {destination}")
|
|
|
- managed = registry.get("midi_bridge")
|
|
|
+ raise RuntimeError(f"{display_name} service destination has the wrong type: {destination}")
|
|
|
+ managed = registry.get(registry_key)
|
|
|
|
|
|
if action == "reload":
|
|
|
if managed is None:
|
|
|
- raise RuntimeError("MIDI bridge is not managed; install midi-bridge before reloading it")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"{display_name} is not managed; install {target_name} before reloading it"
|
|
|
+ )
|
|
|
if managed.get("pending_uninstall"):
|
|
|
- raise RuntimeError("MIDI bridge uninstall is incomplete; retry uninstall midi-bridge first")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"{display_name} uninstall is incomplete; retry uninstall {target_name} first"
|
|
|
+ )
|
|
|
if not destination.is_file():
|
|
|
- raise RuntimeError(f"managed MIDI bridge service file is missing: {destination}")
|
|
|
+ raise RuntimeError(f"managed {display_name} service file is missing: {destination}")
|
|
|
if file_sha256(destination) != managed.get("installed_sha256"):
|
|
|
- raise RuntimeError(f"managed MIDI bridge service file changed locally: {destination}")
|
|
|
+ raise RuntimeError(f"managed {display_name} service file changed locally: {destination}")
|
|
|
run(["systemctl", "--user", "restart", service_name])
|
|
|
run(["systemctl", "--user", "is-active", "--quiet", service_name])
|
|
|
- print("Rigforge MIDI bridge user service restarted.")
|
|
|
+ print(f"Rigforge {display_name} user service restarted.")
|
|
|
return
|
|
|
|
|
|
if action == "uninstall":
|
|
|
if managed is None:
|
|
|
- print("No managed MIDI bridge service to uninstall.")
|
|
|
+ print(f"No managed {display_name} service to uninstall.")
|
|
|
return
|
|
|
backup_path = validate_backup_path(managed.get("backup"), destination)
|
|
|
backup_digest = managed.get("backup_sha256")
|
|
|
if backup_path is not None and backup_path.exists():
|
|
|
if not backup_path.is_file() or file_sha256(backup_path) != backup_digest:
|
|
|
- raise RuntimeError(f"recorded MIDI bridge service backup changed locally: {backup_path}")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"recorded {display_name} service backup changed locally: {backup_path}"
|
|
|
+ )
|
|
|
elif backup_path is not None and not managed.get("pending_uninstall"):
|
|
|
- raise RuntimeError(f"recorded MIDI bridge service backup is missing: {backup_path}")
|
|
|
+ raise RuntimeError(f"recorded {display_name} service backup is missing: {backup_path}")
|
|
|
if (backup_path is None) != (backup_digest is None):
|
|
|
- raise RuntimeError("invalid MIDI bridge service backup record")
|
|
|
+ raise RuntimeError(f"invalid {display_name} service backup record")
|
|
|
|
|
|
current_digest = file_sha256(destination)
|
|
|
recoverable_digests = {managed.get("installed_sha256"), backup_digest, None}
|
|
|
if managed.get("pending_uninstall"):
|
|
|
if current_digest not in recoverable_digests:
|
|
|
- raise RuntimeError(f"unexpected file blocks MIDI bridge uninstall: {destination}")
|
|
|
+ raise RuntimeError(f"unexpected file blocks {display_name} uninstall: {destination}")
|
|
|
elif current_digest != managed.get("installed_sha256"):
|
|
|
raise RuntimeError(
|
|
|
- f"managed MIDI bridge service file changed locally; refusing removal: {destination}"
|
|
|
+ f"managed {display_name} service file changed locally; refusing removal: {destination}"
|
|
|
)
|
|
|
if (
|
|
|
backup_path is not None
|
|
|
@@ -979,11 +1046,11 @@ def deploy_midi_bridge(action, config, registry):
|
|
|
and current_digest == managed.get("installed_sha256")
|
|
|
):
|
|
|
raise RuntimeError(
|
|
|
- f"recorded MIDI bridge service backup is missing; refusing removal: {backup_path}"
|
|
|
+ f"recorded {display_name} service backup is missing; refusing removal: {backup_path}"
|
|
|
)
|
|
|
|
|
|
managed["pending_uninstall"] = True
|
|
|
- registry["midi_bridge"] = managed
|
|
|
+ registry[registry_key] = managed
|
|
|
write_registry(registry)
|
|
|
run(["systemctl", "--user", "disable", "--now", service_name])
|
|
|
if backup_path is not None and current_digest == backup_digest:
|
|
|
@@ -993,22 +1060,26 @@ def deploy_midi_bridge(action, config, registry):
|
|
|
if current_digest == managed.get("installed_sha256"):
|
|
|
destination.unlink()
|
|
|
elif current_digest is not None:
|
|
|
- raise RuntimeError(f"unexpected file blocks MIDI bridge uninstall: {destination}")
|
|
|
+ raise RuntimeError(f"unexpected file blocks {display_name} uninstall: {destination}")
|
|
|
if backup_path is not None:
|
|
|
if backup_path.exists():
|
|
|
os.replace(backup_path, destination)
|
|
|
elif file_sha256(destination) != backup_digest:
|
|
|
- raise RuntimeError(f"recorded MIDI bridge service backup is missing: {backup_path}")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"recorded {display_name} service backup is missing: {backup_path}"
|
|
|
+ )
|
|
|
run(["systemctl", "--user", "daemon-reload"])
|
|
|
- registry.pop("midi_bridge")
|
|
|
+ registry.pop(registry_key)
|
|
|
write_registry(registry)
|
|
|
- print("Rigforge MIDI bridge user service removed; prior unit restored if present.")
|
|
|
+ print(f"Rigforge {display_name} user service removed; prior unit restored if present.")
|
|
|
return
|
|
|
|
|
|
content = unit["content"]
|
|
|
installed_digest = hashlib.sha256(content).hexdigest()
|
|
|
if managed is not None and managed.get("pending_uninstall"):
|
|
|
- raise RuntimeError("MIDI bridge uninstall is incomplete; retry uninstall midi-bridge first")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"{display_name} uninstall is incomplete; retry uninstall {target_name} first"
|
|
|
+ )
|
|
|
if managed is None:
|
|
|
if user_unit_is_active(service_name) or user_unit_is_enabled(service_name):
|
|
|
raise RuntimeError(
|
|
|
@@ -1028,17 +1099,19 @@ def deploy_midi_bridge(action, config, registry):
|
|
|
pending_install = True
|
|
|
else:
|
|
|
if managed.get("destination") != str(destination):
|
|
|
- raise RuntimeError("recorded MIDI bridge service path changed")
|
|
|
+ raise RuntimeError(f"recorded {display_name} service path changed")
|
|
|
backup_path = validate_backup_path(managed.get("backup"), destination)
|
|
|
backup = str(backup_path) if backup_path is not None else None
|
|
|
backup_digest = managed.get("backup_sha256")
|
|
|
if (backup_path is None) != (backup_digest is None):
|
|
|
- raise RuntimeError("invalid MIDI bridge service backup record")
|
|
|
+ raise RuntimeError(f"invalid {display_name} service backup record")
|
|
|
if backup_path is not None and backup_path.exists():
|
|
|
if not backup_path.is_file() or file_sha256(backup_path) != backup_digest:
|
|
|
- raise RuntimeError(f"recorded MIDI bridge service backup changed locally: {backup_path}")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"recorded {display_name} service backup changed locally: {backup_path}"
|
|
|
+ )
|
|
|
elif backup_path is not None and not managed.get("pending_install"):
|
|
|
- raise RuntimeError(f"recorded MIDI bridge service backup is missing: {backup_path}")
|
|
|
+ raise RuntimeError(f"recorded {display_name} service backup is missing: {backup_path}")
|
|
|
previous_digest = (
|
|
|
managed.get("previous_installed_sha256")
|
|
|
if managed.get("pending_install")
|
|
|
@@ -1047,9 +1120,11 @@ def deploy_midi_bridge(action, config, registry):
|
|
|
current_digest = file_sha256(destination)
|
|
|
if managed.get("pending_install"):
|
|
|
if current_digest not in {previous_digest, backup_digest, None}:
|
|
|
- raise RuntimeError(f"MIDI bridge service changed locally during interrupted install: {destination}")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"{display_name} service changed locally during interrupted install: {destination}"
|
|
|
+ )
|
|
|
elif current_digest != previous_digest:
|
|
|
- raise RuntimeError(f"managed MIDI bridge service file changed locally: {destination}")
|
|
|
+ raise RuntimeError(f"managed {display_name} service file changed locally: {destination}")
|
|
|
pending_install = current_digest != installed_digest
|
|
|
|
|
|
unit_changed = file_sha256(destination) != installed_digest
|
|
|
@@ -1066,23 +1141,25 @@ def deploy_midi_bridge(action, config, registry):
|
|
|
"pending_install": pending_install,
|
|
|
"pending_activation": True,
|
|
|
})
|
|
|
- registry["midi_bridge"] = managed
|
|
|
+ registry[registry_key] = managed
|
|
|
write_registry(registry)
|
|
|
|
|
|
if backup_path is not None:
|
|
|
if backup_path.exists():
|
|
|
if not backup_path.is_file() or file_sha256(backup_path) != backup_digest:
|
|
|
- raise RuntimeError(f"recorded MIDI bridge service backup changed locally: {backup_path}")
|
|
|
+ raise RuntimeError(
|
|
|
+ f"recorded {display_name} service backup changed locally: {backup_path}"
|
|
|
+ )
|
|
|
elif file_sha256(destination) == backup_digest:
|
|
|
shutil.copy2(destination, backup_path)
|
|
|
else:
|
|
|
- raise RuntimeError(f"recorded MIDI bridge service backup is missing: {backup_path}")
|
|
|
+ raise RuntimeError(f"recorded {display_name} service backup is missing: {backup_path}")
|
|
|
if unit_changed:
|
|
|
atomic_install_bytes(content, destination)
|
|
|
|
|
|
managed.pop("previous_installed_sha256", None)
|
|
|
managed.pop("pending_install", None)
|
|
|
- registry["midi_bridge"] = managed
|
|
|
+ registry[registry_key] = managed
|
|
|
write_registry(registry)
|
|
|
run(["systemctl", "--user", "daemon-reload"])
|
|
|
run(["systemctl", "--user", "enable", service_name])
|
|
|
@@ -1094,9 +1171,27 @@ def deploy_midi_bridge(action, config, registry):
|
|
|
])
|
|
|
run(["systemctl", "--user", "is-active", "--quiet", service_name])
|
|
|
managed.pop("pending_activation", None)
|
|
|
- registry["midi_bridge"] = managed
|
|
|
+ registry[registry_key] = managed
|
|
|
write_registry(registry)
|
|
|
- print(f"Installed and activated Rigforge MIDI bridge user service at {destination}.")
|
|
|
+ print(f"Installed and activated Rigforge {display_name} user service at {destination}.")
|
|
|
+
|
|
|
+
|
|
|
+def deploy_midi_bridge(action, config, registry):
|
|
|
+ unit = render_midi_bridge_service(config)
|
|
|
+ deploy_single_user_service(
|
|
|
+ action, "midi_bridge", "midi-bridge", "MIDI bridge", unit, registry
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+def deploy_sooperlooper(action, config, registry, state=None):
|
|
|
+ if state is None:
|
|
|
+ state = yaml.safe_load(
|
|
|
+ (ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
|
|
|
+ )
|
|
|
+ unit = render_sooperlooper_service(config, state)
|
|
|
+ deploy_single_user_service(
|
|
|
+ action, "sooperlooper", "sooperlooper", "SooperLooper", unit, registry
|
|
|
+ )
|
|
|
|
|
|
|
|
|
def file_sha256(path):
|
|
|
@@ -1587,6 +1682,7 @@ def main(argv=None):
|
|
|
"mod-host",
|
|
|
"reconcile",
|
|
|
"midi-bridge",
|
|
|
+ "sooperlooper",
|
|
|
),
|
|
|
)
|
|
|
args = parser.parse_args(argv)
|
|
|
@@ -1607,6 +1703,10 @@ def main(argv=None):
|
|
|
deploy_reconcile(args.action, deployment["reconcile"], registry)
|
|
|
elif args.target == "midi-bridge":
|
|
|
deploy_midi_bridge(args.action, deployment["midi_bridge"], registry)
|
|
|
+ elif args.target == "sooperlooper":
|
|
|
+ deploy_sooperlooper(
|
|
|
+ args.action, deployment["sooperlooper"], registry, state=state
|
|
|
+ )
|
|
|
else:
|
|
|
component = "dragonfly_reverb" if args.target == "dragonfly-reverb" else args.target
|
|
|
deploy_lv2_archives(args.action, component, deployment[component], registry)
|