|
@@ -66,6 +66,8 @@ def load_deployment():
|
|
|
errors.append(f"{component} bundle paths are invalid")
|
|
errors.append(f"{component} bundle paths are invalid")
|
|
|
tag = namlv2.get("tag")
|
|
tag = namlv2.get("tag")
|
|
|
match = NAM_RELEASE_ASSET.fullmatch(namlv2.get("archive_url", ""))
|
|
match = NAM_RELEASE_ASSET.fullmatch(namlv2.get("archive_url", ""))
|
|
|
|
|
+ if namlv2.get("source_url") != "https://github.com/mikeoliphant/neural-amp-modeler-lv2":
|
|
|
|
|
+ errors.append("NAM LV2 source URL is invalid")
|
|
|
if not isinstance(tag, str) or not re.fullmatch(r"[A-Za-z0-9._-]+", tag):
|
|
if not isinstance(tag, str) or not re.fullmatch(r"[A-Za-z0-9._-]+", tag):
|
|
|
errors.append("NAM LV2 tag is invalid")
|
|
errors.append("NAM LV2 tag is invalid")
|
|
|
if match is None or match.group("tag") != tag:
|
|
if match is None or match.group("tag") != tag:
|
|
@@ -693,9 +695,42 @@ def deploy_namlv2(action, config, registry):
|
|
|
destination = Path.home() / ".lv2" / bundle_name
|
|
destination = Path.home() / ".lv2" / bundle_name
|
|
|
validate_user_destination(destination)
|
|
validate_user_destination(destination)
|
|
|
managed = registry.get("namlv2")
|
|
managed = registry.get("namlv2")
|
|
|
|
|
+ artifact_directory = config.get("artifact_directory")
|
|
|
|
|
+ artifact_bundle = None
|
|
|
|
|
+ artifact_digest = None
|
|
|
|
|
+ if artifact_directory is not None:
|
|
|
|
|
+ relative = PurePosixPath(artifact_directory)
|
|
|
|
|
+ if relative.is_absolute() or ".." in relative.parts or not relative.parts:
|
|
|
|
|
+ raise RuntimeError("NAM LV2 artifact directory must be a safe repository path")
|
|
|
|
|
+ artifact_root = (ROOT / Path(*relative.parts)).resolve()
|
|
|
|
|
+ if not artifact_root.is_relative_to(ROOT.resolve()):
|
|
|
|
|
+ raise RuntimeError("NAM LV2 artifact directory escapes the repository")
|
|
|
|
|
+ artifact_bundle = artifact_root / bundle_name
|
|
|
|
|
+ provenance_path = artifact_root / "provenance.json"
|
|
|
|
|
+ if not artifact_bundle.is_dir() or not provenance_path.is_file():
|
|
|
|
|
+ raise FileNotFoundError(
|
|
|
|
|
+ f"built NAM LV2 artifact is missing: {artifact_bundle}"
|
|
|
|
|
+ )
|
|
|
|
|
+ with provenance_path.open(encoding="utf-8") as stream:
|
|
|
|
|
+ provenance = json.load(stream)
|
|
|
|
|
+ if (
|
|
|
|
|
+ provenance.get("source_url") != "https://github.com/mikeoliphant/neural-amp-modeler-lv2"
|
|
|
|
|
+ or provenance.get("tag") != config["tag"]
|
|
|
|
|
+ or provenance.get("linkage") != "system libstdc++ and libgcc_s"
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError("built NAM LV2 artifact provenance does not match desired state")
|
|
|
|
|
+ plugin_binary = artifact_bundle / "neural_amp_modeler.so"
|
|
|
|
|
+ if (
|
|
|
|
|
+ not (artifact_bundle / "manifest.ttl").is_file()
|
|
|
|
|
+ or not (artifact_bundle / "neural_amp_modeler.ttl").is_file()
|
|
|
|
|
+ or not plugin_binary.is_file()
|
|
|
|
|
+ or file_sha256(plugin_binary) != provenance.get("artifact_sha256")
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError("built NAM LV2 artifact failed its provenance check")
|
|
|
|
|
+ artifact_digest = tree_sha256(artifact_bundle)
|
|
|
|
|
|
|
|
if action == "reload":
|
|
if action == "reload":
|
|
|
- print("Nothing to reload for the NAM LV2 plugin; restart its LV2 host after installation.")
|
|
|
|
|
|
|
+ print("Nothing to reload for the NAM LV2 plugin; restart mod-host after installation.")
|
|
|
return
|
|
return
|
|
|
|
|
|
|
|
if action == "uninstall":
|
|
if action == "uninstall":
|
|
@@ -756,7 +791,9 @@ def deploy_namlv2(action, config, registry):
|
|
|
raise RuntimeError(f"managed NAM LV2 bundle is missing: {destination}")
|
|
raise RuntimeError(f"managed NAM LV2 bundle is missing: {destination}")
|
|
|
if tree_sha256(destination) != managed.get("installed_sha256"):
|
|
if tree_sha256(destination) != managed.get("installed_sha256"):
|
|
|
raise RuntimeError(f"managed NAM LV2 bundle changed locally; refusing overwrite: {destination}")
|
|
raise RuntimeError(f"managed NAM LV2 bundle changed locally; refusing overwrite: {destination}")
|
|
|
- if managed.get("tag") == config["tag"]:
|
|
|
|
|
|
|
+ if managed.get("tag") == config["tag"] and (
|
|
|
|
|
+ artifact_digest is None or managed.get("artifact_sha256") == artifact_digest
|
|
|
|
|
+ ):
|
|
|
print(f"NAM LV2 tag {config['tag']} is already installed and unchanged.")
|
|
print(f"NAM LV2 tag {config['tag']} is already installed and unchanged.")
|
|
|
return
|
|
return
|
|
|
backup = validate_backup_path(managed.get("backup"), destination, is_directory=True)
|
|
backup = validate_backup_path(managed.get("backup"), destination, is_directory=True)
|
|
@@ -772,17 +809,25 @@ def deploy_namlv2(action, config, registry):
|
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory(prefix="rigforge-namlv2-") as temporary_dir:
|
|
with tempfile.TemporaryDirectory(prefix="rigforge-namlv2-") as temporary_dir:
|
|
|
temporary = Path(temporary_dir)
|
|
temporary = Path(temporary_dir)
|
|
|
- archive_path = temporary / "namlv2.tgz"
|
|
|
|
|
- download_archive(config["archive_url"], archive_path)
|
|
|
|
|
- archive_digest = hashlib.sha256(archive_path.read_bytes()).hexdigest()
|
|
|
|
|
- inspect_archive(archive_path, bundle_name)
|
|
|
|
|
- extraction_root = temporary / "extract"
|
|
|
|
|
- extraction_root.mkdir()
|
|
|
|
|
- extracted_bundle = extraction_root / bundle_name
|
|
|
|
|
- extracted_bundle.mkdir()
|
|
|
|
|
- extract_bundle(archive_path, extracted_bundle, bundle_name)
|
|
|
|
|
- if not extracted_bundle.is_dir():
|
|
|
|
|
- raise RuntimeError(f"expected bundle missing after extraction: {extracted_bundle}")
|
|
|
|
|
|
|
+ archive_digest = None
|
|
|
|
|
+ if artifact_bundle is not None:
|
|
|
|
|
+ extracted_bundle = artifact_bundle
|
|
|
|
|
+ else:
|
|
|
|
|
+ archive_path = temporary / "namlv2.tgz"
|
|
|
|
|
+ download_archive(config["archive_url"], archive_path)
|
|
|
|
|
+ archive_digest = hashlib.sha256(archive_path.read_bytes()).hexdigest()
|
|
|
|
|
+ inspect_archive(archive_path, bundle_name)
|
|
|
|
|
+ extraction_root = temporary / "extract"
|
|
|
|
|
+ extraction_root.mkdir()
|
|
|
|
|
+ extracted_bundle = extraction_root / bundle_name
|
|
|
|
|
+ extracted_bundle.mkdir()
|
|
|
|
|
+ extract_bundle(archive_path, extracted_bundle, bundle_name)
|
|
|
|
|
+ if (
|
|
|
|
|
+ not extracted_bundle.is_dir()
|
|
|
|
|
+ or not (extracted_bundle / "manifest.ttl").is_file()
|
|
|
|
|
+ or not (extracted_bundle / "neural_amp_modeler.so").is_file()
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError(f"expected NAM LV2 bundle missing or incomplete: {extracted_bundle}")
|
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
|
staged_bundle = destination.with_name(destination.name + ".rigforge-new")
|
|
staged_bundle = destination.with_name(destination.name + ".rigforge-new")
|
|
|
previous_bundle = destination.with_name(destination.name + ".rigforge-old")
|
|
previous_bundle = destination.with_name(destination.name + ".rigforge-old")
|
|
@@ -820,9 +865,15 @@ def deploy_namlv2(action, config, registry):
|
|
|
"backup_sha256": backup_sha256,
|
|
"backup_sha256": backup_sha256,
|
|
|
"installed_sha256": tree_sha256(destination),
|
|
"installed_sha256": tree_sha256(destination),
|
|
|
}
|
|
}
|
|
|
|
|
+ if artifact_digest is not None:
|
|
|
|
|
+ registry["namlv2"]["artifact_sha256"] = artifact_digest
|
|
|
|
|
+ registry["namlv2"]["build_provenance"] = str(artifact_root / "provenance.json")
|
|
|
write_registry(registry)
|
|
write_registry(registry)
|
|
|
print(f"Installed NAM LV2 tag {config['tag']} at {destination}.")
|
|
print(f"Installed NAM LV2 tag {config['tag']} at {destination}.")
|
|
|
- print(f"Downloaded archive SHA-256 (identity only, no publisher checksum): {archive_digest}")
|
|
|
|
|
|
|
+ if artifact_digest is not None:
|
|
|
|
|
+ print(f"Installed built NAM LV2 artifact SHA-256: {artifact_digest}")
|
|
|
|
|
+ elif archive_digest is not None:
|
|
|
|
|
+ print(f"Downloaded archive SHA-256 (identity only, no publisher checksum): {archive_digest}")
|
|
|
|
|
|
|
|
|
|
|
|
|
def systemd_quote(value):
|
|
def systemd_quote(value):
|
|
@@ -902,7 +953,17 @@ def render_mod_ui_service(config):
|
|
|
service_template = ROOT / config["service_source"]
|
|
service_template = ROOT / config["service_source"]
|
|
|
with state_file.open(encoding="utf-8") as stream:
|
|
with state_file.open(encoding="utf-8") as stream:
|
|
|
state = yaml.safe_load(stream)
|
|
state = yaml.safe_load(stream)
|
|
|
- reference_files = generate_bundle_files(state, ROOT)
|
|
|
|
|
|
|
+ nam_processor = state["routing"]["mod_host_chains"]["guitar"]["processors"][0]
|
|
|
|
|
+ nam_model_path = (
|
|
|
|
|
+ Path.home()
|
|
|
|
|
+ / config["user_files_directory"]
|
|
|
|
|
+ / "NAM Models"
|
|
|
|
|
+ / "Rigforge"
|
|
|
|
|
+ / Path(nam_processor["asset_path"]).name
|
|
|
|
|
+ )
|
|
|
|
|
+ reference_files = generate_bundle_files(
|
|
|
|
|
+ state, ROOT, nam_model_path=nam_model_path
|
|
|
|
|
+ )
|
|
|
bundle_digest = hashlib.sha256()
|
|
bundle_digest = hashlib.sha256()
|
|
|
for name, content_bytes in sorted(reference_files.items()):
|
|
for name, content_bytes in sorted(reference_files.items()):
|
|
|
bundle_digest.update(name.encode("utf-8") + b"\0" + content_bytes + b"\0")
|
|
bundle_digest.update(name.encode("utf-8") + b"\0" + content_bytes + b"\0")
|
|
@@ -930,6 +991,7 @@ def render_mod_ui_service(config):
|
|
|
"@MOD_DATA_DIR@": systemd_quote(home / ".local" / "share" / "rigforge" / "mod-ui"),
|
|
"@MOD_DATA_DIR@": systemd_quote(home / ".local" / "share" / "rigforge" / "mod-ui"),
|
|
|
"@MOD_LAST_STATE@": systemd_quote(home / config["last_state_file"]),
|
|
"@MOD_LAST_STATE@": systemd_quote(home / config["last_state_file"]),
|
|
|
"@PEDALBOARDS_DIR@": systemd_quote(home / config["pedalboards_directory"]),
|
|
"@PEDALBOARDS_DIR@": systemd_quote(home / config["pedalboards_directory"]),
|
|
|
|
|
+ "@USER_FILES_DIR@": systemd_quote(home / config["user_files_directory"]),
|
|
|
"@REFERENCE_PEDALBOARD@": systemd_quote(reference_pedalboard),
|
|
"@REFERENCE_PEDALBOARD@": systemd_quote(reference_pedalboard),
|
|
|
"@HARDWARE_INPUT_PORT@": config["hardware_input_port"],
|
|
"@HARDWARE_INPUT_PORT@": config["hardware_input_port"],
|
|
|
"@HARDWARE_OUTPUT_PORT@": config["hardware_output_port"],
|
|
"@HARDWARE_OUTPUT_PORT@": config["hardware_output_port"],
|
|
@@ -1325,6 +1387,109 @@ def deploy_mod_host_ports(action, config, registry):
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def mod_ui_nam_model_sources(state):
|
|
|
|
|
+ nam = state["routing"]["mod_host_chains"]["guitar"]["processors"][0]
|
|
|
|
|
+ relative_paths = {nam["asset_path"], *nam.get("available_models", {}).values()}
|
|
|
|
|
+ sources = {}
|
|
|
|
|
+ for relative in sorted(relative_paths):
|
|
|
|
|
+ source = (ROOT / Path(*PurePosixPath(relative).parts)).resolve()
|
|
|
|
|
+ if not source.is_relative_to(ROOT.resolve()) or not source.is_file():
|
|
|
|
|
+ raise FileNotFoundError(
|
|
|
|
|
+ f"declared NAM model is missing or outside repository: {source}"
|
|
|
|
|
+ )
|
|
|
|
|
+ if source.name in sources and sources[source.name] != source:
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"declared NAM models have a filename collision: {source.name}"
|
|
|
|
|
+ )
|
|
|
|
|
+ sources[source.name] = source
|
|
|
|
|
+ return sources
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+def manage_mod_ui_nam_models(action, config, registry, state):
|
|
|
|
|
+ key = "mod_ui_nam_models"
|
|
|
|
|
+ root = Path.home() / config["user_files_directory"] / "NAM Models" / "Rigforge"
|
|
|
|
|
+ managed = registry.get(key)
|
|
|
|
|
+
|
|
|
|
|
+ if action == "uninstall":
|
|
|
|
|
+ if managed is None:
|
|
|
|
|
+ return
|
|
|
|
|
+ if managed.get("directory") != str(root):
|
|
|
|
|
+ raise RuntimeError("managed mod-ui NAM model directory changed")
|
|
|
|
|
+ recorded = managed.get("files")
|
|
|
|
|
+ if not isinstance(recorded, dict):
|
|
|
|
|
+ raise RuntimeError("managed mod-ui NAM model registry is invalid")
|
|
|
|
|
+ for name, digest in recorded.items():
|
|
|
|
|
+ destination = root / name
|
|
|
|
|
+ validate_user_destination(destination)
|
|
|
|
|
+ if destination.is_symlink():
|
|
|
|
|
+ raise RuntimeError(f"managed NAM model became a symlink: {destination}")
|
|
|
|
|
+ if destination.exists() and (
|
|
|
|
|
+ not destination.is_file() or file_sha256(destination) != digest
|
|
|
|
|
+ ):
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"managed NAM model changed locally; refusing to remove: {destination}"
|
|
|
|
|
+ )
|
|
|
|
|
+ for name in recorded:
|
|
|
|
|
+ (root / name).unlink(missing_ok=True)
|
|
|
|
|
+ try:
|
|
|
|
|
+ root.rmdir()
|
|
|
|
|
+ except OSError:
|
|
|
|
|
+ pass
|
|
|
|
|
+ registry.pop(key)
|
|
|
|
|
+ write_registry(registry)
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ if action != "install":
|
|
|
|
|
+ return
|
|
|
|
|
+
|
|
|
|
|
+ sources = mod_ui_nam_model_sources(state)
|
|
|
|
|
+ if managed is None:
|
|
|
|
|
+ recorded = {}
|
|
|
|
|
+ else:
|
|
|
|
|
+ if managed.get("directory") != str(root):
|
|
|
|
|
+ raise RuntimeError("managed mod-ui NAM model directory changed")
|
|
|
|
|
+ recorded = managed.get("files")
|
|
|
|
|
+ if not isinstance(recorded, dict):
|
|
|
|
|
+ raise RuntimeError("managed mod-ui NAM model registry is invalid")
|
|
|
|
|
+
|
|
|
|
|
+ if set(recorded) - set(sources):
|
|
|
|
|
+ raise RuntimeError("managed mod-ui NAM model set changed; uninstall mod-ui first")
|
|
|
|
|
+
|
|
|
|
|
+ root.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
+ plan = []
|
|
|
|
|
+ for name, source in sources.items():
|
|
|
|
|
+ destination = root / name
|
|
|
|
|
+ validate_user_destination(destination)
|
|
|
|
|
+ if destination.is_symlink():
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"refusing to replace symlink in mod-ui NAM directory: {destination}"
|
|
|
|
|
+ )
|
|
|
|
|
+ expected_digest = file_sha256(source)
|
|
|
|
|
+ current_digest = file_sha256(destination)
|
|
|
|
|
+ prior_digest = recorded.get(name)
|
|
|
|
|
+ if prior_digest is not None:
|
|
|
|
|
+ if current_digest != prior_digest:
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"managed NAM model changed locally; refusing overwrite: {destination}"
|
|
|
|
|
+ )
|
|
|
|
|
+ plan.append((name, source, destination, expected_digest, current_digest != expected_digest))
|
|
|
|
|
+ elif current_digest is None:
|
|
|
|
|
+ plan.append((name, source, destination, expected_digest, True))
|
|
|
|
|
+ elif current_digest != expected_digest:
|
|
|
|
|
+ raise RuntimeError(
|
|
|
|
|
+ f"unmanaged file conflicts with declared NAM model: {destination}"
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ installed = dict(recorded)
|
|
|
|
|
+ for name, source, destination, expected_digest, needs_install in plan:
|
|
|
|
|
+ if needs_install:
|
|
|
|
|
+ atomic_install(source, destination)
|
|
|
|
|
+ installed[name] = expected_digest
|
|
|
|
|
+
|
|
|
|
|
+ registry[key] = {"directory": str(root), "files": installed}
|
|
|
|
|
+ write_registry(registry)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def deploy_mod_ui(action, config, registry):
|
|
def deploy_mod_ui(action, config, registry):
|
|
|
if action == "install":
|
|
if action == "install":
|
|
|
if "mod_host_ports" not in registry:
|
|
if "mod_host_ports" not in registry:
|
|
@@ -1351,6 +1516,11 @@ def deploy_mod_ui(action, config, registry):
|
|
|
return
|
|
return
|
|
|
if action == "uninstall" and "midi_bridge" in registry:
|
|
if action == "uninstall" and "midi_bridge" in registry:
|
|
|
raise RuntimeError("uninstall midi-bridge before uninstalling mod-ui")
|
|
raise RuntimeError("uninstall midi-bridge before uninstalling mod-ui")
|
|
|
|
|
+ state = yaml.safe_load(
|
|
|
|
|
+ (ROOT / "config" / "desired-state.yaml").read_text(encoding="utf-8")
|
|
|
|
|
+ )
|
|
|
|
|
+ if action == "install":
|
|
|
|
|
+ manage_mod_ui_nam_models("install", config, registry, state)
|
|
|
unit = render_mod_ui_service(config)
|
|
unit = render_mod_ui_service(config)
|
|
|
reference_sha256 = None
|
|
reference_sha256 = None
|
|
|
if action != "uninstall":
|
|
if action != "uninstall":
|
|
@@ -1363,6 +1533,8 @@ def deploy_mod_ui(action, config, registry):
|
|
|
unit,
|
|
unit,
|
|
|
registry,
|
|
registry,
|
|
|
)
|
|
)
|
|
|
|
|
+ if action == "uninstall":
|
|
|
|
|
+ manage_mod_ui_nam_models("uninstall", config, registry, state)
|
|
|
if action == "install":
|
|
if action == "install":
|
|
|
registry["mod_ui"]["reference_bundle"] = {
|
|
registry["mod_ui"]["reference_bundle"] = {
|
|
|
"destination": str(unit["reference_bundle"]),
|
|
"destination": str(unit["reference_bundle"]),
|