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.
84 lines
2.6 KiB
Bash
84 lines
2.6 KiB
Bash
#!/bin/bash
|
|
# End-to-End-Test für motd-assist in einem Fake-Root.
|
|
set -euo pipefail
|
|
cd /mnt/c/Users/janik.dietz/Coding/motd-assist
|
|
go build -o /tmp/motd-assist .
|
|
|
|
R=/tmp/motdroot
|
|
rm -rf "$R"
|
|
mkdir -p "$R/etc/update-motd.d" "$R/etc/pam.d"
|
|
printf 'NAME="Ubuntu"\nPRETTY_NAME="Ubuntu 24.04.1 LTS"\n' > "$R/etc/os-release"
|
|
printf 'session optional pam_motd.so motd=/run/motd.dynamic\n' > "$R/etc/pam.d/sshd"
|
|
printf '#!/bin/sh\necho Welcome to Ubuntu \\e[1m %s\\e[0m\n' "$(hostname)" > "$R/etc/update-motd.d/00-header"
|
|
printf '#!/bin/sh\necho " * Documentation: man handbook"\n' > "$R/etc/update-motd.d/10-help-text"
|
|
chmod 755 "$R/etc/update-motd.d/00-header"
|
|
chmod 644 "$R/etc/update-motd.d/10-help-text"
|
|
|
|
echo "=== list (vorher) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist list
|
|
|
|
echo
|
|
echo "=== preview (vorher, nur 00-header aktiv) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist preview -w 60
|
|
|
|
echo
|
|
echo "=== apply server-dashboard (als root) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist apply server-dashboard
|
|
|
|
echo
|
|
echo "=== list (nachher) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist list
|
|
|
|
echo
|
|
echo "=== preview (nachher, Breite 60) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist preview -w 60
|
|
|
|
echo
|
|
echo "=== preview (nachher, Breite 40 — schmaler) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist preview -w 40 | cat -v | head -6
|
|
|
|
echo
|
|
echo "=== restore ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist restore
|
|
|
|
echo
|
|
echo "=== list (nach restore) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist list
|
|
|
|
echo
|
|
echo "=== Drop-in-Vorlage anlegen (XDG) ==="
|
|
export XDG_CONFIG_HOME=/tmp/xdg-motd
|
|
rm -rf "$XDG_CONFIG_HOME"
|
|
mkdir -p "$XDG_CONFIG_HOME/motd-assist/templates" "$XDG_CONFIG_HOME/motd-assist/presets"
|
|
printf '#!/bin/sh\necho "== Mein eigenes Template =="\nuname -s\n' > "$XDG_CONFIG_HOME/motd-assist/templates/mein-header"
|
|
cat > "$XDG_CONFIG_HOME/motd-assist/presets/custom.json" <<'EOF'
|
|
{
|
|
"name": "custom",
|
|
"description": "Drop-in-Preset mit eigener Vorlage",
|
|
"scripts": [
|
|
{ "name": "00-header", "enabled": false },
|
|
{ "name": "10-mein-header", "enabled": true, "install": "mein-header" }
|
|
]
|
|
}
|
|
EOF
|
|
|
|
echo
|
|
echo "=== templates (Drop-in muss auftauchen) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist templates
|
|
|
|
echo
|
|
echo "=== apply custom (User-Vorlage via eingebetteten Plan-Inhalt) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist apply custom
|
|
|
|
echo
|
|
echo "=== preview mit Drop-in-Template ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist preview -w 50
|
|
|
|
echo
|
|
echo "=== restore (Drop-in-Script muss weg) ==="
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist restore
|
|
MOTD_ASSIST_ROOT=$R /tmp/motd-assist list
|
|
|
|
echo
|
|
echo "=== ls update-motd.d ==="
|
|
ls -la "$R/etc/update-motd.d"
|