#!/usr/bin/env bash # ============================================================================= # scripts/setup-genomes.sh # Iterates through the GENOMES registry to provision remote and local repos. # ============================================================================= set -euo pipefail source "lib/output.sh" source "globals.env" if [[ -z "${WORK_DIR:-}" ]]; then source "registry.sh" fi source "lib/scaffold.sh" source "lib/git-crypt.sh" source "providers/${PROVIDER}.sh" step "Processing Genome Registry" for entry in "${GENOMES[@]}"; do # 4-field format: name|description|linked_repo|cross_source linked_repo optional (may be empty); cross_source defaults to "no". IFS='|' read -r GENOME_NAME GENOME_DESC GENOME_LINKED GENOME_CROSS_SOURCE <<< "$entry" GENOME_CROSS_SOURCE="${GENOME_CROSS_SOURCE:-no}" export GENOME_NAME GENOME_DESC GENOME_LINKED GENOME_CROSS_SOURCE info "Processing: ${GENOME_NAME} (cross_source: ${GENOME_CROSS_SOURCE})..." # 1. Remote Creation (Idempotent) provider_create_repo "${GENOME_NAME}" "${GENOME_DESC}" "true" "true" SSH_URL=$(provider_ssh_url "${GENOME_NAME}") GENOME_PATH="${WORK_DIR}/${MASTER_REPO}/${GENOME_NAME}" if [[ ! -d "${GENOME_PATH}" ]]; then cd "${WORK_DIR}/${MASTER_REPO}" info "Linking ${GENOME_NAME} as a submodule..." git submodule add "${SSH_URL}" "${GENOME_NAME}" cd "${GENOME_NAME}" git switch -C main # IMPORTANT: Initialize git-crypt BEFORE creating any files gcrypt_init scaffold_genome "." install_precommit_hook "." # Initial genome push git add . git commit -m "feat: initial scaffold and git-crypt init for ${GENOME_NAME}" git push -u origin main # Key export and instructions gcrypt_export_key "${GENOME_NAME}" gcrypt_print_key_instructions "${GENOME_NAME}" cd "${WORK_DIR}/${MASTER_REPO}" git add .gitmodules "${GENOME_NAME}" git diff --cached --quiet || git commit -m "chore: register submodule ${GENOME_NAME}" git push # Commit the submodule reference in the master repo cd "${WORK_DIR}/${MASTER_REPO}" git commit -m "feat: add ${GENOME_NAME} as submodule" git push origin main fi done success "Genome provisioning completed."