feat(deploy): bring new notebook templates into existing workspaces (#11)

Each shipped template is offered once (recorded in
/etc/shellbook/templates-offered) and copied as the service user only
when the file does not exist, so updates add new templates without
overwriting files or restoring deleted ones.
This commit is contained in:
Florian Schmidt
2026-11-16 11:42:13 +01:00
parent 85afd105f7
commit 54115289cc
2 changed files with 34 additions and 1 deletions
+18 -1
View File
@@ -20,4 +20,21 @@ grep -q 'git_app pull --ff-only' "$dir/install.sh" || { echo 'install.sh: existi
# Nothing may remain in the CT's /root after the Proxmox install.
grep -q 'rm -f /root/shellbook-install.env /root/shellbook-install.sh' "$dir/proxmox/create-ct.sh" \
|| { echo 'create-ct.sh: installer files left in the CT' >&2; exit 1; }
printf '8 install script checks passed\n'
# Templates: new ones reach existing workspaces once; existing and deleted files stay as they are.
offer=$(sed -n '/^offer_templates() {/,/^}$/p' "$dir/install.sh")
[[ -n $offer ]] || { echo 'install.sh: offer_templates missing' >&2; exit 1; }
tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT
(
runuser() { shift 3; "$@"; } # stub: run as the current user
eval "$offer"
mkdir -p "$tmp/t/notebooks/infra" "$tmp/w/notebooks"
printf 'new\n' > "$tmp/t/notebooks/infra/lxc.md"; printf 'shipped\n' > "$tmp/t/notebooks/a.md"
printf 'mine\n' > "$tmp/w/notebooks/a.md"
offer_templates "$tmp/t" "$tmp/w" "$tmp/offered"
[[ $(cat "$tmp/w/notebooks/a.md") == mine && $(cat "$tmp/w/notebooks/infra/lxc.md") == new ]] || { echo 'offer_templates: wrong copy' >&2; exit 1; }
rm "$tmp/w/notebooks/infra/lxc.md"
offer_templates "$tmp/t" "$tmp/w" "$tmp/offered"
[[ ! -e $tmp/w/notebooks/infra/lxc.md ]] || { echo 'offer_templates: deleted template came back' >&2; exit 1; }
[[ $(sort "$tmp/offered" | tr '\n' ' ') == 'notebooks/a.md notebooks/infra/lxc.md ' ]] || { echo 'offer_templates: wrong list' >&2; exit 1; }
)
printf '9 install script checks passed\n'