1
0
Fork 0
gnu-plus-dotfiles/run_once_40-install-sway-gentoo.sh.tmpl
rain b78e23aa16 gentoo install scripts: guard with os_family like overlays
Both run_once_20-install-user-packages-gentoo.sh.tmpl and
run_once_40-install-sway-gentoo.sh.tmpl were missing the os_family
template guard (the overlays script got it in the previous fix but
these two slipped through). On non-gentoo boxes — arch, debian —
chezmoi apply would run them and they'd try to 'emerge', failing
with 'sudo: emerge: command not found' and exit status 1, which
breaks topgrade.

Wrap each body in '$0{ if eq .os_family "gentoo" }' / '$0{ else }',
mirroring the chaotic-aur script's pattern and the overlays fix from
the previous commit. On non-gentoo boxes the rendered script reduces
to a single 'skipping' log line and exits 0; on gentoo boxes the full
body (including the existing .sway_setup gate on the sway script) is
preserved.

Verified by rendering both scripts with a gentoo-config override:
  arch (live)  -> 'skipping gentoo user-packages' / 'skipping sway'
  gentoo        -> full body (293 / 87 lines)
Both pass bash -n and actually exit 0 when run on this arch box.
2026-06-25 18:58:27 -04:00

95 lines
No EOL
3.2 KiB
Bash

#!/usr/bin/env bash
# =============================================================================
# run_once_40-install-sway-gentoo.sh.tmpl (gentoo-only)
# Install the sway + wofi + foot + supporting tooling desktop stack on
# gentoo. Equivalent to run_once_40-install-sway.sh.tmpl's arch/debian
# branches.
#
# Gated on .sway_setup. When false (Pis, headless boxes), this script
# exits 0 without doing anything.
# =============================================================================
set -euo pipefail
log() { printf '\033[1;34m[sway]\033[0m %s\n' "$*"; }
{{ if eq .os_family "gentoo" -}}
# --- 0. Gate on .sway_setup ---
{{ if not .sway_setup -}}
log "sway_setup not enabled for this host (.sway_setup=false). Skipping."
log "To enable: touch ~/.config/chezmoi/features/sway && chezmoi apply"
exit 0
{{ end -}}
# Gentoo package set for sway + companions. All live in the main tree
# except some compositor deps that may need ~amd64.
SWAY_PKGS=(
gui-wm/sway
gui-apps/wofi
gui-apps/foot
gui-apps/swaybg
gui-apps/swaylock
gui-apps/swayidle
media-gfx/grim
media-gfx/slurp
gui-apps/waybar
gui-apps/wl-clipboard
x11-terms/foot-terminfo # for $TERM=foot support
)
log "checking sway stack: ${SWAY_PKGS[*]}"
# On gentoo, USE flags matter. Set the ones we need BEFORE emerging.
USE_DIR="/etc/portage/package.use/sway-bootstrap"
sudo mkdir -p "$(dirname "$USE_DIR")"
# sway itself doesn't need flags, but foot needs `+X +wayland`, waybar
# needs `+X +wayland +network +tray +upower +wireplumber`. Lay them out.
# Note: most gentoo ebuilds for these packages have sensible defaults,
# but be explicit for reproducibility.
sudo tee "$USE_DIR" >/dev/null <<'USE_FLAGS'
gui-wm/sway X wayland
gui-apps/foot X wayland
gui-apps/wofi X wayland
gui-apps/waybar X wayland tray upower wireplumber
USE_FLAGS
# Map package names to actual binaries (some packages ship under a
# different name, e.g. wl-clipboard provides wl-copy/wl-paste).
# On gentoo the package name is `gui-apps/wl-clipboard` but the
# binary is `wl-copy`. Strip the category prefix and look up the map.
declare -A PKG_BIN=(
[gui-apps/wl-clipboard]="wl-copy"
[x11-terms/foot-terminfo]="foot"
)
MISSING_PKGS=()
for p in "${SWAY_PKGS[@]}"; do
bin="${PKG_BIN[$p]:-$(basename "$p")}"
if ! command -v "$bin" >/dev/null 2>&1; then
MISSING_PKGS+=("$p")
fi
done
if (( ${#MISSING_PKGS[@]} > 0 )); then
log "missing: ${MISSING_PKGS[*]}"
log "emerge sway stack (gentoo compiles from source; this may take a while)"
sudo emerge --ask=n --nospinner --quiet-build --keep-going \
--with-bdeps=y --autounmask-continue=y --autounmask-license=y \
"${MISSING_PKGS[@]}"
else
log "all sway packages already installed; skipping emerge"
fi
log "sway stack installed"
sway --version 2>&1 | head -1
foot --version 2>&1 | head -1
wofi --version 2>&1 | head -1
# Mark the box so subsequent chezmoi applies know sway is enabled
mkdir -p ~/.config/chezmoi/features
touch ~/.config/chezmoi/features/sway
log "marked box: ~/.config/chezmoi/features/sway"
log "sway stack install complete"
{{ else -}}
# Not a gentoo box — nothing to do (guarded by os_family above).
log "skipping gentoo sway install (os_family={{ .os_family }}, not gentoo)"
{{ end -}}