#!/bin/bash # sddm-theme-sync — regenerate the SDDM "caelestia" theme's colours and # background from the desktop's live caelestia scheme, so the login screen # matches the current wallpaper/palette. Run as root (the installer runs it # once; re-run any time after changing wallpaper): # sudo sddm-theme-sync set -euo pipefail THEME=/usr/share/sddm/themes/caelestia if [[ $EUID -ne 0 ]]; then echo "Error: run as root (sudo sddm-theme-sync)" >&2 exit 1 fi command -v jq >/dev/null 2>&1 || { echo "Error: jq is required" >&2; exit 1; } [[ -d "$THEME" ]] || { echo "Error: theme not installed at $THEME" >&2; exit 1; } # The desktop user whose scheme/wallpaper to mirror. U="${SUDO_USER:-}" if [[ -z "$U" || "$U" == "root" ]]; then U=$(loginctl list-sessions --no-legend 2>/dev/null | awk '$3 != "root" && $3 != "sddm" && $3 != "" { print $3; exit }') fi [[ -n "$U" ]] || { echo "Error: cannot determine the desktop user" >&2; exit 1; } H=$(getent passwd "$U" | cut -d: -f6) SCHEME="$H/.local/state/caelestia/scheme.json" WALLPATH="$H/.local/state/caelestia/wallpaper/path.txt" [[ -f "$SCHEME" ]] || { echo "Error: $SCHEME not found (no caelestia scheme yet)" >&2; exit 1; } c() { jq -r ".colours.$1 // empty" "$SCHEME"; } BASE=$(c background); SC=$(c surfaceContainer); SCH=$(c surfaceContainerHigh) TEXT=$(c onSurface); SUB=$(c onSurfaceVariant); OUT=$(c outlineVariant) PRI=$(c primary); ONPRI=$(c onPrimary); ERR=$(c error) [[ -n "$BASE" && -n "$PRI" && -n "$TEXT" ]] || { echo "Error: scheme.json missing expected colours" >&2; exit 1; } # Background: copy the current wallpaper into the theme (greeter runs as the # sddm user and cannot read the user's home). BG_LINE="background=backgrounds/wallpaper.png" if [[ -f "$WALLPATH" ]]; then WALL=$(cat "$WALLPATH") if [[ -f "$WALL" ]]; then EXT="${WALL##*.}" install -d -m 0755 "$THEME/backgrounds" rm -f "$THEME"/backgrounds/wallpaper.* install -m 0644 "$WALL" "$THEME/backgrounds/wallpaper.$EXT" BG_LINE="background=backgrounds/wallpaper.$EXT" fi fi cat > "$THEME/theme.conf" << EOF # Generated by sddm-theme-sync from $SCHEME — do not edit by hand. [General] $BG_LINE base=#$BASE surfaceContainer=#$SC surfaceContainerHigh=#$SCH text=#$TEXT subtext=#$SUB outline=#$OUT primary=#$PRI onPrimary=#$ONPRI error=#$ERR fontFile=/etc/xdg/quickshell/caelestia/assets/google-sans-flex/GoogleSansFlex-VariableFont_GRAD,ROND,opsz,slnt,wdth,wght.ttf fontFallback=Rubik EOF echo ":: SDDM theme synced to $U's scheme (takes effect at the next greeter)"