48 lines
1.9 KiB
Bash
Executable file
48 lines
1.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# =============================================================================
|
|
# scripts/add-genome.sh
|
|
# Helper to add a single new genome to the existing infrastructure.
|
|
# =============================================================================
|
|
|
|
set -euo pipefail
|
|
source "lib/output.sh"
|
|
source "globals.env"
|
|
source "registry.sh"
|
|
|
|
GENOME_NAME="${1:-}"
|
|
GENOME_DESC="${2:-}"
|
|
GENOME_LINKED="${3:-}" # optional: linked project repo reference
|
|
GENOME_CROSS_SOURCE="${4:-no}" # optional: cross_source flag (default: no)
|
|
|
|
# 1. Check mandatory arguments first
|
|
if [[ -z "$GENOME_NAME" || -z "$GENOME_DESC" ]]; then
|
|
error "Missing arguments."
|
|
echo "Usage: $0 <genome-name> <description> [linked-repo] [cross_source]"
|
|
echo " cross_source: yes|no (default: no)"
|
|
exit 1
|
|
fi
|
|
|
|
# 2. Then validate the flag if a non-default value was passed
|
|
if [[ "$GENOME_CROSS_SOURCE" != "yes" && "$GENOME_CROSS_SOURCE" != "no" ]]; then
|
|
error "Invalid cross_source value: $GENOME_CROSS_SOURCE"
|
|
echo "cross_source must be 'yes' or 'no'"
|
|
exit 1
|
|
fi
|
|
|
|
step "Adding New Genome: ${GENOME_NAME}"
|
|
|
|
# Build a 4-field registry entry (linked_repo may be empty, cross_source defaults to no)
|
|
GENOMES=("${GENOME_NAME}|${GENOME_DESC}|${GENOME_LINKED}|${GENOME_CROSS_SOURCE}")
|
|
|
|
# NOTE — Maintenance smell
|
|
# We source setup-genomes.sh as a library/orchestrator hybrid. This works because:
|
|
# - registry.sh is guarded against double-source (idempotent guard)
|
|
# - setup-genomes.sh checks WORK_DIR before re-sourcing registry.sh
|
|
# - GENOMES is built locally just before the source, so it is not clobbered
|
|
# However, sourcing an orchestration script as a library makes the control flow
|
|
# harder to trace. If this grows, refactor into a shared function (e.g. setup_one_genome)
|
|
# called by both add-genome.sh and setup-genomes.sh.
|
|
|
|
source "scripts/setup-genomes.sh"
|
|
|
|
success "Genome '${GENOME_NAME}' added and linked successfully!"
|