|
@@ -38,6 +38,7 @@ def load_deployment():
|
|
|
raise ValueError("deployment must be a mapping")
|
|
raise ValueError("deployment must be a mapping")
|
|
|
namlv2 = deployment.get("namlv2")
|
|
namlv2 = deployment.get("namlv2")
|
|
|
sooperlooper = deployment.get("sooperlooper")
|
|
sooperlooper = deployment.get("sooperlooper")
|
|
|
|
|
+ slweb = deployment.get("slweb")
|
|
|
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")
|
|
@@ -46,6 +47,7 @@ def load_deployment():
|
|
|
if (
|
|
if (
|
|
|
not isinstance(namlv2, dict)
|
|
not isinstance(namlv2, dict)
|
|
|
or not isinstance(sooperlooper, dict)
|
|
or not isinstance(sooperlooper, dict)
|
|
|
|
|
+ or not isinstance(slweb, 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)
|
|
@@ -53,8 +55,9 @@ def load_deployment():
|
|
|
or not isinstance(mod_ui, dict)
|
|
or not isinstance(mod_ui, dict)
|
|
|
):
|
|
):
|
|
|
raise ValueError(
|
|
raise ValueError(
|
|
|
- "deployment.namlv2, deployment.sooperlooper, deployment.pipewire, deployment.reconcile, "
|
|
|
|
|
- "deployment.midi_bridge, deployment.mod_host_ports, and deployment.mod_ui must be mappings"
|
|
|
|
|
|
|
+ "deployment.namlv2, deployment.sooperlooper, deployment.slweb, deployment.pipewire, "
|
|
|
|
|
+ "deployment.reconcile, 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)
|
|
@@ -1230,6 +1233,252 @@ def render_sooperlooper_service(config, state):
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def slweb_tools_path(config):
|
|
|
|
|
+ relative = PurePosixPath(config.get("install_directory", ""))
|
|
|
|
|
+ if relative.is_absolute() or ".." in relative.parts or not relative.parts:
|
|
|
|
|
+ raise RuntimeError("SLWeb install directory must be a safe relative path")
|
|
|
|
|
+ destination = Path.home() / Path(*relative.parts)
|
|
|
|
|
+ validate_user_destination(destination)
|
|
|
|
|
+ return destination
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def extract_slweb_tools(archive_path, destination, source_directory):
|
|
|
|
|
+ source_root = PurePosixPath(source_directory)
|
|
|
|
|
+ if source_root.is_absolute() or ".." in source_root.parts or len(source_root.parts) != 1:
|
|
|
|
|
+ raise RuntimeError("SLWeb source directory must be one safe repository directory")
|
|
|
|
|
+
|
|
|
|
|
+ with tarfile.open(archive_path, "r:gz") as archive:
|
|
|
|
|
+ selected = []
|
|
|
|
|
+ roots = set()
|
|
|
|
|
+ for member in archive.getmembers():
|
|
|
|
|
+ member_path = PurePosixPath(member.name)
|
|
|
|
|
+ if (
|
|
|
|
|
+ member_path.is_absolute()
|
|
|
|
|
+ or ".." in member_path.parts
|
|
|
|
|
+ or len(member_path.parts) < 2
|
|
|
|
|
+ or member_path.parts[1] != source_root.name
|
|
|
|
|
+ ):
|
|
|
|
|
+ continue
|
|
|
|
|
+ roots.add(member_path.parts[0])
|
|
|
|
|
+ if not (member.isdir() or member.isfile()):
|
|
|
|
|
+ raise RuntimeError(f"unsupported SLWeb source member: {member.name}")
|
|
|
|
|
+ selected.append((member, member_path))
|
|
|
|
|
+
|
|
|
|
|
+ if len(roots) != 1:
|
|
|
|
|
+ raise RuntimeError("SooperLooper archive does not contain one tools directory")
|
|
|
|
|
+ if not selected:
|
|
|
|
|
+ raise RuntimeError("SooperLooper archive has no tools directory")
|
|
|
|
|
+
|
|
|
|
|
+ tools_root = destination / source_root.name
|
|
|
|
|
+ tools_root.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ for member, member_path in selected:
|
|
|
|
|
+ relative = PurePosixPath(*member_path.parts[2:])
|
|
|
|
|
+ if not relative.parts:
|
|
|
|
|
+ continue
|
|
|
|
|
+ output_path = tools_root.joinpath(*relative.parts)
|
|
|
|
|
+ if member.isdir():
|
|
|
|
|
+ output_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ output_path.chmod(0o755)
|
|
|
|
|
+ continue
|
|
|
|
|
+ output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ source = archive.extractfile(member)
|
|
|
|
|
+ if source is None:
|
|
|
|
|
+ raise RuntimeError(f"unable to read SLWeb source member: {member.name}")
|
|
|
|
|
+ with source, output_path.open("wb") as output:
|
|
|
|
|
+ shutil.copyfileobj(source, output)
|
|
|
|
|
+ output_path.chmod(0o755 if member.mode & 0o111 else 0o644)
|
|
|
|
|
+
|
|
|
|
|
+ required_files = (
|
|
|
|
|
+ tools_root / "slweb.py",
|
|
|
|
|
+ tools_root / "slweb_web" / "index.html",
|
|
|
|
|
+ tools_root / "slweb_web" / "app.css",
|
|
|
|
|
+ tools_root / "slweb_web" / "app.js",
|
|
|
|
|
+ )
|
|
|
|
|
+ if any(not path.is_file() for path in required_files):
|
|
|
|
|
+ raise RuntimeError("SooperLooper tools directory is missing SLWeb or its web assets")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def install_slweb_tools(config, source_config, registry):
|
|
|
|
|
+ destination = slweb_tools_path(config)
|
|
|
|
|
+ managed = registry.get("slweb")
|
|
|
|
|
+ if managed is not None:
|
|
|
|
|
+ if managed.get("destination") != str(destination):
|
|
|
|
|
+ raise RuntimeError("recorded SLWeb installation path changed")
|
|
|
|
|
+ if managed.get("pending_uninstall"):
|
|
|
|
|
+ raise RuntimeError("SLWeb uninstall is incomplete; retry uninstall slweb first")
|
|
|
|
|
+ backup = validate_backup_path(
|
|
|
|
|
+ managed.get("backup"), destination, is_directory=True
|
|
|
|
|
+ )
|
|
|
|
|
+ if (backup is None) != (managed.get("backup_sha256") is None):
|
|
|
|
|
+ raise RuntimeError("invalid SLWeb backup record")
|
|
|
|
|
+ if backup is not None and backup.exists():
|
|
|
|
|
+ if not backup.is_dir() or tree_sha256(backup) != managed.get("backup_sha256"):
|
|
|
|
|
+ raise RuntimeError(f"recorded SLWeb backup changed locally: {backup}")
|
|
|
|
|
+ elif backup is not None:
|
|
|
|
|
+ raise RuntimeError(f"recorded SLWeb backup is missing: {backup}")
|
|
|
|
|
+ if not destination.is_dir():
|
|
|
|
|
+ raise RuntimeError(f"managed SLWeb tools directory is missing: {destination}")
|
|
|
|
|
+ if tree_sha256(destination) != managed.get("installed_sha256"):
|
|
|
|
|
+ raise RuntimeError(f"managed SLWeb tools changed locally; refusing overwrite: {destination}")
|
|
|
|
|
+ if managed.get("tag") == source_config["tag"]:
|
|
|
|
|
+ print(f"SLWeb tools from SooperLooper tag {source_config['tag']} are already installed and unchanged.")
|
|
|
|
|
+ return managed
|
|
|
|
|
+
|
|
|
|
|
+ backup_path = destination.with_name(destination.name + ".rigforge-backup")
|
|
|
|
|
+ if managed is None and (backup_path.exists() or backup_path.is_symlink()):
|
|
|
|
|
+ raise RuntimeError(f"SLWeb backup path already exists: {backup_path}")
|
|
|
|
|
+ if destination.exists() and not destination.is_dir():
|
|
|
|
|
+ raise RuntimeError(f"SLWeb destination is not a directory: {destination}")
|
|
|
|
|
+
|
|
|
|
|
+ staged = destination.with_name(destination.name + ".rigforge-new")
|
|
|
|
|
+ previous = destination.with_name(destination.name + ".rigforge-old")
|
|
|
|
|
+ if staged.exists() or staged.is_symlink() or previous.exists() or previous.is_symlink():
|
|
|
|
|
+ raise RuntimeError(f"SLWeb staging or recovery path already exists: {destination}")
|
|
|
|
|
+
|
|
|
|
|
+ source_url = source_config["source_url"].rstrip("/")
|
|
|
|
|
+ tag = source_config["tag"]
|
|
|
|
|
+ if (
|
|
|
|
|
+ source_url != "https://github.com/jojolb/sooperlooper-mods"
|
|
|
|
|
+ or not isinstance(tag, str)
|
|
|
|
|
+ or not re.fullmatch(r"[A-Za-z0-9._-]+", tag)
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError("SLWeb requires the approved SooperLooper GitHub source and tag")
|
|
|
|
|
+ archive_url = f"{source_url}/archive/refs/tags/{tag}.tar.gz"
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ with tempfile.TemporaryDirectory(prefix="rigforge-slweb-") as temporary_dir:
|
|
|
|
|
+ temporary = Path(temporary_dir)
|
|
|
|
|
+ archive_path = temporary / "sooperlooper-source.tar.gz"
|
|
|
|
|
+ download_archive(archive_url, archive_path)
|
|
|
|
|
+ archive_digest = hashlib.sha256(archive_path.read_bytes()).hexdigest()
|
|
|
|
|
+ extracted = temporary / "source"
|
|
|
|
|
+ extracted.mkdir()
|
|
|
|
|
+ extract_slweb_tools(archive_path, extracted, config["source_directory"])
|
|
|
|
|
+ shutil.copytree(extracted, staged)
|
|
|
|
|
+ except Exception:
|
|
|
|
|
+ if staged.exists():
|
|
|
|
|
+ shutil.rmtree(staged)
|
|
|
|
|
+ raise
|
|
|
|
|
+
|
|
|
|
|
+ backup = managed.get("backup") if managed is not None else None
|
|
|
|
|
+ backup_digest = managed.get("backup_sha256") if managed is not None else None
|
|
|
|
|
+ backup_created = False
|
|
|
|
|
+ moved_previous = False
|
|
|
|
|
+ try:
|
|
|
|
|
+ if managed is None and destination.exists():
|
|
|
|
|
+ shutil.copytree(destination, backup_path, symlinks=True)
|
|
|
|
|
+ backup = str(backup_path)
|
|
|
|
|
+ backup_digest = tree_sha256(backup_path)
|
|
|
|
|
+ backup_created = True
|
|
|
|
|
+ destination.parent.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ if destination.exists():
|
|
|
|
|
+ os.replace(destination, previous)
|
|
|
|
|
+ moved_previous = True
|
|
|
|
|
+ os.replace(staged, destination)
|
|
|
|
|
+ installed_digest = tree_sha256(destination)
|
|
|
|
|
+ record = {
|
|
|
|
|
+ "destination": str(destination),
|
|
|
|
|
+ "source_url": source_url,
|
|
|
|
|
+ "tag": tag,
|
|
|
|
|
+ "archive_sha256": archive_digest,
|
|
|
|
|
+ "installed_sha256": installed_digest,
|
|
|
|
|
+ "backup": backup,
|
|
|
|
|
+ "backup_sha256": backup_digest,
|
|
|
|
|
+ }
|
|
|
|
|
+ registry["slweb"] = record
|
|
|
|
|
+ write_registry(registry)
|
|
|
|
|
+ except (OSError, shutil.Error):
|
|
|
|
|
+ if destination.exists() and moved_previous:
|
|
|
|
|
+ shutil.rmtree(destination)
|
|
|
|
|
+ if moved_previous and previous.exists():
|
|
|
|
|
+ os.replace(previous, destination)
|
|
|
|
|
+ if backup_created and backup_path.exists():
|
|
|
|
|
+ shutil.rmtree(backup_path)
|
|
|
|
|
+ if staged.exists():
|
|
|
|
|
+ shutil.rmtree(staged)
|
|
|
|
|
+ raise
|
|
|
|
|
+ if previous.exists():
|
|
|
|
|
+ shutil.rmtree(previous)
|
|
|
|
|
+ print(f"Installed SLWeb tools from {tag} at {destination}.")
|
|
|
|
|
+ print(f"Downloaded SooperLooper source archive SHA-256 (identity only): {archive_digest}")
|
|
|
|
|
+ return record
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def uninstall_slweb_tools(config, registry):
|
|
|
|
|
+ managed = registry.get("slweb")
|
|
|
|
|
+ if managed is None:
|
|
|
|
|
+ print("No managed SLWeb tools to uninstall.")
|
|
|
|
|
+ return
|
|
|
|
|
+ destination = slweb_tools_path(config)
|
|
|
|
|
+ if managed.get("destination") != str(destination):
|
|
|
|
|
+ raise RuntimeError("recorded SLWeb installation path changed")
|
|
|
|
|
+ backup = validate_backup_path(managed.get("backup"), destination, is_directory=True)
|
|
|
|
|
+ backup_digest = managed.get("backup_sha256")
|
|
|
|
|
+ if (backup is None) != (backup_digest is None):
|
|
|
|
|
+ raise RuntimeError("invalid SLWeb backup record")
|
|
|
|
|
+ if backup is not None and backup.exists():
|
|
|
|
|
+ if not backup.is_dir() or tree_sha256(backup) != backup_digest:
|
|
|
|
|
+ raise RuntimeError(f"recorded SLWeb backup changed locally: {backup}")
|
|
|
|
|
+
|
|
|
|
|
+ current_digest = tree_sha256(destination) if destination.is_dir() else None
|
|
|
|
|
+ if destination.exists() and not destination.is_dir():
|
|
|
|
|
+ raise RuntimeError(f"SLWeb destination has the wrong type: {destination}")
|
|
|
|
|
+ if managed.get("pending_uninstall"):
|
|
|
|
|
+ if current_digest not in {managed.get("installed_sha256"), backup_digest, None}:
|
|
|
|
|
+ raise RuntimeError(f"unexpected SLWeb files block uninstall: {destination}")
|
|
|
|
|
+ elif current_digest != managed.get("installed_sha256"):
|
|
|
|
|
+ raise RuntimeError(f"managed SLWeb tools changed locally; refusing removal: {destination}")
|
|
|
|
|
+ if backup is not None and not backup.exists() and current_digest == managed.get("installed_sha256"):
|
|
|
|
|
+ raise RuntimeError(f"recorded SLWeb backup is missing: {backup}")
|
|
|
|
|
+
|
|
|
|
|
+ managed["pending_uninstall"] = True
|
|
|
|
|
+ registry["slweb"] = managed
|
|
|
|
|
+ write_registry(registry)
|
|
|
|
|
+ if current_digest == managed.get("installed_sha256"):
|
|
|
|
|
+ shutil.rmtree(destination)
|
|
|
|
|
+ if backup is not None and backup.exists():
|
|
|
|
|
+ if destination.exists():
|
|
|
|
|
+ raise RuntimeError(f"unexpected destination blocks SLWeb backup restore: {destination}")
|
|
|
|
|
+ os.replace(backup, destination)
|
|
|
|
|
+ registry.pop("slweb")
|
|
|
|
|
+ write_registry(registry)
|
|
|
|
|
+ print("SLWeb tools removed; prior directory restored if present.")
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def render_slweb_service(config, source_config, tools_digest):
|
|
|
|
|
+ destination = slweb_tools_path(config)
|
|
|
|
|
+ service_template = ROOT / config["service_source"]
|
|
|
|
|
+ if not service_template.is_file():
|
|
|
|
|
+ raise RuntimeError(f"SLWeb service template is missing: {service_template}")
|
|
|
|
|
+ replacements = {
|
|
|
|
|
+ "@SLWEB_DIRECTORY@": systemd_quote(destination),
|
|
|
|
|
+ "@PYTHON@": systemd_quote(config["python_path"]),
|
|
|
|
|
+ "@OSC_HOST@": source_config["osc"]["host"],
|
|
|
|
|
+ "@OSC_PORT@": str(source_config["osc"]["port"]),
|
|
|
|
|
+ "@HTTP_HOST@": config["http_host"],
|
|
|
|
|
+ "@HTTP_PORT@": str(config["http_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 SLWeb service template")
|
|
|
|
|
+ fingerprint = hashlib.sha256(
|
|
|
|
|
+ json.dumps(
|
|
|
|
|
+ {"slweb": config, "sooperlooper_source": source_config, "tools_sha256": tools_digest},
|
|
|
|
|
+ sort_keys=True,
|
|
|
|
|
+ separators=(",", ":"),
|
|
|
|
|
+ ).encode("utf-8")
|
|
|
|
|
+ + content.encode("utf-8")
|
|
|
|
|
+ ).hexdigest()
|
|
|
|
|
+ content += f"\n# Rigforge runtime fingerprint: {fingerprint}\n"
|
|
|
|
|
+ return {
|
|
|
|
|
+ "name": config["user_service"],
|
|
|
|
|
+ "destination": Path.home() / config["service_destination"],
|
|
|
|
|
+ "content": content.encode("utf-8"),
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def atomic_install_bytes(content, destination):
|
|
def atomic_install_bytes(content, destination):
|
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
|
fd, temporary_name = tempfile.mkstemp(prefix=f".{destination.name}.", dir=destination.parent)
|
|
fd, temporary_name = tempfile.mkstemp(prefix=f".{destination.name}.", dir=destination.parent)
|
|
@@ -1814,6 +2063,10 @@ def reset_mod_ui_reference(config, registry):
|
|
|
|
|
|
|
|
|
|
|
|
|
def deploy_sooperlooper(action, config, registry, state=None):
|
|
def deploy_sooperlooper(action, config, registry, state=None):
|
|
|
|
|
+ if action == "uninstall" and (
|
|
|
|
|
+ "slweb" in registry or "slweb_service" in registry
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError("uninstall slweb before uninstalling SooperLooper")
|
|
|
if state is None:
|
|
if state is None:
|
|
|
state = yaml.safe_load(
|
|
state = yaml.safe_load(
|
|
|
(ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
|
|
(ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
|
|
@@ -1824,6 +2077,36 @@ def deploy_sooperlooper(action, config, registry, state=None):
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def deploy_slweb(action, config, source_config, registry):
|
|
|
|
|
+ if action == "install" and "sooperlooper" not in registry:
|
|
|
|
|
+ raise RuntimeError("install sooperlooper before installing slweb")
|
|
|
|
|
+ if action == "uninstall" and "slweb" not in registry and "slweb_service" not in registry:
|
|
|
|
|
+ print("No managed SLWeb service or tools to uninstall.")
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ if action == "install":
|
|
|
|
|
+ tools = install_slweb_tools(config, source_config, registry)
|
|
|
|
|
+ else:
|
|
|
|
|
+ tools = registry.get("slweb")
|
|
|
|
|
+ if action == "reload" and tools is None:
|
|
|
|
|
+ raise RuntimeError("SLWeb tools are not managed; install slweb before reloading it")
|
|
|
|
|
+ if tools is not None:
|
|
|
|
|
+ destination = slweb_tools_path(config)
|
|
|
|
|
+ if destination.is_dir() and tree_sha256(destination) != tools.get("installed_sha256"):
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"managed SLWeb tools changed locally; refusing service operation: {destination}"
|
|
|
|
|
+ )
|
|
|
|
|
+ if tools is None:
|
|
|
|
|
+ raise RuntimeError("SLWeb tools are not managed; install slweb first")
|
|
|
|
|
+
|
|
|
|
|
+ unit = render_slweb_service(
|
|
|
|
|
+ config, source_config, tools.get("installed_sha256", "unmanaged")
|
|
|
|
|
+ )
|
|
|
|
|
+ deploy_single_user_service(action, "slweb_service", "slweb", "SLWeb", unit, registry)
|
|
|
|
|
+ if action == "uninstall":
|
|
|
|
|
+ uninstall_slweb_tools(config, registry)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def file_sha256(path):
|
|
def file_sha256(path):
|
|
|
return hashlib.sha256(path.read_bytes()).hexdigest() if path.is_file() else None
|
|
return hashlib.sha256(path.read_bytes()).hexdigest() if path.is_file() else None
|
|
|
|
|
|
|
@@ -2340,6 +2623,7 @@ def main(argv=None):
|
|
|
"reconcile",
|
|
"reconcile",
|
|
|
"midi-bridge",
|
|
"midi-bridge",
|
|
|
"sooperlooper",
|
|
"sooperlooper",
|
|
|
|
|
+ "slweb",
|
|
|
),
|
|
),
|
|
|
)
|
|
)
|
|
|
parser.add_argument(
|
|
parser.add_argument(
|
|
@@ -2382,6 +2666,10 @@ def main(argv=None):
|
|
|
deploy_sooperlooper(
|
|
deploy_sooperlooper(
|
|
|
args.action, deployment["sooperlooper"], registry, state=state
|
|
args.action, deployment["sooperlooper"], registry, state=state
|
|
|
)
|
|
)
|
|
|
|
|
+ elif args.target == "slweb":
|
|
|
|
|
+ deploy_slweb(
|
|
|
|
|
+ args.action, deployment["slweb"], deployment["sooperlooper"], registry
|
|
|
|
|
+ )
|
|
|
else:
|
|
else:
|
|
|
component = "dragonfly_reverb" if args.target == "dragonfly-reverb" else args.target
|
|
component = "dragonfly_reverb" if args.target == "dragonfly-reverb" else args.target
|
|
|
deploy_lv2_archives(args.action, component, deployment[component], registry)
|
|
deploy_lv2_archives(args.action, component, deployment[component], registry)
|