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
+16
View File
@@ -59,6 +59,22 @@ if [[ -z $(find "$workspace" -mindepth 1 -maxdepth 1 -print -quit) ]]; then
chown -R shellbook:shellbook "$workspace"
runuser -u shellbook -- git -C "$workspace" init
fi
# Offer each shipped notebook template once: updates bring new templates into existing
# workspaces, but never overwrite files or bring back ones the user deleted. The copy runs
# as the service user, so links inside the workspace cannot redirect a root write.
offer_templates() { # <templates dir> <workspace> <offered list>
local file rel
touch "$3"
[[ -d $1/notebooks ]] || return 0
while IFS= read -r -d '' file; do
rel=${file#"$1"/}
grep -qxF -- "$rel" "$3" && continue
runuser -u shellbook -- bash -c 'test -e "$2" || test -L "$2" || install -D -m 644 "$1" "$2"' _ "$file" "$2/$rel"
printf '%s\n' "$rel" >> "$3"
done < <(find "$1/notebooks" -type f -name '*.md' -print0 | sort -z)
}
install -d -m 0750 /etc/shellbook
offer_templates /opt/shellbook/templates/workspace "$workspace" /etc/shellbook/templates-offered
if [[ ! -f /home/shellbook/.ssh/id_ed25519 ]]; then
runuser -u shellbook -- ssh-keygen -q -t ed25519 -N '' -f /home/shellbook/.ssh/id_ed25519 -C shellbook
fi