#!/bin/bash # Artifact command handler — `libreportal artifact ` # --------------------------------------------------------------------------- # Dispatched automatically by cli_initialize.sh (category -> cliHandleArtifactCommands). # # This is PHASE 1 of the unified distribution primitive: the READ side. It fetches # and verifies the team-signed artifact index (hotfixes today; apps/themes/ # components later — all the same envelope) and lists what's available. It makes # NO changes to the system, so — like `updater check` — it runs directly rather # than through the task system. The state-changing `apply`/`rollback` verbs (which # DO route through tasks → snapshot → declarative ops → rollback → History) arrive # in Phase 2. See docs/roadmap/updates-and-distribution.md. cliHandleArtifactCommands() { local sub="$initial_command2" # Lazy-loader gap: ensure the read primitives are defined. These are new # files; the array/manifest regen self-heals them on deploy, but this covers # the window before that (mirrors cli_updater_commands.sh sourcing its # generator). artifacts.sh leans on fetch.sh helpers, so load both. if ! declare -F lpFetchIndex >/dev/null 2>&1; then source "$install_scripts_dir/source/fetch.sh" 2>/dev/null source "$install_scripts_dir/source/artifacts.sh" 2>/dev/null fi case "$sub" in ""|"index"|"list") artifactListIndex ;; *) cliShowArtifactHelp ;; esac } # Fetch + verify the signed index and print a human summary. Read-only. artifactListIndex() { isHeader "Artifact index ($(lpReleaseChannel))" local json if ! json="$(lpFetchIndex)"; then isError "Could not fetch or verify the artifact index from $(lpArtifactIndexUrl)." isNotice "Nothing is published yet, or the channel is unreachable. (This is expected before the first index ships.)" return 1 fi local serial generated_at serial="$(_lpJsonNum "$json" index_serial)" generated_at="$(lpIndexTop generated_at "$json")" isNotice "Signed + verified. serial=${serial:-?} generated=${generated_at:-?}" local ids; ids="$(lpIndexArtifactIds "$json")" if [[ -z "$ids" ]]; then isSuccessful "0 artifacts available — the index is empty (nothing to apply)." return 0 fi local n=0 id obj title type sev while IFS= read -r id; do [[ -z "$id" ]] && continue n=$((n + 1)) obj="$(lpArtifactById "$json" "$id")" if [[ -n "$obj" ]]; then title="$(_lpJsonStr "$obj" title)" type="$(_lpJsonStr "$obj" type)" sev="$(_lpJsonStr "$obj" severity)" echo " • [${type:-?}/${sev:-info}] $id — ${title:-}" else echo " • $id" fi done <<< "$ids" isSuccessful "$n artifact(s) available." }