Files
pentest.intro/lib/cmd_seeds.sh
T
quoije c66b5641b6 Phase 3: unattended install, seed ISOs and VM lifecycle
autounattend template (q35/AHCI/e1000, no virtio injection), per-VM seed
ISOs with a bootstrap that configures the static IP, enables WinRM/RDP and
chains into the role script. build --dry-run, up/down/status/vnc verbs.

Static addressing happens in PowerShell rather than in the unattend file:
Microsoft-Windows-TCPIP matches adapters by connection name and fails
silently when the name differs.
2026-10-21 18:46:31 -04:00

67 lines
2.0 KiB
Bash

# shellcheck shell=bash
# cmd_seeds — render one unattend + payload per VM and pack a seed ISO.
# Nothing here needs root or a downloaded ISO; it is pure file assembly.
cmd_seeds() {
local tmpl="$LAB_DIR/seed/Autounattend.xml.tmpl"
local payload="$LAB_DIR/seed/payload"
[[ -r $tmpl ]] || die "missing template: $tmpl"
[[ -d $payload ]] || die "missing payload dir: $payload"
have_cmd genisoimage || have_cmd xorriso || die "genisoimage or xorriso is required"
: "${LAB_ADMIN_PASSWORD:?LAB_ADMIN_PASSWORD is not set in lab.conf}"
mkdir -p "$LAB_ROOT/seeds"
local i name ip role work iso volid dns
for i in "${!VM_NAMES[@]}"; do
name=${VM_NAMES[$i]}
ip=${VM_IPS[$i]}
role=${VM_ROLES[$i]}
dns=$LAB_DC_IP # every lab VM resolves through the DC
work="$LAB_ROOT/seeds/$name"
rm -rf "$work"
mkdir -p "$work/norbourg/roles"
sed -e "s|@@HOSTNAME@@|${name}|g" \
-e "s|@@ADMIN_PASSWORD@@|${LAB_ADMIN_PASSWORD}|g" \
-e "s|@@IMAGE_INDEX@@|${WINDOWS_IMAGE_INDEX:-2}|g" \
"$tmpl" > "$work/Autounattend.xml"
cp "$payload/bootstrap.cmd" "$work/norbourg/"
cp "$payload/bootstrap.ps1" "$work/norbourg/"
cat > "$work/norbourg/config.ps1" <<EOF
\$Config = @{
Hostname = '${name}'
IP = '${ip}'
Prefix = ${LAB_NETMASK}
Gateway = '${LAB_GATEWAY}'
DNS = '${dns}'
Role = '${role}'
Domain = '${DOMAIN}'
}
EOF
# A malformed answer file means a 20-minute silent install failure; catch it here.
python3 - "$work/Autounattend.xml" <<'PY' || die "rendered answer file is not valid XML for ${name}"
import sys, xml.etree.ElementTree as ET
ET.parse(sys.argv[1])
PY
iso="$LAB_ROOT/seeds/${name}-seed.iso"
volid="NRBG_${name^^}"
if have_cmd genisoimage; then
genisoimage -quiet -volid "$volid" -J -R -o "$iso" "$work"
else
xorriso -as mkisofs -quiet -V "$volid" -J -R -o "$iso" "$work"
fi
ok "$(printf '%-6s %-14s %-4s %s' "$name" "$ip" "$role" "$iso")"
done
printf '\n'
ok "${#VM_NAMES[@]} seed ISO(s) in ${LAB_ROOT}/seeds"
}