feat: Implement scripts for master repository and genome provisioning

This commit is contained in:
Matteo Cherubini 2026-05-08 21:09:42 +02:00
parent b899572cdb
commit b490e6c70f
2 changed files with 96 additions and 0 deletions

62
scripts/setup-genomes.sh Normal file
View file

@ -0,0 +1,62 @@
#!/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

34
scripts/setup-master.sh Normal file
View file

@ -0,0 +1,34 @@
#!/usr/bin/env bash
# =============================================================================
# scripts/setup-master.sh
# Initializes the umbrella (Master) repository and core configurations.
# =============================================================================
set -euo pipefail
source "lib/output.sh"
source "config.env"
source "lib/scaffold.sh"
step "Configuring Master Repository: ${MASTER_REPO}"
# Ensure workspace exists
mkdir -p "${WORK_DIR}/${MASTER_REPO}"
cd "${WORK_DIR}/${MASTER_REPO}"
if [ ! -d ".git" ]; then
info "Initializing Git in Master repository..."
git init
# Optional: Add Karpathy's core reference as a read-only submodule
if [ -n "${GIST_URL:-}" ]; then
info "Adding core-karpathy as an external reference..."
git submodule add "${GIST_URL}" core-karpathy || warn "Could not add core-karpathy submodule."
fi
fi
# Apply master-level templates (README, AGENTS)
scaffold_master "."
# Initial commit for the master structure
git add .
git commit -m "chore: initialize master scaffold" || info "No changes to commit in master."