The script's body was never wrapped in an os_family template conditional
despite the header claiming it was 'guarded by the chezmoi template
engine'. So topgrade/chezmoi apply would run it on every box and die
with '/var/db/repos/gentoo missing' on arch/debian.
Wrap the body in '{{ if eq .os_family "gentoo" }}' / '{{ else }}' (same
pattern the arch-only chaotic-aur script already uses). On non-gentoo
boxes the rendered script reduces to a single 'skipping' log line.
Also fix two stale comments in the header (filename was 05, not 10).
Verified by rendering with --config override: arch → no-op log line,
gentoo → full body intact, both pass bash -n.
68 lines
2.8 KiB
Bash
Executable file
68 lines
2.8 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# =============================================================================
|
|
# run_once_10-add-gentoo-overlays.sh.tmpl (gentoo-only)
|
|
# Add the GURU overlay to the portage repository list. GURU is the
|
|
# community overlay (like AUR for arch) where packages like bun, eza,
|
|
# sway, etc. live when they're not in the main tree.
|
|
#
|
|
# Idempotent: skips if GURU is already enabled.
|
|
# Guarded: this script is a no-op on non-gentoo boxes via the os_family
|
|
# template conditional below — so topgrade/chezmoi apply never errors
|
|
# on arch/debian where /var/db/repos/gentoo doesn't exist.
|
|
#
|
|
# Run-order: 00 (bootstrap) → 05 (hosts) → 10 (overlays, here)
|
|
# → 20 (packages) → 40 (sway)
|
|
# =============================================================================
|
|
set -euo pipefail
|
|
|
|
log() { printf '\033[1;34m[overlays]\033[0m %s\n' "$*"; }
|
|
die() { printf '\033[1;31m[overlays ERROR]\033[0m %s\n' "$*" >&2; exit 1; }
|
|
|
|
{{ if eq .os_family "gentoo" -}}
|
|
# --- gentoo: ensure GURU overlay is enabled ---
|
|
if [[ ! -d /var/db/repos/gentoo ]]; then
|
|
die "/var/db/repos/gentoo missing — this doesn't look like a gentoo system"
|
|
fi
|
|
|
|
# GURU overlay — required for eza, lazygit, topgrade, etc.
|
|
if [[ -d /var/db/repos/guru ]]; then
|
|
log "GURU overlay already enabled at /var/db/repos/guru — skipping"
|
|
else
|
|
log "enabling GURU overlay via eselect repository"
|
|
# `eselect repository` needs the overlays.xml index. If the cached
|
|
# one is corrupt (lxml.etree.XMLSyntaxError), delete it and re-fetch.
|
|
ESEL_REPO_CACHE="${HOME}/.cache/eselect-repo/repositories.xml"
|
|
if [[ -f "$ESEL_REPO_CACHE" ]]; then
|
|
# Quick sanity check: try to parse the XML. If invalid, delete.
|
|
if ! python3 -c "import xml.etree.ElementTree as ET; ET.parse('$ESEL_REPO_CACHE')" 2>/dev/null; then
|
|
log "WARN: $ESEL_REPO_CACHE is corrupt; removing and re-fetching"
|
|
rm -f "$ESEL_REPO_CACHE"
|
|
fi
|
|
fi
|
|
if ! sudo eselect repository list 2>&1 | grep -qi guru; then
|
|
log "fetching overlays.xml index"
|
|
sudo emaint sync --auto
|
|
fi
|
|
sudo eselect repository enable guru
|
|
# Sync just the new repo so we don't re-pull the entire gentoo tree
|
|
log "syncing GURU overlay"
|
|
sudo emaint sync -r guru
|
|
log "GURU overlay enabled and synced"
|
|
fi
|
|
|
|
# --- verify ---
|
|
log "enabled overlays:"
|
|
eselect repository list 2>&1 | sed 's/^/ /'
|
|
|
|
# Verify the GURU repo is readable
|
|
if [[ ! -f /var/db/repos/guru/profiles/repo_name ]]; then
|
|
die "/var/db/repos/guru/profiles/repo_name missing — overlay didn't sync cleanly"
|
|
fi
|
|
GURU_NAME=$(cat /var/db/repos/guru/profiles/repo_name)
|
|
log "GURU repo verified: $GURU_NAME"
|
|
|
|
log "overlays ready"
|
|
{{ else -}}
|
|
# Not a gentoo box — nothing to do (guarded by os_family above).
|
|
log "skipping gentoo overlays (os_family={{ .os_family }}, not gentoo)"
|
|
{{ end -}}
|