#!/usr/bin/env bash # ============================================================================= # scripts/setup-genomes.sh # Iterates through the GENOMES registry to provision remote and local repos. # Handles git-crypt initialization and submodule linking. # ============================================================================= set -euo pipefail source "lib/output.sh" source "config.env" source "lib/scaffold.sh" source "lib/git-crypt.sh" source "providers/${PROVIDER}.sh" step "Processing Genome Registry" for entry in "${GENOMES[@]}"; do # Parse name and description from the array IFS='|' read -r GENOME_NAME GENOME_DESC <<< "$entry" export GENOME_NAME GENOME_DESC info "Processing: ${GENOME_NAME}..." # 1. Remote Provisioning (Idempotent: skips if exists) provider_create_repo "${GENOME_NAME}" "${GENOME_DESC}" "true" GENOME_PATH="${WORK_DIR}/${MASTER_REPO}/${GENOME_NAME}" if [ ! -d "${GENOME_PATH}" ]; then info "Creating local directory and initializing scaffold..." mkdir -p "${GENOME_PATH}" cd "${GENOME_PATH}" git init # IMPORTANT: Initialize git-crypt BEFORE creating sensitive files gcrypt_init # Create directory structure and apply templates scaffold_genome "." install_precommit_hook "." # Initial commit and push to remote git add . git commit -m "feat: initial scaffold for ${GENOME_NAME}" SSH_URL=$(provider_ssh_url "${GENOME_NAME}") git remote add origin "${SSH_URL}" git push -u origin main # Export the AES key for the user to back up gcrypt_export_key "${GENOME_NAME}" # 2. Link as submodule in the Master repository cd "${WORK_DIR}/${MASTER_REPO}" info "Linking ${GENOME_NAME} as a submodule..." git submodule add "${SSH_URL}" "${GENOME_NAME}" git add .gitmodules "${GENOME_NAME}" git commit -m "feat: link submodule ${GENOME_NAME}" else warn "Genome directory '${GENOME_NAME}' already exists. Skipping local setup." fi done