#!/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' "$*"; } # --- 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-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"