feat: drop-in support for custom templates

User templates can now be added without rebuilding: drop a script into
~/.config/motd-assist/templates/ and reference it from a preset via
"install": "<filename>". Same-name files override built-ins; new files
are picked up by the running TUI via 'r'. `motd-assist templates` lists
known templates and creates the drop-in directory.

Apply plans now embed the resolved template content (Plan.ResolveContents)
so the sudo/root process never needs to read user config; snapshots store
installed script content so restore works under sudo as well. Validation
rejects plans with unresolved content.
This commit is contained in:
Tronax 2026-08-31 10:31:58 +02:00
parent d56659e21a
commit 303c49b484
Signed by: Tronax
SSH key fingerprint: SHA256:2pKKXDZucWvaF/GzXNz0FY53EAO1YDLN80bqS+TTz/o
10 changed files with 375 additions and 48 deletions

23
main.go
View file

@ -10,6 +10,7 @@ import (
tea "github.com/charmbracelet/bubbletea"
"motd-assist/internal/assets"
"motd-assist/internal/motd"
"motd-assist/internal/preset"
"motd-assist/internal/ui"
@ -35,6 +36,8 @@ func main() {
cmdList(root)
case "presets":
cmdPresets()
case "templates":
cmdTemplates()
case "apply":
cmdApply(root)
case "restore":
@ -128,6 +131,19 @@ func cmdPresets() {
}
}
func cmdTemplates() {
dir, err := assets.EnsureTemplatesDir()
if err != nil {
fatal(err)
}
fmt.Println("Eigene Vorlagen: Datei in diesen Ordner legen und im Preset referenzieren:")
fmt.Printf(" { \"name\": \"10-mein-style\", \"enabled\": true, \"install\": \"<dateiname>\" }\n")
fmt.Printf("Drop-in-Ordner: %s\n\n", dir)
for _, t := range assets.Templates() {
fmt.Printf(" %-20s (%s)\n", t.Name, t.Source)
}
}
func cmdApply(root string) {
if len(os.Args) < 3 {
fatal(fmt.Errorf("Usage: motd-assist apply <preset>"))
@ -163,6 +179,12 @@ func cmdApply(root string) {
return
}
// Vorlagen-Inhalte im User-Kontext auflösen, bevor der Plan
// (ggf. per sudo) an Root übergeben wird.
if err := plan.ResolveContents(); err != nil {
fatal(err)
}
if motd.IsRoot() {
if err := motd.Execute(root, plan); err != nil {
fatal(err)
@ -239,6 +261,7 @@ Usage:
motd-assist preview [-w N] aktuellen MOTD rendern und ausgeben
motd-assist list Scripte und Zustand auflisten
motd-assist presets verfügbare Presets auflisten
motd-assist templates Vorlagen auflisten + Drop-in-Ordner anzeigen
motd-assist apply <preset> Preset anwenden (fragt ggf. sudo-Passwort)
motd-assist restore letzten Apply zurücksetzen
motd-assist help diese Hilfe