1
0
Fork 0
gnu-plus-dotfiles/run_once_40-install-sway.sh.tmpl
rain 4556813e78 Gentoo bootstrap: fix ambiguous package names + early-return on os_family mismatch
Three issues caught during tadbit onboarding:

1. run_once_00-install-bootstrap-tools.sh.tmpl (gentoo branch):
   'gnupg' is ambiguous (app-crypt/gnupg vs app-vim/gnupg). Use full
   category/package names: app-crypt/gnupg, app-crypt/age, etc.
   The previous 'for p in age curl ...' loop fed short names to
   emerge which printed '!!! The short ebuild name gnupg is
   ambiguous' and exited 1.

2. run_once_20-install-user-packages-gentoo.sh.tmpl:
   sys-devel/base-devel doesn't exist on Gentoo (it's an Arch/Fedora
   concept; Gentoo's toolchain is the @system set which is always
   installed). Removed base-devel from the package list.

3. Universal scripts (run_once_20 + run_once_40) were running on
   gentoo and hitting either 'die unsupported os_family' (universal
   20) or 'WARNING sway packages not configured for gentoo' (universal
   40). Added early-return: 'if os_family == gentoo, exit 0' at the
   top of each universal script so the gentoo-specific scripts
   handle the box. (Same pattern the chaotic-aur script already had.)

4. run_once_10-add-gentoo-overlays.sh.tmpl:
   The cached ~/.cache/eselect-repo/repositories.xml was corrupt on
   tadbit (lxml.etree.XMLSyntaxError on every 'eselect repository
   list' call). Added a sanity check: parse the XML with
   xml.etree.ElementTree, delete if invalid, re-fetch.

After these fixes, the bootstrap on tadbit is expected to run cleanly
with --keep-going (the four failures above all become no-ops).
2026-06-23 16:18:54 -04:00

93 lines
No EOL
3.2 KiB
Bash

#!/usr/bin/env bash
# =============================================================================
# run_once_40-install-sway.sh.tmpl
# Install the sway + wofi + foot + supporting tooling desktop stack.
#
# Gated on .sway (set in .chezmoi.yaml.tmpl). When false (Pis, headless
# boxes, etc.), this script exits 0 without doing anything.
#
# To opt a new box in: `touch ~/.config/chezmoi/features/sway` then
# `chezmoi apply`. To opt out: `touch ~/.config/chezmoi/features/no-sway`.
#
# Idempotent: skips if sway is already installed.
#
# Note: this script is for arch and debian. Gentoo has its own
# run_once_40-install-sway-gentoo.sh.tmpl. Without the early return
# below, both scripts would run on gentoo and the universal one
# would print "WARNING: sway packages not configured for os_family=gentoo".
# =============================================================================
set -euo pipefail
log() { printf '\033[1;34m[sway]\033[0m %s\n' "$*"; }
# --- 0. Gate on the .sway flag ---
{{ 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 -}}
# --- 0b. Gentoo uses its own sway script (different packages + USE flags) ---
{{ if eq .os_family "gentoo" -}}
log "sway stack install handled by run_once_40-install-sway-gentoo.sh.tmpl on gentoo"
log "to skip this universal script; exiting"
exit 0
{{ end -}}
# --- 1. Install packages ---
SWAY_PKGS=(sway wofi foot swaybg swaylock swayidle grim slurp waybar wl-clipboard)
{{ if eq .os_family "arch" -}}
# mako is in arch [extra]
SWAY_PKGS+=(mako)
{{ else if eq .os_family "debian" -}}
# mako isn't packaged on debian. Use dunst (lightweight notification daemon,
# widely compatible with sway/waybar setups).
SWAY_PKGS+=(dunst)
{{ else -}}
log "WARNING: sway packages not configured for os_family={{ .os_family }}"
{{ end -}}
log "checking sway stack: ${SWAY_PKGS[*]}"
# Only invoke sudo if any of the packages are missing. Bit has most
# already; byte/kaiser are full. This avoids a no-op sudo prompt.
#
# Note: a few packages ship their CLI binary under a different name
# (e.g. wl-clipboard provides wl-copy/wl-paste, not `wl-clipboard`).
# Map those to the actual binary we use.
declare -A PKG_BIN=(
[wl-clipboard]="wl-copy"
[mako]="mako"
)
MISSING_PKGS=()
for p in "${SWAY_PKGS[@]}"; do
bin="${PKG_BIN[$p]:-$p}"
if ! command -v "$bin" >/dev/null 2>&1; then
MISSING_PKGS+=("$p")
fi
done
if (( ${#MISSING_PKGS[@]} > 0 )); then
log "missing: ${MISSING_PKGS[*]}"
{{ if eq .os_family "arch" -}}
sudo pacman -S --needed --noconfirm "${MISSING_PKGS[@]}"
{{ else if eq .os_family "debian" -}}
export DEBIAN_FRONTEND=noninteractive
sudo apt-get install -y --no-install-recommends "${MISSING_PKGS[@]}"
{{ end -}}
else
log "all sway packages already installed; skipping"
fi
log "sway stack installed"
sway --version 2>&1 | head -1
foot --version 2>&1 | head -1
wofi --version 2>&1 | head -1
# --- 2. 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"