Files
postinstall-debian/core/registry.sh
2026-03-15 05:37:15 +01:00

55 lines
1.3 KiB
Bash

#!/usr/bin/env bash
REGISTRY_MODULE_COUNT=0
declare -a REGISTRY_MODULES=()
declare -A REGISTRY_MODULE_PATHS=()
registry_init() {
local module_file=""
local module_id=""
REGISTRY_MODULE_COUNT=0
REGISTRY_MODULES=()
REGISTRY_MODULE_PATHS=()
while IFS= read -r module_file; do
# shellcheck source=/dev/null
source "$module_file"
module_id="${module_file#"$RUNTIME_PROJECT_ROOT/modules/"}"
module_id="${module_id%/module.sh}"
REGISTRY_MODULES+=("$module_id")
REGISTRY_MODULE_PATHS["$module_id"]="$module_file"
done < <(find "$RUNTIME_PROJECT_ROOT/modules" -mindepth 3 -maxdepth 3 -type f -name 'module.sh' | sort)
REGISTRY_MODULE_COUNT="${#REGISTRY_MODULES[@]}"
}
registry_summary() {
printf '%s' "$REGISTRY_MODULE_COUNT"
}
registry_list() {
printf '%s\n' "${REGISTRY_MODULES[@]}"
}
registry_has_module() {
local module_id="$1"
[[ -n "${REGISTRY_MODULE_PATHS[$module_id]:-}" ]]
}
registry_module_path() {
local module_id="$1"
printf '%s\n' "${REGISTRY_MODULE_PATHS[$module_id]:-}"
}
registry_module_test_path() {
local module_id="$1"
local module_path=""
module_path="${REGISTRY_MODULE_PATHS[$module_id]:-}"
if [[ -z "$module_path" ]]; then
return 1
fi
printf '%s\n' "${module_path%/module.sh}/tests.sh"
}