#!/usr/bin/env bash # Install hyprlogin + greetd config from chezmoi-tracked sources into /etc. # Run manually after `chezmoi apply` when files under system/ change. # # Usage: ~/.local/share/chezmoi/system/install-greeter.sh [--dry-run] set -euo pipefail dry_run=0 [[ "${1:-}" == "--dry-run" ]] && dry_run=1 source_dir="${CHEZMOI_SOURCE_DIR:-}" if [[ -z "$source_dir" ]] && command -v chezmoi >/dev/null 2>&1; then source_dir="$(chezmoi source-path 2>/dev/null || true)" fi [[ -z "$source_dir" ]] && source_dir="$HOME/.local/share/chezmoi" sys_dir="$source_dir/system" if [[ ! -d "$sys_dir" ]]; then echo "no system/ tree in $source_dir" >&2 exit 1 fi staging="$(mktemp -d -t greeter-staging-XXXXXX)" trap 'rm -rf "$staging"' EXIT # Files to install: source.tmpl → /etc target (mode) files=( "etc/greetd/greetd.conf.tmpl /etc/greetd/greetd.conf 0644" "etc/hyprlogin/apex-neon.conf.tmpl /etc/hyprlogin/apex-neon.conf 0644" "etc/hyprlogin/hyprlogin.conf.tmpl /etc/hyprlogin/hyprlogin.conf 0644" "etc/hyprlogin/hyprland-greeter.conf.tmpl /etc/hyprlogin/hyprland-greeter.conf 0644" ) render() { local src="$1" dst="$2" mkdir -p "$(dirname "$dst")" chezmoi execute-template --source "$source_dir" < "$src" > "$dst" } needs_install=0 declare -a plan for entry in "${files[@]}"; do read -r rel target mode <<<"$entry" src="$sys_dir/$rel" rendered="$staging/$rel" rendered="${rendered%.tmpl}" render "$src" "$rendered" if [[ ! -f "$target" ]] || ! diff -q "$rendered" "$target" >/dev/null 2>&1; then plan+=("$rendered → $target ($mode)") needs_install=1 fi done # Wallpapers: per-monitor, driven by chezmoi data.monitors[].lockscreen-wallpaper # Renders a "name|path" line per monitor that has a wallpaper set. wp_tmpl='{{ range .monitors }}{{ $wp := index . "lockscreen-wallpaper" }}{{ if $wp }}{{ .name }}|{{ $wp }} {{ end }}{{ end }}' declare -a wp_plan while IFS='|' read -r mon wp; do [[ -z "$mon" || -z "$wp" ]] && continue wp="${wp/#\~/$HOME}" if [[ ! -f "$wp" ]]; then echo "warning: monitor $mon wallpaper missing: $wp" >&2 continue fi ext="${wp##*.}" target="/etc/hyprlogin/wallpaper-${mon}.${ext}" if [[ ! -f "$target" ]] || ! cmp -s "$wp" "$target"; then plan+=("$wp → $target (0644)") wp_plan+=("$wp|$target") needs_install=1 fi done < <(chezmoi execute-template --source "$source_dir" <<<"$wp_tmpl") if (( ! needs_install )); then echo "nothing to do — /etc files already match chezmoi source" exit 0 fi echo "would install:" printf ' %s\n' "${plan[@]}" if (( dry_run )); then exit 0 fi # Back up current greetd config once, the first time, for one-step rollback. if [[ -f /etc/greetd/greetd.conf && ! -f /etc/greetd/greetd.conf.nwg-hello-bak ]]; then echo "backing up existing /etc/greetd/greetd.conf → /etc/greetd/greetd.conf.nwg-hello-bak" sudo cp -a /etc/greetd/greetd.conf /etc/greetd/greetd.conf.nwg-hello-bak fi for entry in "${files[@]}"; do read -r rel target mode <<<"$entry" rendered="$staging/${rel%.tmpl}" sudo install -Dm"$mode" "$rendered" "$target" done for pair in "${wp_plan[@]:-}"; do [[ -z "$pair" ]] && continue IFS='|' read -r src target <<<"$pair" sudo install -Dm0644 "$src" "$target" done cat <