Files
quoije dcb64ac65e Restructure the repository per session
session1/ now holds the whole live lab (content, platforms, docs, answer key,
README); session2/ keeps the design for the second workshop. The root README
indexes both and states that session2 modifies session1 rather than
duplicating it.

build-bundle.sh builds from session1 and still produces a flat archive, so
the documented paths inside a deployment (platforms/<p>/lab.sh) are
unchanged. .gitignore follows the move.
2026-10-24 14:22:39 -04:00

80 lines
3.0 KiB
Bash

# shellcheck shell=bash
# cmd_web — assemble the archived site and apply the seed layer.
# Syncing to FS01 arrives with phase 7, once the VM exists.
cmd_web() {
local site="$CONTENT_DIR/web/site" seed="$CONTENT_DIR/web/seed"
local sync=0 arg
for arg in "$@"; do
case $arg in
--sync) sync=1 ;;
-h|--help) info "usage: ./lab.sh web [--sync]"; return 0 ;;
*) die "unknown argument: $arg" ;;
esac
done
step "assemble"
python3 "$CONTENT_DIR/scripts/prepare_site.py" || die "site assembly failed"
step "seed layer"
[[ -d $seed ]] || die "missing $seed"
cp -a "$seed/." "$site/"
ok "seed applied: $(find "$seed" -type f | wc -l) file(s)"
step "layout"
printf ' %-34s %s\n' "public/IT-inventaire.txt" \
"$([[ -f $site/public/IT-inventaire.txt ]] && echo present || echo MISSING)"
printf ' %-34s %s\n' "robots.txt" \
"$([[ -f $site/robots.txt ]] && echo present || echo MISSING)"
printf ' %-34s %s\n' "index.html" \
"$([[ -f $site/index.html ]] && echo present || echo MISSING)"
if (( ! sync )); then
printf '\n'
ok "web root ready: ${site#$CONTENT_DIR/}"
info " preview: python3 -m http.server 8080 --directory ${site#$CONTENT_DIR/}"
info " push to FS01: ./lab.sh web --sync"
return 0
fi
_web_sync "$site"
}
_web_sync() {
local site=$1
local i ip remote='C:\\norbourg\\site'
i=$(vm_index fs01) || die "fs01 is not defined in lab.conf"
ip=${VM_IPS[$i]}
step "push to fs01 ($ip)"
tcp_open "$ip" 445 || die "fs01 SMB is not reachable — is it provisioned?"
have_cmd smbclient || die "smbclient is required to push the site"
# Clear the staging folder first: smbclient only adds, so an old file would
# otherwise come back on every sync.
backend_ready fs01 120 >/dev/null 2>&1 || true
backend_ps fs01 "Remove-Item -Recurse -Force -ErrorAction SilentlyContinue 'C:\\norbourg\\site'" >/dev/null 2>&1 || true
# Bulk copy goes over SMB: WinRM caps the command line at ~8 KB.
smbclient "//$ip/C\$" -W "$NETBIOS" \
-U "$LAB_USER%$LAB_ADMIN_PASSWORD" \
-c "prompt OFF; recurse ON; mkdir norbourg; mkdir norbourg\\site; lcd $site; cd norbourg\\site; mput *" \
>/dev/null 2>&1 || true
backend_ready fs01 300 || die "fs01 did not answer"
# Mirror, not merge: remove everything except the web.config that fs01.ps1
# places in public/, otherwise files deleted from the repo keep being served.
backend_ps fs01 "
Get-ChildItem 'C:\inetpub\wwwroot' -Force | Where-Object { \$_.Name -ne 'public' } |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Get-ChildItem 'C:\inetpub\wwwroot\public' -Force | Where-Object { \$_.Name -ne 'web.config' } |
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
Copy-Item -Path 'C:\norbourg\site\*' -Destination 'C:\inetpub\wwwroot' -Recurse -Force
Test-Path 'C:\inetpub\wwwroot\index.html'" \
| grep -qi true || die "copy failed on fs01"
ok "site published to C:\\inetpub\\wwwroot"
info " http://10.10.10.20/ · http://www.norbourg.lab/"
}